Direct and indirect effects: mediation

Epidemiology guide, part 5

An exposure often acts through intermediate variables: obesity raises blood pressure, which raises the risk of a heart attack. Mediation analysis splits the total effect of an exposure into the part that goes through a mediator (the indirect effect) and the rest (the direct effect). The aim is to explain how an exposure works, or what share of its effect an intervention on the mediator could remove. It needs more assumptions than estimating a total effect, and those assumptions are where most mediation analyses fail (VanderWeele 2016; Hernán and Robins 2020).

Effects to estimate

Figure 1: Left, the total effect c of X on Y. Right, the same effect split into the path through the mediator M (a, from X to M, and b, from M to Y given X) and the direct path c′ (from X to Y given M).
effect question definition
Total effect (TE) what if X changed? compares Y with X and without X, M following X
Controlled direct effect (CDE) what if X changed and M were fixed at a value m for everyone? depends on m when X and M interact
Natural direct effect (NDE) what if X changed but M stayed as it would be without X? the effect not through M
Natural indirect effect (NIE) what if X stayed, but M changed as X would change it? the effect through M

On the difference scale TE = NDE + NIE, and the proportion mediated is NIE / TE. In linear models without an X × M interaction the classic approach of Baron and Kenny (Baron and Kenny 1986) gives them directly:

  • product method: NIE = a × b, NDE = c′;
  • difference method: NIE = c − c′.

The two agree for linear models of continuous outcomes. For binary and survival outcomes (logistic, Cox) they do not, because odds and hazard ratios are non-collapsible: c − c′ then mixes mediation with the change of scale (Measures and models). With an X × M interaction, or with non-linear models, natural effects need the counterfactual definitions and software that implements them (Imai et al. 2010).

The assumptions

Figure 2: Mediation needs every one of these confounders measured and adjusted for: C1 (exposure and outcome), C2 (mediator and outcome), C3 (exposure and mediator). L, a mediator-outcome confounder that the exposure itself affects, breaks the natural effects altogether.

Natural direct and indirect effects can be estimated only if there is no unmeasured confounding of (VanderWeele 2016):

  1. the exposure and the outcome (C1);
  2. the mediator and the outcome (C2), even in a randomised trial, because the mediator is not randomised. This is the assumption most often broken;
  3. the exposure and the mediator (C3);
  4. and no confounder of the mediator and the outcome is itself affected by the exposure (L).

Randomising X removes C1 and C3, not C2. The adjustment sets of the two regressions differ: the model for M needs the X–M confounders, and the model for Y needs the X–Y and M–Y confounders.

Example 1: full mediation (continuous outcome)

Formoterol vs salbutamol in asthma, children aged 7 to 14. Peak expiratory flow (PEF) rises with age, but age has no effect of its own in the scenario: older children are taller, and height determines lung size. Age acts entirely through height.

simulated population (30,000) a trial of 300: estimate (bootstrap 95% CI)
total effect of age (c) 13.03 11.5 (8.0 to 15.1)
age on height (a, cm per year) 4.36 4.3 (3.9 to 4.7)
height on PEF (b, L/min per cm) 3.02 3.44 (2.52 to 4.41)
direct effect of age (c’) -0.15 -3.3 (-8.3 to 1.8)
indirect effect (a × b) 13.18 14.8 (11.0 to 19.0)

Each year of age adds 13 L/min of PEF. Given height, age adds nothing (-0.1): the indirect effect a × b = 13.2 is the whole effect. In a trial of 300 children the indirect effect is estimated with a bootstrap confidence interval, because a product of two estimates is not normally distributed.

In jamovi: open the trial’s data and run jAMM ▸ GLM Mediation Model with pef as dependent variable, height as mediator, age as covariate (and drug as factor), bootstrap confidence intervals; or medmod ▸ Mediation for a single mediator without covariates. Both fit linear models (with lavaan), so they need a continuous mediator and outcome.

Example 2: partial mediation, with confounders of the mediator

Blood pressure in US adults, cross-sectional. People with a college education have lower systolic pressure, partly because they are less poor (the poverty ratio enters the outcome model) and partly for other reasons. Age and race affect education, poverty and blood pressure, so they confound both steps.

Figure 3: Education and blood pressure (Blood pressure in US adults): age and race (adjusted for, double border) confound education, poverty and blood pressure.
adjusted for age and race not adjusted
total -3.16 mmHg -5.26 mmHg
direct -2.50 mmHg -4.30 mmHg
indirect (through poverty) -0.66 mmHg -0.95 mmHg
proportion mediated 21% 18%

Most of the effect of college education here is direct; poverty carries a small part. Without adjusting for age and race the total effect is confounded: older people have less education and higher pressure.

Example 3: an event outcome, by the difference method

Coronary heart disease incidence: men have a higher hazard than women partly because they have lower HDL. jamovi’s mediation modules need a continuous outcome, so for a Cox model the usual approach is the difference method: the hazard ratio of sex before and after adding HDL, with the confounders of HDL and CHD (age, BMI) in both models.

Cox model HR of men, simulated cohort of 60,000 studysim’s truth
sex, age, BMI (total effect) 1.77 1.76
sex, age, BMI, HDL (direct effect) 1.56 1.60

On the log scale, (log 1.77 − log 1.56) / log 1.77 = 22% of the effect of sex goes through HDL. The approximation is reasonable here because coronary events are uncommon. With a common outcome the hazard ratio changes when a covariate is added even if it mediates nothing, so this share is not a mediated proportion. For binary or survival outcomes, estimate natural effects with the R package mediation (in jamovi, through the Rj editor) or with weighting methods.

A checklist

  1. Write the diagram with the exposure, the mediator, the outcome and the confounders of all three pairs (Causal diagrams).
  2. Make sure the mediator happens after the exposure and before the outcome.
  3. Adjust the mediator model for exposure-mediator confounders, and the outcome model for exposure-outcome and mediator-outcome confounders.
  4. Test the exposure × mediator interaction; if present, report controlled direct effects at chosen values of M, or natural effects from software that allows the interaction.
  5. Use bootstrap confidence intervals for indirect effects.
  6. Discuss unmeasured mediator-outcome confounding, which randomising the exposure does not remove, and run a sensitivity analysis.

Software

situation jamovi R
continuous M and Y, one mediator medmod Mediation lm, lavaan
several mediators, covariates, moderated mediation jAMM GLM Mediation Model lavaan
binary or survival Y, X × M interaction (Rj) mediation, CMAverse

References

Baron, Reuben M., and David A. Kenny. 1986. “The Moderator–Mediator Variable Distinction in Social Psychological Research: Conceptual, Strategic, and Statistical Considerations.” Journal of Personality and Social Psychology 51 (6): 1173–82. https://doi.org/10.1037/0022-3514.51.6.1173.
Hernán, Miguel A., and James M. Robins. 2020. Causal Inference: What If. Chapman & Hall/CRC. https://miguelhernan.org/whatifbook.
Imai, Kosuke, Luke Keele, and Dustin Tingley. 2010. “A General Approach to Causal Mediation Analysis.” Psychological Methods 15 (4): 309–34. https://doi.org/10.1037/a0020761.
VanderWeele, Tyler J. 2016. “Mediation Analysis: A Practitioner’s Guide.” Annual Review of Public Health 37 (1): 17–32. https://doi.org/10.1146/annurev-publhealth-032315-021402.