Algorithm Search⌘K

Techniqueadvanced

Mediation analysis

Also called natural direct and indirect effects, causal mediation analysis.

Splits a total effect into the part that goes through a mediator and the part that does not, defined by nested counterfactuals and identified under strong assumptions.

Mediation analysis asks how a treatment AA has its effect on an outcome YY: how much of the effect goes through an intermediate variable MM, the mediator, and how much goes by other paths. A training program may raise wages partly because it raises skills and partly because the certificate signals something to employers. The natural indirect effect is the change in YY when the mediator is moved from the value it would have without treatment to the value it would have with treatment, holding the treatment fixed. The natural direct effect is the change in YY when the treatment changes but the mediator is held at its untreated value. Both are defined by nested potential outcomes such as Y(1,M(0))Y(1, M(0)), which no unit can ever show, since it combines the treated world for YY with the untreated world for MM. They add up to the total effect. They can be estimated by the mediation formula, but only under sequential ignorability, which includes an assumption that no experiment can check. In linear models without interaction the indirect effect is the product of two regression coefficients, and that product equals the difference between the total and the direct coefficient exactly.

In plain words

A drug lowers heart attacks. Part of the reason is that it lowers cholesterol, and part may be something else, like lower inflammation. To split the effect, imagine giving each patient the drug but somehow keeping their cholesterol where it would have been without the drug. The change from no drug to this strange situation is the direct effect. The change from this situation to the plain drug, which lets cholesterol fall, is the indirect effect. The two pieces add to the whole effect.

The strange situation is never observed, not even in an ideal experiment, because a patient's cholesterol without the drug and their outcome with the drug come from two different worlds. So the split needs assumptions that are stronger than for the total effect.

When it applies

A binary treatment AA, a mediator MM that occurs after AA and before YY, an outcome YY, and pre-treatment covariates XX. The potential mediator is M(a)M(a) and the potential outcome is Y(a,m)Y(a, m); consistency says M=M(A)M = M(A) and Y=Y(A,M)Y = Y(A, M). The effects are, for the average over the population:

  • Total effect. TE=E[Y(1,M(1))−Y(0,M(0))]\mathrm{TE} = \mathbb{E}[Y(1, M(1)) - Y(0, M(0))], the usual average treatment effect.
  • Controlled direct effect. CDE(m)=E[Y(1,m)−Y(0,m)]\mathrm{CDE}(m) = \mathbb{E}[Y(1, m) - Y(0, m)], the effect of AA when MM is set to mm for everyone.
  • Natural direct effect. NDE=E[Y(1,M(0))−Y(0,M(0))]\mathrm{NDE} = \mathbb{E}[Y(1, M(0)) - Y(0, M(0))].
  • Natural indirect effect. NIE=E[Y(1,M(1))−Y(1,M(0))]\mathrm{NIE} = \mathbb{E}[Y(1, M(1)) - Y(1, M(0))].

Adding the last two, the middle terms cancel: NDE+NIE=TE\mathrm{NDE} + \mathrm{NIE} = \mathrm{TE}. The other order of the telescoping sum, E[Y(1,M(1))−Y(0,M(1))]+E[Y(0,M(1))−Y(0,M(0))]\mathbb{E}[Y(1, M(1)) - Y(0, M(1))] + \mathbb{E}[Y(0, M(1)) - Y(0, M(0))], gives a second split, and the two differ when AA and MM interact.

Identification. Sequential ignorability (Imai, Keele and Yamamoto 2010) assumes, for all a,a′,ma, a', m:

  1. {Y(a′,m),M(a)}\{Y(a', m), M(a)\} is independent of AA given XX: no unmeasured confounding of the treatment, as in ignorability;
  2. Y(a′,m)Y(a', m) is independent of M(a)M(a) given A=aA = a and XX: no unmeasured confounding of the mediator and the outcome, including the case a′≠aa' \ne a;

and positivity, Pr⁡[M=m∣A=a,X=x]>0\Pr[M = m \mid A = a, X = x] > 0 where needed. Then the mediation formula of Pearl (2001) holds:

E[Y(a,M(a∗))]=∑x∑mE[Y∣A=a,M=m,X=x] Pr⁡[M=m∣A=a∗,X=x] Pr⁡[X=x],\mathbb{E}[Y(a, M(a^*))] = \sum_x\sum_m\mathbb{E}[Y \mid A = a, M = m, X = x]\,\Pr[M = m \mid A = a^*, X = x]\,\Pr[X = x],

with integrals in place of sums for continuous variables.

Proof. Fix xx and condition on X=xX = x throughout. Then E[Y(a,M(a∗))]=∑mE[Y(a,m)∣M(a∗)=m]Pr⁡[M(a∗)=m]\mathbb{E}[Y(a, M(a^*))] = \sum_m\mathbb{E}[Y(a, m) \mid M(a^*) = m]\Pr[M(a^*) = m]. For the second factor, assumption 1 gives Pr⁡[M(a∗)=m]=Pr⁡[M(a∗)=m∣A=a∗]=Pr⁡[M=m∣A=a∗]\Pr[M(a^*) = m] = \Pr[M(a^*) = m \mid A = a^*] = \Pr[M = m \mid A = a^*]. For the first factor,

E[Y(a,m)∣M(a∗)=m]=1E[Y(a,m)∣M(a∗)=m,A=a∗]=2E[Y(a,m)∣A=a∗]=1E[Y(a,m)∣A=a]=2E[Y(a,m)∣M(a)=m,A=a],\mathbb{E}[Y(a, m) \mid M(a^*) = m] \overset{1}{=} \mathbb{E}[Y(a, m) \mid M(a^*) = m, A = a^*] \overset{2}{=} \mathbb{E}[Y(a, m) \mid A = a^*] \overset{1}{=} \mathbb{E}[Y(a, m) \mid A = a] \overset{2}{=} \mathbb{E}[Y(a, m) \mid M(a) = m, A = a],

and the last term is E[Y∣A=a,M=m]\mathbb{E}[Y \mid A = a, M = m] by consistency. The first step uses the joint independence in 1, the second uses 2 with A=a∗A = a^*, the third uses 1, and the fourth uses 2 with A=aA = a. Averaging over xx gives the formula. ■\blacksquare

The second step, with a≠a∗a \ne a^*, is the cross-world part: it relates Y(a,m)Y(a, m) to M(a∗)M(a^*), two quantities that never coexist. Robins and Richardson (2010) point out that no experiment, even one that randomizes both AA and MM, can test it, so the natural effects are identified only under an assumption that is not testable in principle. The controlled direct effect needs only the same-world parts and is identified by ∑x(E[Y∣1,m,x]−E[Y∣0,m,x])Pr⁡[x]\sum_x(\mathbb{E}[Y \mid 1, m, x] - \mathbb{E}[Y \mid 0, m, x])\Pr[x]. The method does not apply when a variable affected by AA confounds MM and YY, since then assumption 2 fails for every choice of XX that excludes it, and the natural effects are not identified at all without further assumptions.

The template

Estimation. The plug-in version of the mediation formula:

  1. MEDIATION(data, X)
  2. 1fit an outcome model μ(a, m, x) for E[Y | A = a, M = m, X = x]
  3. 2fit a mediator model p(m | a, x) for Pr[M = m | A = a, X = x]
  4. 3θ(a, a*) ← (1/n) Σᵢ Σ_m μ(a, m, Xᵢ) p(m | a*, Xᵢ) ▷ for (a, a*) in {(0, 0), (1, 0), (1, 1)}
  5. 4NDE ← θ(1, 0) - θ(0, 0); NIE ← θ(1, 1) - θ(1, 0)
  6. 5return (NDE, NIE), with intervals from the bootstrap or the delta method

For a continuous mediator, line L3 integrates over the fitted density of MM, usually by drawing mediator values from it, as in the algorithm of Imai, Keele and Tingley (2010). For OLS models it has a closed form.

Linear models. Suppose E[M∣A,X]=α0+αA+αx⊤X\mathbb{E}[M \mid A, X] = \alpha_0 + \alpha A + \alpha_x^\top X and E[Y∣A,M,X]=β0+γA+βM+θAM+βx⊤X\mathbb{E}[Y \mid A, M, X] = \beta_0 + \gamma A + \beta M + \theta AM + \beta_x^\top X. Plugging these into the mediation formula (VanderWeele and Vansteelandt 2009), with mˉ0=α0+αx⊤E[X]\bar m_0 = \alpha_0 + \alpha_x^\top\mathbb{E}[X] the mean mediator without treatment:

NDE=γ+θ mˉ0,NIE=α(β+θ).\mathrm{NDE} = \gamma + \theta\,\bar m_0, \qquad \mathrm{NIE} = \alpha(\beta + \theta).

Without interaction, θ=0\theta = 0, these are the classical NDE=γ\mathrm{NDE} = \gamma and NIE=αβ\mathrm{NIE} = \alpha\beta, the product of coefficients of Baron and Kenny (1986).

Product equals difference, exactly. Let τ^\hat\tau be the OLS coefficient of AA in the regression of YY on (1,A)(1, A), α^\hat\alpha that of MM on (1,A)(1, A), and γ^,β^\hat\gamma, \hat\beta those of YY on (1,A,M)(1, A, M). Then in every sample

τ^−γ^=α^β^.\hat\tau - \hat\gamma = \hat\alpha\hat\beta.

Proof. Write the long regression as Yi=β^0+γ^Ai+β^Mi+e^iY_i = \hat\beta_0 + \hat\gamma A_i + \hat\beta M_i + \hat e_i, where the residuals e^\hat e are orthogonal to 11, AA and MM. Take the sample covariance of both sides with AA: Cov^(A,Y)=γ^ Var^(A)+β^ Cov^(A,M)+0\widehat{\mathrm{Cov}}(A, Y) = \hat\gamma\,\widehat{\mathrm{Var}}(A) + \hat\beta\,\widehat{\mathrm{Cov}}(A, M) + 0. Divide by Var^(A)\widehat{\mathrm{Var}}(A): the left side is τ^\hat\tau and Cov^(A,M)/Var^(A)=α^\widehat{\mathrm{Cov}}(A, M)/\widehat{\mathrm{Var}}(A) = \hat\alpha. ■\blacksquare

With the same covariates XX in all three regressions the identity still holds, by the Frisch-Waugh-Lovell theorem applied after removing XX from AA, MM and YY. It is an algebraic fact, not a causal one: it holds for any variable MM, mediator or not. It fails for logistic and other nonlinear models, where the two methods give different answers.

Worked example. No covariates, binary AA and MM, and a population with

Pr⁡[M=1∣A]\Pr[M = 1 \mid A] E[Y∣A,M=0]\mathbb{E}[Y \mid A, M = 0] E[Y∣A,M=1]\mathbb{E}[Y \mid A, M = 1]
A=0A = 0 0.2 1 3
A=1A = 1 0.6 2 5

With AA randomized and sequential ignorability, the mediation formula gives

  • θ(0,0)=1⋅0.8+3⋅0.2=1.4\theta(0, 0) = 1 \cdot 0.8 + 3 \cdot 0.2 = 1.4,
  • θ(1,1)=2⋅0.4+5⋅0.6=3.8\theta(1, 1) = 2 \cdot 0.4 + 5 \cdot 0.6 = 3.8,
  • θ(1,0)=2⋅0.8+5⋅0.2=2.6\theta(1, 0) = 2 \cdot 0.8 + 5 \cdot 0.2 = 2.6,

so TE=2.4\mathrm{TE} = 2.4, NDE=2.6−1.4=1.2\mathrm{NDE} = 2.6 - 1.4 = 1.2 and NIE=3.8−2.6=1.2\mathrm{NIE} = 3.8 - 2.6 = 1.2. The linear formulas agree: the saturated outcome regression has β0=1\beta_0 = 1, γ=1\gamma = 1, β=2\beta = 2, θ=5−2−3+1=1\theta = 5 - 2 - 3 + 1 = 1, and the mediator regression has α0=0.2\alpha_0 = 0.2, α=0.4\alpha = 0.4, so NDE=1+1⋅0.2=1.2\mathrm{NDE} = 1 + 1 \cdot 0.2 = 1.2 and NIE=0.4⋅(2+1)=1.2\mathrm{NIE} = 0.4 \cdot (2 + 1) = 1.2. The other split uses θ(0,1)=1⋅0.4+3⋅0.6=2.2\theta(0, 1) = 1 \cdot 0.4 + 3 \cdot 0.6 = 2.2: direct effect 3.8−2.2=1.63.8 - 2.2 = 1.6 and indirect effect 2.2−1.4=0.82.2 - 1.4 = 0.8, again summing to 2.4. The difference comes from the interaction θ=1\theta = 1. The controlled direct effects are CDE(0)=1\mathrm{CDE}(0) = 1 and CDE(1)=2\mathrm{CDE}(1) = 2.

Classic examples

  • Psychology. Baron and Kenny (1986) set the practice of testing whether AA affects MM, whether MM affects YY given AA, and whether the effect of AA shrinks when MM is added. Their paper is among the most cited in the field; the causal assumptions behind it were made explicit only later.
  • Epidemiology. How much of the effect of smoking on low birth weight goes through gestational age, or how much of the effect of education on health goes through income. Robins and Greenland (1992) gave the counterfactual definitions in this setting.
  • Genetics. How much of the effect of a variant on disease goes through a measured gene expression or a biomarker.
  • Policy. How much of the effect of a job training program on earnings goes through employment and how much through hourly wages.
  • Fairness. Path-specific effects, a generalization, ask how much of the effect of a protected attribute on a decision goes through permitted and forbidden paths.

Variations

  • Interventional effects. Replace M(a∗)M(a^*) by a random draw from the distribution of M(a∗)M(a^*). The effects then need no cross-world assumption, and they are identified even with a treatment-induced confounder of MM and YY, but they no longer add up to the total effect in general.
  • Several mediators. Joint natural effects through a set of mediators are identified like one; splitting between correlated mediators needs more assumptions or path-specific effects.
  • Sensitivity analysis. Imai, Keele and Tingley (2010) index violations of assumption 2 by the correlation ρ\rho between the error terms of the mediator and outcome models and report the ρ\rho at which the indirect effect would vanish, in the spirit of Rosenbaum's sensitivity analysis.
  • Weighting and doubly robust estimators. Inverse probability weighting by the mediator model, and estimators that combine weighting with the outcome model so that one correct model suffices.
  • Front-door adjustment. If MM carries the whole effect and the treatment-outcome confounding does not touch MM, the total effect is identified through MM even with unmeasured confounding of AA and YY. This is the front-door criterion of Pearl, listed under see also.
  • Principal stratification. For effects within strata of (M(0),M(1))(M(0), M(1)), as with compliers in the local average treatment effect theorem.

Pitfalls

  • Assuming the mediator is randomized because the treatment is. Randomizing AA gives assumption 1 for free but says nothing about assumption 2. A confounder of MM and YY biases both natural effects, even in a perfect trial.
  • Adjusting for variables affected by the treatment. Putting a post-treatment variable in XX breaks assumption 1; if it confounds MM and YY, the natural effects are not identified.
  • Using the Baron-Kenny steps as a causal test. Requiring a significant total effect before looking for mediation has low power and is not needed; a significant product of coefficients is not evidence of a causal path unless the assumptions hold.
  • Ignoring the interaction. With A×MA \times M interaction, γ\gamma is a controlled direct effect at M=0M = 0, not the natural direct effect, and αβ\alpha\beta is not the indirect effect.
  • Nonlinear models and the difference method. In logistic regression, the change in the coefficient of AA when MM is added mixes mediation with the noncollapsibility of the odds ratio.
  • Measurement error in MM. In linear models, classical error in MM biases the indirect effect toward 0 and the direct effect away from it.
  • Reading the proportion mediated as a fraction of people. NIE/TE\mathrm{NIE}/\mathrm{TE} can be above 1 or negative when the two effects have opposite signs.

Exercises

  1. Show that NDE+NIE=TE\mathrm{NDE} + \mathrm{NIE} = \mathrm{TE}, and that the second split, with E[Y(1,M(1))−Y(0,M(1))]\mathbb{E}[Y(1, M(1)) - Y(0, M(1))] as the direct part, also sums to TE\mathrm{TE}.
  2. In the worked example, compute NDE\mathrm{NDE} and NIE\mathrm{NIE} from the linear formulas with mˉ0\bar m_0 replaced by mˉ1=0.6\bar m_1 = 0.6 and β\beta by β\beta alone, and say which split these numbers give.
  3. Show that if θ=0\theta = 0 and there are no covariates, the plug-in NIE is α^β^\hat\alpha\hat\beta and that it equals τ^−γ^\hat\tau - \hat\gamma.
  4. A trial randomizes both AA and MM (for example, a drug and a dose of a cholesterol-lowering agent). Which effects does it identify without further assumptions?
  5. Give an example where NIE\mathrm{NIE} and NDE\mathrm{NDE} have opposite signs, and explain why the proportion mediated is then misleading.

References

  1. Reuben M. Baron and David A. Kenny, The moderator-mediator variable distinction in social psychological research, conceptual, strategic, and statistical considerations, Journal of Personality and Social Psychology 51(6), 1986, pp. 1173 to 1182 (the regression steps for mediation and the product of coefficients)
  2. James M. Robins and Sander Greenland, Identifiability and exchangeability for direct and indirect effects, Epidemiology 3(2), 1992, pp. 143 to 155 (the nested counterfactual definitions of direct and indirect effects and their identification problems)
  3. Judea Pearl, Direct and indirect effects, Proceedings of the Seventeenth Conference on Uncertainty in Artificial Intelligence, 2001, pp. 411 to 420 (natural direct and indirect effects and the mediation formula)
  4. Kosuke Imai, Luke Keele and Dustin Tingley, A general approach to causal mediation analysis, Psychological Methods 15(4), 2010, pp. 309 to 334 (sequential ignorability, the estimation algorithm by simulation, sensitivity analysis)
  5. Kosuke Imai, Luke Keele and Teppei Yamamoto, Identification, inference and sensitivity analysis for causal mediation effects, Statistical Science 25(1), 2010, pp. 51 to 71 (the identification theorem under sequential ignorability and the sensitivity parameter)
  6. James M. Robins and Thomas S. Richardson, Alternative graphical causal models and the identification of direct effects, in Causality and Psychopathology, Oxford University Press, 2010, the whole chapter (cross-world independence, why no experiment identifies natural effects; general locator, the page numbers were not checked)
  7. Tyler J. VanderWeele and Stijn Vansteelandt, Conceptual issues concerning mediation, interventions and composition, Statistics and Its Interface 2(4), 2009, pp. 457 to 468 (the regression formulas for natural effects with an exposure-mediator interaction)
  8. Tyler J. VanderWeele, Explanation in Causal Inference, Methods for Mediation and Interaction, Oxford University Press, 2015, Chapters 2 and 3 on mediation with regression and on sensitivity analysis (general locator, the section numbers were not checked)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises