Mon - Fri : 08:00 AM - 5:00 PM
734.544-8038

# Estimating HLM Models Using R: Part 2

### Note: For a fuller treatment, download our series of lectures Hierarchical Linear Models.

#### 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 Equation (1):

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

The intercept can be modeled as a grand mean γ00, plus the effect of the average SES score γ01, plus a random error u0j.

$$\tag{4} \beta_{0j} = \gamma_{00} + \gamma_{01}(MEAN \; SES_{j}) + u_{0j}$$

Substituting (4) into (1) yields

$$\tag{5} Y_{ij} = \gamma_{00} + \gamma_{01}(MEAN \; SES_{j}) + u_{0j} + e_{ij}$$

The following estimates the model in R:


model2<-lme(mathach ~ meanses, random = ~ 1 | id, data=hsb)



The only difference from Model 1 was that the model now includes a fixed effect for mean SES. Thus, if Model 1 were already estimated, Model 2 could be obtained with the update function:


model2<-update(model1,mathach ~ meanses)



Either way, the results can once again be viewed using summary, and the VarCorr function returns the variance components as variances.

> summary(model2)
Linear mixed-effects model fit by REML
Data: hsb
AIC     BIC    logLik
46969.28 46996.8 -23480.64

Random effects:
Formula: ~1 | id
(Intercept) Residual
StdDev:     1.62441 6.257562

Fixed effects: mathach ~ meanses
Value Std.Error   DF  t-value p-value
(Intercept) 12.649435 0.1492801 7025 84.73622       0
meanses      5.863538 0.3614580  158 16.22191       0
Correlation:
(Intr)
meanses -0.004

Standardized Within-Group Residuals:
Min          Q1         Med          Q3         Max
-3.13479829 -0.75256339  0.02408657  0.76773257  2.78501439

Number of Observations: 7185
Number of Groups: 160

> VarCorr(model2)
id = pdLogChol(1)
Variance  StdDev
(Intercept)  2.638708 1.624410
Residual    39.157082 6.257562



This corresponds to Table 4.3 in R&B.

The next step is to estimate a random coefficient model.