Mediation (the Lurking Third Variable)
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
When a third variable explains a relationship. By the end you should be able to:
- Define mediation and tell it apart from moderation.
- Read the Baron & Kenny logic and the ACME (indirect effect).
Mediation is when a third variable — the mediator — carries some or all of A’s effect on B: A → M → B. The total effect splits into a direct effect (A → B) and an indirect effect (A → M → B). If the mediator carries all of it, that’s full mediation; some of it, partial. The indirect effect is the ACME.
A cautionary tale
Two real, statistically significant correlations: US spending on science and technology tracks almost perfectly with deaths by hanging/strangulation/suffocation; and the number of lawyers in California correlates with the number of people who die of cancer on a Thursday. Significant — and absurd. What’s going on? Almost certainly a third variable driving both. Take the first: what pushes up both science spending and the raw count of such deaths? Population. As the US grows, so does total science spending, and so — inevitably — does the raw count of deaths of almost any kind. The A–B link is an artefact of a lurking third variable.
That idea splits two ways. Sometimes the third variable explains the relationship — mediation. Sometimes it changes the relationship — moderation (which is really an interaction, and gets its own sheet). In mediation, A influences the mediator, and the mediator influences B. (And yes, a relationship can be both mediated and moderated at once — moderated mediation — but that’s for another day.)
The mediation triangle
Does age raise heart‑disease risk partly because older people smoke more? Age → cigarettes → risk. Slide how much of age’s effect flows through smoking and watch the paths — and the labels for partial vs full mediation.
At 0% the effect runs straight from age to risk — the indirect path is dead, no mediation. Slide it up and the a → b route thickens while the direct arrow thins: smoking is now carrying age’s effect. At 100% the direct path vanishes — full mediation, where age matters only through smoking. In real data you almost always land in between: partial mediation.
Testing it
The classic recipe is Baron & Kenny (1986) — four regressions. With predictor age, mediator cigarettes, outcome risk: (1) age predicts risk; (2) age predicts cigarettes; (3) cigarettes predict risk controlling for age; (4) age’s effect shrinks once cigarettes are in the model. That pattern signals mediation — but to test whether the indirect effect is real, use the Sobel test or, better, the mediate() function with bootstrapping (resampling the data many times rather than assuming normality). The number to report is the ACME — the average causal mediation effect.
library(mediation)
m_model <- lm(cigs ~ age) # predictor -> mediator
o_model <- lm(risk ~ age + cigs) # + mediator -> outcome
med <- mediate(m_model, o_model, treat = "age", mediator = "cigs",
boot = TRUE, sims = 1500) # bootstrap the indirect effect
summary(med) # ACME = indirect effect; ADE = direct; Prop. Mediatedimport pingouin as pg # not in the live runtime
pg.mediation_analysis(data=df, x="age", m="cigs", y="risk",
n_boot=1500) # 'indirect' row ~ ACME, with a bootstrap CIThe first R tab runs live (the Baron & Kenny coefficient‑shrink); the others are static references.
TipCheck your understanding
Age predicts heart risk. Add cigarettes to the model and age’s coefficient shrinks toward zero. What does that suggest — and how would you confirm it?
That smoking is mediating age’s effect: age → cigarettes → risk. If age’s direct effect drops all the way to ~0, it’s full mediation; if it only shrinks, partial. The coefficient shrink is the Baron & Kenny signal, but to confirm it’s real you test the indirect effect directly — a Sobel test, or (better) a bootstrapped ACME from mediate() — and check its confidence interval excludes zero.
Mediation is a causal claim wearing regression’s clothes. The Baron & Kenny pattern is consistent with A → M → B, but the same numbers can arise from reverse causation (B → M) or a common cause behind both — regression alone can’t tell them apart, so design and theory do the heavy lifting. Test the indirect effect itself (a bootstrapped ACME), not just “all four steps significant”; and prefer bootstrapping to the Sobel test, which assumes the indirect effect is normally distributed (it usually isn’t).
Where this shows up next
Its sibling is moderation (when the third variable changes rather than explains the effect). See Chapter (GLM Extensions) for the full worked mediation.