Mixed Models vs ANOVA/Regression
Info sheet · Statistics for Psychology & Neuroscience
Warning✎ Editing notes — to do / to check
Working notes for the author — not shown to students once collapsed; remove before publishing.
- [ ]
What you’ll get from this sheet
Where linear mixed models sit relative to the tools you already know — and why people are so keen on them. By the end you should be able to:
- Say how LMMs relate to ANOVA and regression.
- Explain how fixed and random effects are modelled differently.
- List several real advantages of LMMs over ANOVA/regression.
An LMM is regression plus random effects. A fixed effect is estimated on the mean of your outcome; a random effect is estimated on its variability. Unlike ANOVA/regression, LMMs don’t need independent, balanced, aggregated, or even normal data.
Fixed on the mean, random on the variability
The biggest difference we’ve drawn so far: an LMM lets you include both fixed and random effects — as many as you like. And it treats them differently. The effect of a fixed effect is estimated on the mean of your outcome; the effect of a random effect is estimated on the variability of your outcome.
An example (I was hungry writing this). Say you’re hired to study customer satisfaction with a set of donuts, sold across dozens of franchise locations. We treat donut type as a fixed effect — we care about this specific handful of donuts — and store location as a random effect, because we can’t test all locations (there are 150+ Tim Hortons in Toronto alone) but want to generalise beyond the ones we sample. The LMM estimates how donut type moves mean satisfaction, and how much of the variability in satisfaction is due to store.
Why LMMs beat their older relatives
Being able to include random effects is only the start. The rest of the case:
- They don’t require independent data points. Independent-samples ANOVA and regression need the levels within a factor to be independent. LMMs don’t — we can model the dependency directly (same stores, same participants).
- They handle nesting — multiple levels of it. Satisfaction scores within stores, within cities, within provinces. RM and mixed ANOVA can model only one level; LMMs model many. That’s why they’re also called multilevel or hierarchical models.
- They tolerate unbalanced designs and missing data. ANOVA throws up its hands at an empty cell; an LMM carries on.
- They don’t need aggregated data. With ANOVA we often average to force balance — run two groups of 50 who each did 100 trials, and we usually feed the ANOVA one mean per person (50 points per group). That throws away a huge amount of information (the whole trial history). An LMM uses every trial from every participant, even when the counts differ.
- They needn’t assume normality (as GLMMs). The “generalised” cousin handles non-normal outcomes — Poisson counts, logistic categories. We won’t cover those here, but it’s why the family is so flexible.
- They’re all the rage. It’s all anyone wants to talk about at statistics parties. Pull them off and you’ll look so cool.
Borrowing strength: the shrinkage picture
Here’s the idea that ties several of those advantages together. Suppose you measure satisfaction at six stores with very different sample sizes. Plain regression gives you two bad options: lump all stores together (ignore the differences), or fit each store as its own fixed effect (and fully trust even the store with n = 3). An LMM does something smarter — it pulls each store’s estimate toward the overall mean, by an amount that depends on how much data that store has. Watch:
The store with n = 3 looks extreme, but with so little data most of that is noise — so the LMM trusts it less and pulls it most of the way back to the overall mean. The n = 50 store barely budges. Turn the noise up and everything shrinks harder. That “borrowing of strength” is impossible in ordinary ANOVA/regression, and it’s exactly why LMMs cope so gracefully with unbalanced data: a small or half-empty group simply contributes what little it reliably can.
See it in code
The random effect is the part in parentheses; everything else is ordinary regression.
library(lme4)
# donut type: FIXED (the means); store: RANDOM (the variability)
m <- lmer(satisfaction ~ donut_type + (1 | store), data = donuts)
summary(m) # fixed-effect estimates + variance components
# nesting is just nested random effects:
lmer(satisfaction ~ donut_type + (1 | province/city/store), data = donuts)import statsmodels.formula.api as smf
smf.mixedlm("satisfaction ~ donut_type", data=donuts,
groups=donuts["store"]).fit().summary()Static reference — lme4/statsmodels aren’t in the in-page runtime.
TipCheck your understanding
You ran 100 trials per participant but averaged them to one score each before your ANOVA. What did that cost — and how does an LMM avoid it?
Averaging throws away all the trial-level variation (and forces you to pretend everyone did the same number of trials). An LMM keeps every trial, models each participant as a random effect to account for the fact that one person’s trials aren’t independent, and doesn’t care that trial counts differ across people. You keep the information and respect the dependency.
All this power isn’t free — it comes with a large helping of complexity. LMMs can fail to converge, force you to choose a random-effects structure, distinguish REML from ML estimation, and hand you variance components to interpret. Even the p-values are contested (the denominator degrees of freedom aren’t obvious). Reach for an LMM when the structure of your data demands it — not by default.
Where this shows up next
Next we pay for the awesomeness: the extra complexity of specifying, estimating, and interpreting an LMM. See Chapter (Mixed-Effects Models) for the full comparison and the donut worked example.