Mixed effects models analyze data with grouped, repeated, or hierarchical structure, such as students within schools or measurements within patients. This cheat sheet helps students connect the model equation, the variance components, and the software syntax used to fit these models. It is especially useful when ordinary regression is not appropriate because observations within the same group are correlated.
Key Facts
- A basic random-intercept mixed model is , where is the group-specific random intercept.
- Random effects are commonly modeled as and residual errors as .
- The intraclass correlation for a random-intercept model is .
- A random-slope model can be written as .
- In lme4 syntax, a random intercept is written as .
- In lme4 syntax, a correlated random intercept and slope are written as .
- In lme4 syntax, uncorrelated random intercepts and slopes are written as .
- Use maximum likelihood to compare models with different fixed effects, and use restricted maximum likelihood for final estimation of variance components.
Vocabulary
- Fixed effect
- A coefficient such as that estimates the average relationship between a predictor and the response across the population.
- Random effect
- A group-specific deviation such as or that allows intercepts or slopes to vary across clusters.
- Cluster
- A grouping unit, such as a school, patient, classroom, or site, within which observations may be correlated.
- Variance component
- A parameter such as or that measures variability from random effects or residual error.
- Intraclass correlation
- The proportion of total variance attributable to between-cluster differences, computed as .
- Random slope
- A group-specific change in a predictor effect, represented by in a model such as .
Common Mistakes to Avoid
- Treating clustered observations as independent is wrong because observations in the same group often share unmodeled influences, which can make standard errors too small.
- Using fixed effects and random effects interchangeably is wrong because fixed effects estimate population-average coefficients, while random effects estimate group-level variation around those coefficients.
- Adding random slopes without enough data per group is risky because the model may not have enough information to estimate slope variability reliably.
- Comparing models fitted with restricted maximum likelihood when fixed effects differ is wrong because REML likelihoods are not directly comparable across different fixed-effect structures.
- Interpreting as residual error is wrong because represents between-group intercept variance, while represents within-group residual variance.
Practice Questions
- 1 A random-intercept model has and . Compute .
- 2 Write the lme4 formula for predicting from with a random intercept for .
- 3 For , identify the fixed effects and random effects.
- 4 Explain why a mixed effects model is often better than ordinary least squares regression for repeated measurements from the same person.