# Estimating HLM Models Using R: Part 2

Jeremy Albright

Posted on
ANOVA HLM R

## The Means-as-Outcomes Model

After estimating the empty model, R&B develop a Means-as-Outcomes model in which a school-level variable, meanses, is added to the model for the intercept. This variable reflects the average student SES level in each school. Recall that, when fitting the empty model, we began with the following equation:

$Y_{ij} = \beta_{0j} + e_{ij}$

Now the intercept can be modeled as a grand mean, $$\gamma_{00}$$, plus the effect of the average SES score, $$\gamma_{01}$$, plus a random error, $$u_{0j}$$.

$\beta_{0j} = \gamma_{00} + \gamma_{01}(\text{Mean SES}_j) + u_{0j}$

Substituting,

$Y_{ij} = \gamma_{00} + \gamma_{01}(\text{Mean SES}_j) + u_{0j} + e_{ij}$

The following will estimate the model.

mod_2 <- lmer(mathach ~ meanses + (1 | schid), data = hsb)
summary(mod_2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: mathach ~ meanses + (1 | schid)
##    Data: hsb
##
## REML criterion at convergence: 46961.3
##
## Scaled residuals:
##      Min       1Q   Median       3Q      Max
## -3.13480 -0.75256  0.02409  0.76773  2.78501
##
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  schid    (Intercept)  2.639   1.624
##  Residual             39.157   6.258
## Number of obs: 7185, groups:  schid, 160
##
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)
## (Intercept)  12.6494     0.1493 153.7425   84.74   <2e-16 ***
## meanses       5.8635     0.3615 153.4067   16.22   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
##         (Intr)
## meanses -0.004

The only difference from the empty model is that we’ve now included meanses as a fixed effect. The estimate of 5.864 tells us how much on average across all schools we would expect math achievement to increase for each unit increase in the school-level mean SES. This effect is statistically significant, $$p < 0.001$$.

The next step is to fit a random coefficient model.