18.4 Multilevel models

  • Gelman/Hill 2007, Chapter 11-13: Data Analysis Using Regression and Multilevel/Hierarchical Models

  • Package lme4 and arm
  • The lmer function
    • fit <- lmer(y ~ 1 + (1 | county)): Varying-intercept model with no predictors
      • county: Grouping variable`
    • fit <- lmer(y ~ ilevel.var + (1 | county)): Varying-intercept model with an individual-level predictor
    • display(fit): Summarize estimation results
    • coef(fit): Display coefficients
    • fixef(fit): Average
    • ranef(fit): Group-level errors
    • se.fixef(fit) and se.ranef(fit): Pull out standard errors
    • lmer(y ~ ilevel.var + glevel.var + (1 | county)): Adding a group level predictor
    • lmer(y ~ ilevel.var + (1 + ilevel.var | county)): Varying intercept, varying slope
    • lmer(formula = y ~ ilevel.var + glevel.var + ilevel.var:glevel.var + (1 + ilevel.var | county)): Varying intercept, varying slope + group level predictor included