TL;DR
A treatment often changes an outcome in two ways at once: directly, and by changing some intermediate variable that then changes the outcome. Mediation analysis is the method for pulling these apart. The intermediate variable is the mediator, the part that flows through it is the indirect effect, and the rest is the direct effect. Splitting the total effect this way answers "how" as well as "how much", but only under strong assumptions about confounding.
Where you'll see it: in studies asking whether a civic program works through knowledge, whether a policy reduces conflict through trust, and in any claim of the form "X affects Y because X changes Z".
Intuition
Two roads to the same place
Suppose a civics workshop is offered to a random set of voters. The workshop might raise turnout in two ways. It might teach people where and how to vote, which pushes turnout up directly. It might also raise political knowledge, and knowledge in turn makes people more likely to vote. Both roads lead to higher turnout, and the total effect is the sum of the two.
Mediation analysis asks how much of the effect travels along the second road.
flowchart LR X["Treatment X"] -- "a" --> M["Mediator M"] M -- "b" --> Y["Outcome Y"] X -- "c' (direct)" --> Y
The total effect is the direct arrow plus the product of the two arrows on the indirect path.
The indirect effect is the product of the two arrows on the mediated path ( and ), and the direct effect is the arrow that skips the mediator.
Note that the mediator is not a control variable. Controls are things you hold fixed. A mediator is something the treatment changes, and it is the channel you want to see.
The math
Let be the treatment, the mediator, and the outcome. A linear mediation model is a pair of regressions:
Here is the effect of treatment on the mediator, is the effect of the mediator on the outcome holding treatment fixed, and is the direct effect of treatment on the outcome.
Each equation is an ordinary linear regression. The error terms and are the parts the model does not explain.
Total, direct and indirect effects
If you regress on alone, the slope is the total effect . Substitute the mediator equation into the outcome equation and collect terms:
So the total effect is . The direct effect is and the indirect effect is the product . The indirect effect is the amount the treatment moves the mediator, multiplied by the amount the mediator moves the outcome.
The same idea in counterfactual language
The linear coefficients are a special case of a more general definition. Write for the outcome a unit would have with treatment and mediator value , and for the mediator value it would have under treatment . Then
NIE is the natural indirect effect: switch the mediator from its untreated value to its treated value, holding treatment at 1. NDE is the natural direct effect: switch treatment, holding the mediator at its untreated value. The two add up to the total effect. In a linear model with no interactions, NIE and NDE .
What has to be true
To read causally, you need the mediator to be as good as randomly assigned, given the observed covariates. Four conditions do the work: no unmeasured confounding of treatment and outcome, no unmeasured confounding of treatment and mediator, no unmeasured confounding of mediator and outcome, and no confounder of mediator and outcome that is itself affected by the treatment. The third is the hard one, because the mediator is usually chosen by the same people whose outcomes you measure. Randomizing the treatment does not randomize the mediator.
Worked examples
Let , and .
- Indirect effect: .
- Total effect: .
- Share mediated: , so half the total effect runs through the mediator.
- Check by direct substitution: raise by 1. The mediator rises by . The outcome rises by directly and by through the mediator. Total rise . Matches.
Interpretation: the treatment moves the outcome by 0.4 in total, and half of that comes from the mediator.
These numbers are made up to show the arithmetic, not taken from a real study. A workshop raises a knowledge score by points. Each knowledge point raises turnout probability by (1.5 percentage points). The workshop has a direct effect (1 point) on turnout.
- Indirect effect: , which is 3 percentage points.
- Total effect: , which is 4 percentage points.
- Share mediated: .
- Interpretation: most of the workshop's effect on turnout comes through knowledge, if the assumptions above hold. If knowledge is itself correlated with unmeasured motivation, the 3-point indirect effect is overstated.
The arithmetic is simple. The inference is where the work lies, which is why the assumptions in the math section come first.
Inference on the indirect effect
The product is not normally distributed, even when and are, so the usual -test is only approximate. The Sobel approximation uses , where and are the standard errors of and . Bootstrapping, resampling the data and recomputing many times, is now more common because it respects the skew of the product.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Mediator is measured with error | Indirect effect is biased toward zero | Measure the mediator better, or use a latent-variable model |
| Mediator is affected by confounders of the outcome | Path is confounded, so is wrong | Design an experiment that randomizes the mediator, or use sensitivity analysis |
| Treatment and mediator interact in the outcome | The linear misstates the effect | Use the counterfactual definitions and estimate NIE and NDE directly |
| Binary outcome such as voting | Linear is not on the probability scale | Use a counterfactual method that handles non-linear models |
| Several mediators | Their indirect effects can cancel or overlap | Specify each mediator and its own path, and check order |
The most common failure is to run the regressions, see a significant , and call it proven. A mediation result is only as strong as the assumption that nothing confounds the mediator and outcome. Treat it as a structured hypothesis, not a finding, unless the mediator was randomized.
History
Path analysis, the diagram-and-coefficient approach underneath mediation, began with the geneticist Sewall Wright in the 1920s, who used path coefficients to decompose correlations among traits. Social psychologists took up the idea in the 1980s. Reuben Baron and David Kenny's 1986 paper gave the field a three-step recipe, and it became the standard way to test mediation for decades. The Sobel test, from Michael Sobel in the early 1980s, gave the indirect effect a standard error. Later work by Kosuke Imai, Luke Keele and Teppei Yamamoto, around 2010, reframed mediation in the counterfactual language used above and showed what assumptions the older recipes needed. The method spread into political science, public health and economics because the question of "how" is so often the question that matters.
Check yourself
QuestionRecall: what is the indirect effect in a linear mediation model, in terms of and ?Show answer
The indirect effect is : the effect of treatment on the mediator, times the effect of the mediator on the outcome holding treatment fixed.
QuestionComputation: with , and , what are the indirect effect, the total effect and the share mediated?Show answer
Indirect . Total . Share mediated , so 60 percent of the total effect runs through the mediator.
QuestionWhy: why can't a randomized treatment alone guarantee that the indirect effect is causal?Show answer
Randomizing the treatment makes the comparison between treated and untreated units fair for the total effect. It does not randomize the mediator, which is a post-treatment variable that units themselves may differ on. If some unmeasured trait affects both the mediator and the outcome, the path picks up that confounding, and is biased even though the treatment was randomized.
QuestionApplied: a study finds that a training program raises job offers, and that the effect is 'fully mediated' by interview skills. What should you check before believing that?Show answer
Check that interview skills were measured after the program but before job offers were decided, and whether anything else that affects both interview skills and job offers was left out, such as motivation or prior work experience. Also check whether the study randomized the mediator or only the program. Without a design that handles the mediator, "fully mediated" is a hypothesis about the path, not an established finding.