Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

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 yij=β0+β1xij+u0j+εijy_{ij} = \beta_0 + \beta_1 x_{ij} + u_{0j} + \varepsilon_{ij}, where u0ju_{0j} is the group-specific random intercept.
  • Random effects are commonly modeled as u0jN(0,τ00)u_{0j} \sim N(0, \tau_{00}) and residual errors as εijN(0,σ2)\varepsilon_{ij} \sim N(0, \sigma^2).
  • The intraclass correlation for a random-intercept model is ICC=τ00τ00+σ2ICC = \frac{\tau_{00}}{\tau_{00} + \sigma^2}.
  • A random-slope model can be written as yij=β0+β1xij+u0j+u1jxij+εijy_{ij} = \beta_0 + \beta_1 x_{ij} + u_{0j} + u_{1j}x_{ij} + \varepsilon_{ij}.
  • In lme4 syntax, a random intercept is written as yx+(1group)\text{y} \sim \text{x} + (1\mid \text{group}).
  • In lme4 syntax, a correlated random intercept and slope are written as yx+(1+xgroup)\text{y} \sim \text{x} + (1 + \text{x}\mid \text{group}).
  • In lme4 syntax, uncorrelated random intercepts and slopes are written as yx+(1+xgroup)\text{y} \sim \text{x} + (1 + \text{x}\Vert \text{group}).
  • 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 β1\beta_1 that estimates the average relationship between a predictor and the response across the population.
Random effect
A group-specific deviation such as u0ju_{0j} or u1ju_{1j} 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 τ00\tau_{00} or σ2\sigma^2 that measures variability from random effects or residual error.
Intraclass correlation
The proportion of total variance attributable to between-cluster differences, computed as ICC=τ00τ00+σ2ICC = \frac{\tau_{00}}{\tau_{00} + \sigma^2}.
Random slope
A group-specific change in a predictor effect, represented by u1ju_{1j} in a model such as yij=β0+β1xij+u1jxij+εijy_{ij} = \beta_0 + \beta_1 x_{ij} + u_{1j}x_{ij} + \varepsilon_{ij}.

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 τ00\tau_{00} as residual error is wrong because τ00\tau_{00} represents between-group intercept variance, while σ2\sigma^2 represents within-group residual variance.

Practice Questions

  1. 1 A random-intercept model has τ00=4\tau_{00} = 4 and σ2=12\sigma^2 = 12. Compute ICC=τ00τ00+σ2ICC = \frac{\tau_{00}}{\tau_{00} + \sigma^2}.
  2. 2 Write the lme4 formula for predicting score\text{score} from hours\text{hours} with a random intercept for school\text{school}.
  3. 3 For yij=β0+β1xij+u0j+u1jxij+εijy_{ij} = \beta_0 + \beta_1 x_{ij} + u_{0j} + u_{1j}x_{ij} + \varepsilon_{ij}, identify the fixed effects and random effects.
  4. 4 Explain why a mixed effects model is often better than ordinary least squares regression for repeated measurements from the same person.