Mixed-effects models
Ordinary regression assumes every observation is independent. When you measure the same people repeatedly, or sample pupils from the same classes, that assumption fails, and standard errors come out too small. Mixed-effects models build the grouping into the model.
Fixed and random effects
- Fixed effects: the average relationships you want to estimate, such as the effect of days of sleep deprivation on reaction time.
- Random intercepts: each group (person, school) gets its own baseline, drawn from a distribution of baselines.
- Random slopes: each group can also have its own slope, for when people respond differently to the predictor.
Worked example: reaction time under sleep restriction
In R’s lme4::sleepstudy data (Belenky et al., 2003), 18 participants were restricted to three hours’ sleep a night and their reaction time was measured daily for 10 days, 180 observations in all. We model reaction time on days, with a random intercept for each participant.
Model: Linear mixed-effects model (random intercept, REML) Outcome: Reaction N: 180 Groups: Subject (18 groups) Random intercept variance: 1378.1786 Residual variance: 960.4566 ICC: 0.5893 Wald chi-squared: 169.4014 (df=1) P-value: 9.998e-39 Fixed-effect tests: t tests, Satterthwaite degrees of freedom === COEFFICIENTS === const: coef=251.4051, se=9.7467, t=25.7938, df=22.8102, p=0.0000, ci=[231.2332, 271.5770] Days: coef=10.4673, se=0.8042, t=13.0154, df=161.0000, p=0.0000, ci=[8.8791, 12.0555] === DIAGNOSTICS === Residual normality p: 0.0004
These estimates match R’s lme4 and lmerTest.
Interpretation
- Days: b = 10.47 ms per day, 95% CI [8.88, 12.06], p < .001. Reaction time slowed by about 10 ms for each day of restricted sleep.
- Intercept: 251.4 ms, the average reaction time at day 0.
- Random intercept SD ≈ 37 ms (√1378) and residual SD ≈ 31 ms (√960). People differ a lot in their baseline speed.
- ICC = .59: 59% of the variation in reaction time (after the trend over days) is between people. Treating the 180 observations as independent would have been badly wrong.
- Caveat: the residuals aren’t normal (p = .0004). In this dataset, participants also differ in how fast they decline, so adding a random slope for days would be the natural next model.
APA write-up
A linear mixed-effects model with a random intercept for participant showed that reaction time increased with days of sleep restriction, b = 10.47 ms per day, 95% CI [8.88, 12.06], t(161) = 13.02, p < .001. The intraclass correlation was .59.
Why not repeated measures ANOVA?
- Mixed models keep participants with missing time points. RM-ANOVA drops them entirely.
- Time can be continuous and unequally spaced.
- Random slopes model individual differences in change.
- They extend to three or more levels (pupils in classes in schools).
See repeated measures ANOVA for the classic approach.
Practical notes
- Degrees of freedom for fixed effects aren’t straightforward. Satterthwaite or Kenward-Roger approximations are standard, and Analytika uses Satterthwaite.
- Complex random-effect structures can fail to converge or give singular fits. Simplify if so.
- For yes/no or count outcomes, use generalised linear mixed models (GLMMs).
References
- Belenky, G., Wesensten, N. J., Thorne, D. R., Thomas, M. L., Sing, H. C., Redmond, D. P., Russo, M. B., & Balkin, T. J. (2003). Patterns of performance degradation and restoration during sleep restriction and subsequent recovery: A sleep dose-response study. Journal of Sleep Research, 12(1), 1–12.
More in Regression
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.