[R-sig-ME] generalized linear mixed-effects model and lmer, lme

Douglas Bates bates at stat.wisc.edu
Sat Aug 30 12:40:47 CEST 2008

On Fri, Aug 29, 2008 at 9:50 PM, Qinglin Wu <qwu5 at yahoo.com> wrote:
> Dear list,

> I am the new R user and just start last Friday.  I am fitting the generalized linear mixed-effects model and going to use "glmer" function.  I don't understand the following two examples in the glmer function documentation:

> Example 1:  lmer(Reaction ~ Days + (Days | Subject), sleepstudy))
> Example 2:  lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy))

> In example 1,  i can write the model as:
> reaction = a_0 + a_1*days + b_0 + b1*days.
> The fixed effecta are a_0 + a_1*days, the random effects are b_0 + b1*days.

> How can you explain example 2?  Can I write the model as:
> reaction = a_0 + a_1*days +  b_0 + c1*days.

> these two have the same fixed effect.  What is the random effects in example 2?   Is it b_0 + c1*days?  Or one random effect is b_0 and another one is c1*days?

The two models differ in the form of the covariance matrix of the
random effects.  In the first example the random effect for the
intercept and the random effect for the slope are allowed to be
correlated within subject.  In the second example they are

In general, random effects associated with different random-effects
terms in a mixed-model formula are independent.

You may find the slides
http://www.stat.wisc.edu/~bates/PotsdamGLMM/LMMD.pdf and
http://www.stat.wisc.edu/~bates/PotsdamGLMM/GLMMD.pdf helpful in
learning about the lme4 package.

> If I use "lme" function, how can I write it in the "random" argument.

I'm not sure what "it" is here.

> Their results are totally different.
> Another question, I tried the function "lme".  I think it should have the same result with the function "lmer".  But it didn't.

> I tried the following models:
> lme(distance ~ age + Sex, data = Orthodont, random = ~ age+Sex)
> lmer(distance~age+Sex+(age+Sex|Subject),Orthodont)
> lmer(distance~age+Sex+((age+Sex)|Subject),Orthodont)

> They have the almost same results except "Corr" in the random effects.

Well the last two are equivalent.  I don't know about the first one.
However, the model doesn't make sense.  You are trying to define a
random effect for Sex by Subject but Sex doesn't vary within Subject.

The numerical methods underlying the lme function and the lmer
function are quite different.  I believe that the methods for lmer are
more reliable.

> I don't know how the two functions work in the R.  I checked the functions in the package. We can not look them.

You can always look at the functions.  R is an Open Source project and
the sources for all packages are available at CRAN.  Not only the
current sources but the entire archive of the sources for the lme4
package is available at http://r-forge.r-project.org/projects/lme4
under the SCM tab.

> Does anybody know there are some other places so that I can look the source code and then I know how they work.

Well you can look at the source code as I described above.  As for
knowing how the functions work, that may take more than a casual glace
at the sources.  There are days when I find it difficult to decide
exactly how they work, and I wrote most of them.

> Any help would be appreciated.
> Cynthia Wu
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

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