I originally learned about random effects models when taking a course on Hierarchical Linear Models, which was taught using Raudenbush and Bryk's HLM book and software, and it sort of indoctrinated me to the subject in a very narrow way. I have a hard time thinking about random effects models in a way other than "Level-1 formula is..." and "Level-2 formula is..." Now I'm trying to migrate away from the HLM software and use instead lme4
. But of course even if I specify the model correctly lme4 will give me slightly different estimates than the HLM software, so I'm not 100% sure that I'm doing this correctly. Could someone please tell me whether I am specifying the following model (from chapter 2 of the HLM help manual) correctly?
Level-1 model:
$$MATHACH_{ij} = \beta_{0j} + \beta_{1j}SES_{ij} + r_{ij}$$
Level-2 models: $$\beta_{0j} = \gamma_{00} + \gamma_{01}SECTOR_j + \gamma_{02}MEANSES_j + u_{0j}$$ $$\beta_{1j} = \gamma_{10} + \gamma_{11}SECTOR_j + \gamma_{12}MEANSES_j + u_{1j}$$
This yields the following mixed model:
$$MATHACH_{ij} = \gamma_{00} + \gamma_{01}SECTOR_j + \gamma_{02}MEANSES_j + \gamma_{10}SES_{ij} + \gamma_{11}SECTOR_jSES_{ij} + \gamma_{12}MEANSES_jSES_{ij} + u_{0j} + u_{1j}SES_{ij} + r_{ij}$$
But seeing it in mixed model form doesn't quite help me with making sure I'm doing it right in lme4
. Here's what I have so far:
lmer(mathach ~ sector + meanses + ses + sector:ses + meanses:ses + (1+ses|school),data=dat)
We are measuring children (level 1) nested in schools (level 2). ses
is a child-level predictor, while sector
and meanses
are school-level predictors. Subscript i
is for children and subscript j
is for schools.