Search

Search papers and lessons

Mediation Analysis

Level 3 · 10 min read

Mediation analysis splits a treatment's total effect into a direct path and an indirect path that runs through a middle variable, the mediator.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Methods
  • Classical models
  • Losses & regularization
  • Discrete math
  • Sign in to see your progress

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 (aa and bb), and the direct effect is the arrow c′c' 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

Definition: Mediation model (linear case)

Let XX be the treatment, MM the mediator, and YY the outcome. A linear mediation model is a pair of regressions:

Mi=a0+a Xi+ε1i,Yi=b0+c′Xi+b Mi+ε2i.M_i = a_0 + a\,X_i + \varepsilon_{1i}, \qquad Y_i = b_0 + c' X_i + b\,M_i + \varepsilon_{2i}.

Here aa is the effect of treatment on the mediator, bb is the effect of the mediator on the outcome holding treatment fixed, and c′c' is the direct effect of treatment on the outcome.

Each equation is an ordinary linear regression. The error terms ε1i\varepsilon_{1i} and ε2i\varepsilon_{2i} are the parts the model does not explain.

Total, direct and indirect effects

If you regress YY on XX alone, the slope is the total effect cc. Substitute the mediator equation into the outcome equation and collect terms:

Yi=b0+c′Xi+b (a0+aXi+ε1i)+ε2i=(b0+ba0)+(c′+ab) Xi+(error).Y_i = b_0 + c' X_i + b\,(a_0 + a X_i + \varepsilon_{1i}) + \varepsilon_{2i} = (b_0 + b a_0) + (c' + ab)\,X_i + (\text{error}).

So the total effect is c=c′+abc = c' + ab. The direct effect is c′c' and the indirect effect is the product abab. 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 Y(x,m)Y(x, m) for the outcome a unit would have with treatment xx and mediator value mm, and M(x)M(x) for the mediator value it would have under treatment xx. Then

NIE=E[Y(1,M(1))−Y(1,M(0))],NDE=E[Y(1,M(0))−Y(0,M(0))].\text{NIE} = \mathbb{E}\left[Y\big(1, M(1)\big) - Y\big(1, M(0)\big)\right], \qquad \text{NDE} = \mathbb{E}\left[Y\big(1, M(0)\big) - Y\big(0, M(0)\big)\right].

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 =ab= ab and NDE =c′= c'.

What has to be true

To read abab 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

Example
A tiny hand-computable case

Let a=0.5a = 0.5, b=0.4b = 0.4 and c′=0.2c' = 0.2.

  1. Indirect effect: ab=0.5×0.4=0.20ab = 0.5 \times 0.4 = 0.20.
  2. Total effect: c=c′+ab=0.20+0.20=0.40c = c' + ab = 0.20 + 0.20 = 0.40.
  3. Share mediated: ab/c=0.20/0.40=0.5ab / c = 0.20 / 0.40 = 0.5, so half the total effect runs through the mediator.
  4. Check by direct substitution: raise XX by 1. The mediator rises by a=0.5a = 0.5. The outcome rises by c′=0.2c' = 0.2 directly and by b×0.5=0.2b \times 0.5 = 0.2 through the mediator. Total rise 0.40.4. Matches.

Interpretation: the treatment moves the outcome by 0.4 in total, and half of that comes from the mediator.

Example
A civics workshop (illustrative numbers)

These numbers are made up to show the arithmetic, not taken from a real study. A workshop raises a knowledge score by a=2.0a = 2.0 points. Each knowledge point raises turnout probability by b=0.015b = 0.015 (1.5 percentage points). The workshop has a direct effect c′=0.01c' = 0.01 (1 point) on turnout.

  1. Indirect effect: ab=2.0×0.015=0.030ab = 2.0 \times 0.015 = 0.030, which is 3 percentage points.
  2. Total effect: c=0.010+0.030=0.040c = 0.010 + 0.030 = 0.040, which is 4 percentage points.
  3. Share mediated: 0.030/0.040=0.750.030 / 0.040 = 0.75.
  4. 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 abab is not normally distributed, even when aa and bb are, so the usual zz-test is only approximate. The Sobel approximation uses SE⁡(ab)≈b2sa2+a2sb2\operatorname{SE}(ab) \approx \sqrt{b^2 s_a^2 + a^2 s_b^2}, where sas_a and sbs_b are the standard errors of aa and bb. Bootstrapping, resampling the data and recomputing abab many times, is now more common because it respects the skew of the product.

Tradeoffs and failure modes

SituationProblemBetter choice
Mediator is measured with errorIndirect effect is biased toward zeroMeasure the mediator better, or use a latent-variable model
Mediator is affected by confounders of the outcomePath bb is confounded, so abab is wrongDesign an experiment that randomizes the mediator, or use sensitivity analysis
Treatment and mediator interact in the outcomeThe linear abab misstates the effectUse the counterfactual definitions and estimate NIE and NDE directly
Binary outcome such as votingLinear abab is not on the probability scaleUse a counterfactual method that handles non-linear models
Several mediatorsTheir indirect effects can cancel or overlapSpecify each mediator and its own path, and check order

The most common failure is to run the regressions, see a significant abab, 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 aa and bb?Show answer

The indirect effect is abab: the effect of treatment on the mediator, times the effect of the mediator on the outcome holding treatment fixed.

QuestionComputation: with a=0.3a = 0.3, b=0.5b = 0.5 and c′=0.1c' = 0.1, what are the indirect effect, the total effect and the share mediated?Show answer

Indirect ab=0.15ab = 0.15. Total c=c′+ab=0.25c = c' + ab = 0.25. Share mediated =0.15/0.25=0.6= 0.15 / 0.25 = 0.6, 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 bb picks up that confounding, and abab 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.

Sources