[R-sig-ME] lmList from lme4 on grouped data objects

Viechtbauer Wolfgang (STAT) wolfgang.viechtbauer at maastrichtuniversity.nl
Fri Nov 15 20:29:37 CET 2013


Ah, did not realize that (in principle) it is already doing as.data.frame(). Unfortunately, I don't have a solution to the issue mentioned. But a note in the docs is certainly useful.

Best,
Wolfgang

> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-models-
> bounces at r-project.org] On Behalf Of Ben Bolker
> Sent: Wednesday, November 13, 2013 16:19
> To: r-sig-mixed-models at r-project.org
> Subject: Re: [R-sig-ME] lmList from lme4 on grouped data objects
> 
> Viechtbauer Wolfgang (STAT <wolfgang.viechtbauer at ...> writes:
> 
> >
> > Dear lme4-Maintainers,
> >
> > As far as I can tell, lmList() from lme4 does not
> > play nicely with grouped data objects from the nlme package. Example:
> >
> > library(lme4)
> > data(Orthodont, package="nlme")
> >
> > class(Orthodont)
> >
> > ### [1] "nfnGroupedData" "nfGroupedData"  "groupedData"    "data.frame"
> >
> > res <- lmList(distance ~ age | Subject, data=Orthodont)
> >
> > ### Error in eval(expr, envir, enclos) : object 'Subject' not found
> > ### In addition: Warning message:
> > ### In Ops.ordered(age, Subject) : '|' is not
> > meaningful for ordered factors
> >
> > Orthodont <- as.data.frame(Orthodont)
> >
> > res <- lmList(distance ~ age | Subject, data=Orthodont)
> >
> > ### works
> >
> > This had me stumped for a while, so I figured I would note this here (in
> case anybody else runs into this
> > issue). After googling a bit, I found:
> >
> > https://github.com/lme4/lme4/blob/master/tests/lmList.R
> >
> > so nothing really new here. But maybe add a check
> >  to lmList() whether somebody specifies a grouped data
> > object and turn it into a regular data frame?
> 
> 
>   This is a good point. The code of lmList actually has a
> line converting the 'data' argument via 'as.data.frame', but
> it doesn't work! The reason is a bit subtle -- lmList constructs
> its model frame by modifying the call and evaluating it in the
> parent frame, so that modifications to 'data' within the function
> itself get lost ...  I'm not currently sure of the best way to
> fix this, so in the meantime I'm adding a comment to the documentation.
> 
> There are still some open issues with lmList: in particular, it
> doesn't play nicely with the nlme accessor methods:
> 
> https://github.com/lme4/lme4/issues/26
> 
> _______________________________________________
> 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