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? Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com
lmList from lme4 on grouped data objects
3 messages · Ben Bolker, Viechtbauer Wolfgang (STAT)
1 day later
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
2 days later
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