r - issues with groupedData() -
i'm following tutorial on mixed effects models. tutorial uses egsingle dataset mlmrev package. part of tutorial, author uses groupeddata() as:
egsingle <- groupeddata(math ~ year | schoolid/childid, data = egsingle)
could me understand "schoolid/childid" refers to?
please note schoolid , childid both factors!
also, later in tutorial, author takes sample of size 50 , uses lmlist() fit ols regression each subject using:
egsingle <- groupeddata(math ~ year | schoolid/childid, data = egsingle) samp <- sample(levels(egsingle$childid), 50) level2.subgroup <- subset(egsingle, childid %in% samp) # fitting separate ols regression line each student level2 <- lmlist(math ~ year | childid, data = level2.subgroup) plot(augpred(level2))
when run lmlist command above, these errors:
error in eval(expr, envir, enclos) : object 'childid' not found in addition: warning messages: 1: in lmlist(math ~ year | childid, data = level2.subgroup) : lmlist not (yet) work correctly on groupeddata objects 2: in ops.factor(schoolid, childid) : ‘/’ not meaningful factors
could me figure out why these errors?
as roman luštrik comments,
schoolid/chilidid
means "school id" , "child id nested within school id" both grouping variables. nesting format formally constructs interaction between higher , lower levels; heuristically, lets computer know "child 1 in school 1" , "child 1 in school 2" different individuals.you're having problem conflicts between versions of
lmlist
innlme
,lme4
packages. if run exactly these lines clean r session:
## load data without loading package & dependencies data(egsingle, package="mlmrev") library("nlme") egsingle <- groupeddata(math ~ year | schoolid/childid, data = egsingle) samp <- sample(levels(egsingle$childid), 50) level2.subgroup <- subset(egsingle, childid %in% samp) # fitting separate ols regression line each student level2 <- lmlist(math ~ year | childid, data = level2.subgroup) plot(augpred(level2))
it should work fine. should work if library("mlmrev")
before load nlme
(so nlme
before lme4
in search path), or if explicitly specify nlme::lmlist
don't accidentally pick lme4::lmlist
.
Comments
Post a Comment