[R] problem with interaction in lmer even after creating an "interaction variable"
Ben Bolker
bbolker at gmail.com
Thu Nov 7 15:03:22 CET 2013
a_lampei <anna.lampei-bucharova <at> uni-tuebingen.de> writes:
>
> Dear all,
> I have a problem with interactions in lmer. I have 2 factors (garden and
> gebiet) which interact, plus one other variable (home),
> dataframe arr. When
> I put:
> /
> lmer (biomass ~ home + garden:gebiet + ( 1|Block), data = arr)/
>
> it writes:
> /Error in lme4::lFormula(formula = biomass ~ home + garden:gebiet
> + (1 | :
> rank of X = 28 < ncol(X) = 30/
>
> In the lmer help I found out that if not all combination of
> the interaction
> are realized, lmer has problems and one should do new variable using
> "interaction", which I did:
> /
> arr$agg <- interaction (arr$gebiet, arr$garden, drop = TRUE)/
>
> when I fit the interaction term now:
> /
> lmer (biomass ~ home + agg+ ( 1|Block), data = arr)/
>
> The error does not change:
> /
> Error in lme4::lFormula(formula = biomass ~ home + agg + (1 | Block), :
> rank of X = 28 < ncol(X) = 29/
>
> No NAs are in the given variables in the dataset.
>
> Interestingly it works when I put only given interaction like
>
> /lmer (biomass ~ agg + ( 1|Block), data = arr)/
>
> Even following models work:
> /lmer (biomass ~ gebiet*garden + ( 1|Block), data = arr)
> lmer (biomass ~ garden + garden:gebiet +( 1|Block), data = arr)/
>
> But if I add the interaction term in th enew formate of
> the new fariable, it
> reports again the same error.
>
> /lmer (biomass ~ garden + agg +( 1|Block), data = arr)/
>
> If I put any other variable from the very same dataframe
> (not only variable
> "home"), the error is reported again.
>
> I do not understand it, the new variable is just another
> factor now, or? And
> it is in the same dataframe, it has the same length.
>
> Does anyone have any idea?
>
> Thanks a lot, Anna
>
This probably belongs on r-sig-mixed-models.
Presumably 'home' is still correlated with one of the
columns of 'garden:gebiet'.
Here's an example of how you can use svd() to find out which
of your columns are collinear:
set.seed(101)
d <- data.frame(x=runif(100),y=1:100,z=2:101)
m <- model.matrix(~x+y+z,data=d)
s <- svd(m)
zapsmall(s$d)
## [1] 828.8452 6.6989 2.6735 0.0000
## this tells us there is one collinear component
zapsmall(s$v)
## [,1] [,2] [,3] [,4]
## [1,] -0.0105005 -0.7187260 0.3872847 0.5773503
## [2,] -0.0054954 -0.4742947 -0.8803490 0.0000000
## [3,] -0.7017874 0.3692117 -0.1945349 0.5773503
## [4,] -0.7122879 -0.3495142 0.1927498 -0.5773503
## this tells us that the first (intercept), third (y),
## and fourth (z) column of the model matrix are
## involved in the collinear term, i.e.
## 1+y-z is zero
More information about the R-help
mailing list