1

I'm following a tutorial on mixed effects models. The tutorial uses egsingle dataset from mlmRev package. As part of the tutorial, the author uses groupedData() as:

egsingle <- groupedData(math ~ year | schoolid/childid, data = egsingle)

Could someone help me understand what "schoolid/childid" refers to?

Please note that schoolid and childid are both factors!

Also, later in the tutorial, the author takes a sample of size 50 and uses lmList() to fit OLS regression for each subject by using:

egsingle <- groupedData(math ~ year | schoolid/childid, data = egsingle)
samp <- sample(levels(egsingle$childid), 50)
level2.subgroup <- subset(egsingle, childid %in% samp)

# fitting a separate OLS regression line to each student
level2 <- lmList(math ~ year | childid, data = level2.subgroup)
plot(augPred(level2))

when I run lmList command above, I get 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 does not (yet) work correctly on groupedData objects
2: In Ops.factor(schoolid, childid) : ‘/’ not meaningful for factors

Could anyone help me figure out why I get these errors?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Sam
  • 4,357
  • 6
  • 36
  • 60
  • It means that levels if `childid` are nested inside a `schoolid`, which is the whole point of mixed effects models (not counting continuous autocorrelated time/space variables, see this paper by [Bolker et al. 2009](http://www.sciencedirect.com/science/article/pii/S0169534709000196)). I'm not sure `lmList` works for mixed effects models. – Roman Luštrik Jul 18 '15 at 06:35

1 Answers1

2
  1. As Roman Luštrik comments, schoolid/chilidid means "school ID" and "child ID nested within school ID" are both grouping variables. The nesting format formally constructs an interaction between the higher and lower levels; heuristically, it lets the computer know that "child 1 in school 1" and "child 1 in school 2" are different individuals.

  2. You're having a problem with conflicts between the versions of lmList in the nlme and lme4 packages. If you run exactly these lines from a 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 a separate OLS regression line to each student
level2 <- lmList(math ~ year | childid, data = level2.subgroup)
plot(augPred(level2))

it should work fine. It should also work if you library("mlmRev") before you load nlme (so nlme is before lme4 in the search path), or if you explicitly specify nlme::lmList so you don't accidentally pick up lme4::lmList.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453