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.

Understanding Mixed Effects Models Reference

Fixed effects describe relationships that the study wants to estimate directly. A study of test scores may treat hours of study, teaching method, or family income as fixed effects. Their coefficients describe an average relationship across the population represented by the data.

Random effects describe how groups depart from that average. Each school can have its own starting level, yet the model treats those school differences as draws from one wider distribution. This creates partial pooling.

A school with little data is pulled toward the overall average more strongly than a school with much data. Partial pooling prevents unstable group estimates from being treated as equally reliable.

The intraclass correlation measures how much outcome variation belongs to differences between groups rather than differences among people within a group. A high value means two students from the same school tend to resemble each other more than two randomly chosen students. This matters because ignoring clustering usually makes standard errors too small.

Effects may then look more precise than they really are. The intraclass correlation is useful before fitting a full model because it reveals whether grouping is likely to matter.

It is not a universal measure of quality. Its size depends on the outcome, the groups, and the population being studied.

A random intercept allows groups to begin at different baseline levels. A random slope goes further by allowing the effect of a predictor to differ by group. For example, extra study time may be more strongly related to scores in some schools than in others.

Random slopes are often realistic, but they need enough information. Each group needs several observations with meaningful variation in the predictor.

A model with many random effects can fail to estimate reliably when there are few groups or when predictor values barely change within groups. Centering a predictor around its overall mean often makes the intercept easier to interpret and can reduce fitting problems.

Model fitting requires careful choices. Maximum likelihood is appropriate when comparing models that differ in their fixed predictors because it uses a common basis for that comparison. Restricted maximum likelihood is usually preferred once the fixed part has been chosen, since it gives better estimates of variance components in many settings.

Students should inspect residual plots, check for unusually influential groups, and examine whether the assumed spread of residuals seems reasonable. Random effects are commonly assumed to follow a bell shaped distribution, but this is an assumption to assess, not a fact guaranteed by software.

A mixed model can describe associations well, yet it does not by itself prove that one variable causes another. Study design, omitted variables, and measurement quality still matter.