[R-sig-ME] question about linear mixed models

Andrew Dolman andydolman at gmail.com
Thu Jul 8 09:56:20 CEST 2010


Hello Jose,

lme4 can handle crossed and nested random effects whereas nlme can
only do nested random effects.

What you've specified here:

> mixed.model <- lmer (y ~ x1+x2+x3 + (1 | nation) + (1 | year), data=data)

has crossed random effects.

> and R returns the following output for the random effects:
>
> Random effects:
>  Groups   Name          Variance   Std.Dev.
>  year          (Intercept)   0.00            0.00
>  nation      (Intercept)   9.40            3.07
>  Residual                      2.42             1.56

and you seem to have zero variance associated with the random effect
"year". This may be a problem with the way you've coded your data
which is why it's helpful if you post a sample of your data, or dummy
data, with your question.

do > head(mydataframe)
the output from str (mydataframe) is useful too because we can see how
many levels of each factor you have


If you want a nested model in lme4 you should specify it as  + (1 |
nation/year) OR +(1|nation) + (1|nation:year)


I'm not sure what the model is that you specified in nlme but it can't
be the same as the one for lme4 because nlme cannot do crossed random
effects

> mixed.effects <- lme (y ~ x1+x2+x3, data=data,
>      random=~1|nation+1|year, method="REML")


Andy.




More information about the R-sig-mixed-models mailing list