[R-sig-ME] logLik df in lme vs. lmer
Martin Maechler
maechler at stat.math.ethz.ch
Thu Apr 3 18:16:11 CEST 2008
>>>>> "AB" == Andrew Beckerman <a.beckerman at sheffield.ac.uk>
>>>>> on Thu, 3 Apr 2008 15:43:55 +0100 writes:
AB> Dear all -
AB> R 2.6.2, lme4 version 0.99875-9, OSX.
If you use any recent R-forge version of 'lme4'
you will see that the degrees of freedoms
are 6 and 5 (instead of 5 and 4) for your two examples.
You can get the R-forge version by
install.packages("lme4",repos="http://R-Forge.R-project.org")
library(lme4)
If you want to have it in a different than default library
(because you would want the "old" CRAN-lme4 by default),
you'd need something like
myLib <- "......./my_library"
## ^^^^^^^^^^^^^^^^^^ a place where you have WRITE permission
dir.create(myLib)
install.packages("lme4",repos="http://R-Forge.R-project.org",
lib = myLib)
library(lme4, lib = myLib)
Martin
AB> We have noticed that lme and lmer produce different estimates of the
AB> number of paramters in the estimation of the logLik. While these are
AB> different, the logLik is not (good), but ensuing calculations of AIC
AB> can be.
AB> According to some textbooks (i.e. Burnham and Anderson), the number of
AB> paramters is calcuated as the intercept + betas+ random effects levels
AB> (?) + a term for the residual variance. In the example below
AB> (sleepstudy from lmer), that calculation results in df=5, as indicated
AB> in lmer but not in lme.
AB> library(lme4)
AB> wrk<-sleepstudy # data from lmer package
AB> fm.lmer <- lmer(Reaction ~ Days + (Days|Subject), wrk,method="ML")
AB> logLik(fm.lmer) # df = 5
AB> fm.lmer
AB> AIC(logLik(fm.lmer))
AB> detach(package:lme4)
AB> library(nlme)
AB> fm.lme <- lme(Reaction ~ Days,random=~Days|Subject, wrk,method="ML")
AB> summary(fm.lme)
AB> logLik(fm.lme) # df=6
AB> AIC(logLik(fm.lme))
AB> However, we have also seen lmer appear to "underestimate" and lme get
AB> it right -
AB> # continuing from above
AB> wrk2<-Orthodont # data from nlme package
AB> fm.lme2 <- lme(distance ~ age + Sex, data = wrk2, random = ~
AB> 1,method="ML")
AB> fm.lme2
AB> logLik(fm.lme2) # df=5 (correct?)
AB> detach(package:nlme)
AB> library(lme4)
AB> fm.lmer2 <- lmer(distance ~ age + Sex+(1|Subject), data = wrk2,
AB> method="ML")
AB> fm.lmer2
AB> logLik(fm.lmer2) # df=4 (now underestimated?)
AB> Does anyone know what is going on? Obviously, we can just specify the
AB> df in AIC calculations by hand, but AIC() uses the df from logLik (),
AB> which seems to vary.
AB> I've noticed this question here as well.
AB> http://tolstoy.newcastle.edu.au/R/e4/help/08/02/3988.html
AB> Cheers
AB> andrew
AB> ---------------------------------------------------------------------------------
AB> Dr. Andrew Beckerman
AB> Department of Animal and Plant Sciences, University of Sheffield,
AB> Alfred Denny Building, Western Bank, Sheffield S10 2TN, UK
AB> ph +44 (0)114 222 0026; fx +44 (0)114 222 0002
AB> http://www.beckslab.staff.shef.ac.uk/
AB> _______________________________________________
AB> R-sig-mixed-models at r-project.org mailing list
AB> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list