I want to fit a model with 5 levels. All levels are hierarchical. That is, level 5 is nested in level 4, level4 is nested in level 3, etc. level 2 is nested in level 1. All levels are factors.
Single level and two level models are working well:
model1 <- lmer(y ~ 1 + (1 | level1), data=data)
model2 <- lmer(y ~ 1 + (1 | level1/level2), data=data)
I wish to fit a model including all levels. What is the appropriate syntax for lmer?
My ideas so far:
model3 <- lmer(y ~ 1 + (1 | level1 / level2 / level3 / level4 / level5), data=data)
model4 <- lmer(y ~ 1 + (1 | level1 / level2) + (1 | level2 / level3) + (1 | level3 / level4)+ (1 | level4 / level5)
model3 produced this error:
Error: couldn't evaluate grouping factor level5:(level4:(level3:(level2:level1))) within model frame: try adding grouping factor to data frame explicitly if possible
which I can not interpret.
Can you guys hellp me out here?