viewof scn = html`<select style="font-size:15px;padding:4px 8px">
<option value="0">The 3 task conditions (A, B, C) — the only ones you care about</option>
<option value="1">The 40 participants in your study, sampled from the population</option>
<option value="2">5 new donut flavours the company asked you to test</option>
<option value="3">The hundreds of stores selling the donuts (you test a sample)</option>
<option value="4">Disease 1, Disease 2, and healthy controls</option>
<option value="5">Schools sampled from across the country</option>
<option value="6">Drug dose: 0 mg, 10 mg, 20 mg — the exact doses of interest</option>
<option value="7">The house areas in the London dataset (you want to generalise beyond them)</option>
</select>`
md`**Your call**`Fixed vs Random Effects
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
Before we dive into linear mixed models (LMMs), we need one crucial distinction: fixed effects vs random effects. By the end you should be able to:
- Tell a fixed effect from a random one, and say why the difference matters.
- See why ANOVA and regression — treating everything as fixed — are limited.
A fixed effect includes all the levels you care about (you can only generalise to those levels). A random effect’s levels are a sample from a larger population (letting you generalise beyond them). ANOVA and regression treat everything as fixed — LMMs let you have both.
What do we mean by an “effect”?
An effect is just a factor or variable that might influence the outcome — task type, stimulus modality, disease status, and so on. The new question is how we treat that factor:
- A fixed effect is one where all the levels of interest are in the study. Task conditions A, B, C when those three are the whole point; or Disease 1, Disease 2, and healthy controls. You can only generalise to the levels you included.
- A random effect is one where the levels are sampled from a larger population — not all possible levels are present. Your 40 participants (you didn’t test everyone); schools sampled from across a country; the house areas in the London dataset when you want to say something beyond those specific areas. A random effect lets you generalise past the sample.
“Random” here does not mean “by chance” in the everyday sense. It means randomly sampled from a larger distribution.
Quiz: fixed or random?
Pick a scenario, make your call, and see why. The tell is always the same question: are these all the levels I care about, or a sample standing in for many more?
Why this matters
ANOVA and regression share an important weakness: they treat everything as fixed. That’s fine much of the time, but it blocks two things. First, generalising to new participants or groups you didn’t test. Second, modelling hierarchical or multi-level structure — students within classrooms, patients within clinics, repeated measures within people. Both need random effects, and that’s exactly what linear mixed models add.
There’s a neat way to hold the two ideas apart, which we’ll lean on next: a fixed effect influences the mean of the outcome, while a random effect influences its variability. In the donut study — five flavours the company chose (fixed), sold across hundreds of sampled stores (random) — the LMM estimates how flavour shifts average satisfaction, and how much store explains the spread around it.
(And yes: mixed ANOVA isn’t the same as this. A mixed ANOVA is only a very basic version of a mixed model — a stepping stone, not the full picture.)
See it in code
The syntax makes the distinction concrete: a random effect goes in parentheses with a grouping variable.
library(lme4)
# satisfaction: flavour is FIXED (the means), store is RANDOM (the variability)
lmer(satisfaction ~ flavour + (1 | store), data = donuts)
# compare to plain regression, where EVERYTHING is fixed:
lm(satisfaction ~ flavour, data = donuts)import statsmodels.formula.api as smf
# flavour = fixed effect; store = random intercept (groups)
smf.mixedlm("satisfaction ~ flavour", data=donuts, groups=donuts["store"]).fit().summary()Static reference — lme4/statsmodels aren’t in the in-page runtime. The (1 | store) term is the random effect.
TipCheck your understanding
You measure reaction times from 30 participants, each doing the same 4 task conditions. Which factor is fixed and which is random?
Task condition is a fixed effect — those four conditions are the levels you care about, and you’re not sampling from a population of conditions. Participant is a random effect — your 30 people are a sample standing in for a wider population, and you want your conclusions to generalise beyond them. (This is exactly the structure a repeated-measures design has — and an LMM handles it more flexibly.)
The fixed/random call isn’t always clean-cut — it depends on your inferential goal, not just the variable. The same factor (say, “hospital”) is fixed if you only care about these three hospitals, but random if they’re a sample meant to represent hospitals in general. Ask what you want to generalise to before you decide. And a random effect needs enough levels to estimate a variance — with only 2–3 groups, a fixed effect is usually the safer choice.
Where this shows up next
This is the doorway to Chapter (Mixed-Effects Models). Next we contrast LMMs with ANOVA/regression, then add random intercepts and slopes.