A forking path splitting around a central node

A training programme improves test scores. But why? Because it raised study hours, or because it reduced test anxiety, or both? A treatment lowers blood pressure. Is the benefit mediated by sodium intake, or does the drug act directly on vascular tone?

Mediation analysis tries to decompose a total effect into a part that runs through a proposed mechanism and a part that does not. It is one of the most requested analyses in applied research and one of the most frequently over-interpreted, because the question it answers is causal and the data are usually observational.

The decomposition

With a predictor X, a mediator M and an outcome Y, the standard parameterisation uses two equations. One models the mediator as a function of X, with coefficient a. The other models the outcome as a function of X and M, with coefficient b for the mediator and c’ for the direct effect of X.

M = i1 + a·X + e1
Y = i2 + c'·X + b·M + e2

The indirect effect is the product a·b. The direct effect is c’. Their sum is the total effect c, which is what a simple regression of Y on X estimates when M is omitted.

QuantityMeaningEstimated by
Total effect (c)Change in Y per unit X, ignoring the mechanismRegression of Y on X
Direct effect (c′)Change in Y per unit X holding M fixedCoefficient of X in the model with M
Indirect effect (a·b)Change in Y transmitted through MProduct of the two path coefficients

Baron and Kenny, and why the steps are obsolete

The classic recipe required four conditions: X predicts Y, X predicts M, M predicts Y controlling for X, and the X coefficient shrinks once M is added. It is still taught, and it is still wrong in three specific ways.

  • Requiring a significant total effect excludes real mechanisms that operate alongside opposing pathways, where the total effect is near zero while the indirect effect is substantial.
  • The stepwise logic uses significance tests as gates, which conflates effect size with sample size at every step.
  • It provides no interval for the indirect effect, which is the quantity of interest.

Modern practice estimates a·b directly and puts a confidence interval around it. The total effect is reported for context, not used as a precondition.

Why the interval must be bootstrapped

The sampling distribution of a product of two coefficients is not normal, and it is usually skewed. The Sobel test, which assumes normality and divides a·b by an approximate standard error, therefore produces intervals that are too narrow and p-values that are too small, especially for modest sample sizes.

Bootstrap resampling sidesteps the algebra entirely: resample the data with replacement many times, compute a·b in each resample, and use the empirical distribution of those estimates. The resulting interval is asymmetric when the estimate is, which is the correct shape.

# R
library(mediation)
med <- lm(study_hours ~ training + baseline, data = dat)
out <- lm(score ~ training + study_hours + baseline, data = dat)

res <- mediate(med, out, treat = "training", mediator = "study_hours",
               boot = TRUE, sims = 5000)
summary(res)
# Python
import pingouin as pg
pg.mediation_analysis(data=dat, x="training", m="study_hours",
                      y="score", covar=["baseline"],
                      n_boot=5000, seed=42)

The percentile interval is the default and is usually adequate. Bias-corrected and accelerated (BCa) intervals adjust for skew and bias and are preferable when the bootstrap distribution is markedly asymmetric. What matters most is that the interval is bootstrap-based at all, and that the number of resamples is stated.

The assumptions nobody can test for you

This is the part that separates a defensible mediation analysis from a path diagram with numbers attached. Four assumptions are required, and the two most important ones cannot be verified from the data.

AssumptionTestable?What violating it does
Temporal order X → M → YOnly by designReverses the causal story entirely
No unmeasured confounding of X → YNoBiases total and direct effects
No unmeasured confounding of M → YNoBiases the indirect effect; the fatal one
No unmeasured confounding of X → MNoBiases a, and therefore a·b

The M→Y assumption is the strictest. M is not randomised, so anything that predicts both the mediator and the outcome — and is not in the model — contaminates the indirect effect. In observational data this is almost always plausible, which is why a mediation claim from cross-sectional data should be written as an association consistent with mediation rather than as a mechanism.

Temporal ordering deserves equal weight. If X, M and Y are all measured on the same day, the data cannot distinguish X → M → Y from M → X → Y, and both may fit equally well. The design, not the statistics, has to settle it.

When the mechanism itself depends on something

If the effect of M on Y differs across levels of X — that is, if there is an X×M interaction — the simple a·b decomposition no longer holds, because the indirect effect is not constant. Moderated mediation handles this by estimating conditional indirect effects, and the reporting burden rises accordingly.

library(lavaan)
model <- '
  M ~ a*X
  Y ~ c*X + b*M
  indirect := a*b
  direct   := c
  total    := c + a*b
'
fit <- sem(model, data = dat, se = "bootstrap", bootstrap = 5000)
parameterEstimates(fit, boot.ci.type = "bca.simple")

Structural equation models are the flexible option here: multiple mediators, moderated paths and latent variables are all expressible, and bootstrapped intervals remain available. The assumptions do not become easier, though — a larger model simply has more untestable claims in it.

Causal mediation and sensitivity analysis

The counterfactual formulation defines natural direct and indirect effects as contrasts between potential outcomes under different mediator values, which is what makes the causal assumptions explicit rather than implicit. When the assumptions can be argued from design — a randomised X, a well-measured mediator, plausible exclusion restrictions — this framing is far more defensible than the regression decomposition alone.

Because the key assumption is untestable, sensitivity analysis is not optional. Report how strong an unmeasured confounder of the M→Y relationship would have to be to reduce the indirect effect to zero. If a modest one would do it, say so.

library(medsens)
sens <- medsens(res)
summary(sens)
plot(sens)

What to report

Give the estimated paths a, b, c′ and the total effect, each with a confidence interval; the indirect effect a·b with a bootstrap interval and the number of resamples; the interval type; the covariates included in both models; the temporal ordering of measurement; and an explicit statement of the confounding assumptions plus the sensitivity result.

Treat the proportion mediated with suspicion. It is a ratio of two estimated quantities, so it is unstable when the total effect is small, can exceed one or fall below zero when pathways oppose each other, and is not an effect size. Report absolute effects instead, and mention the proportion only if it is stable and interpretable.

Mediation, moderation and confounding are three different questions about the same three variables, and mixing them up is the most common error in this literature. If you want the confounding side worked through properly, Ampersand Academy covers causal inference from observational data in depth.

Practice

  1. Fit the two-equation model and compute a·b by hand, then compare it with the bootstrap interval.
  2. Run the Sobel test alongside the bootstrap and describe how the interval widths differ.
  3. Refit with an additional covariate predicting both mediator and outcome and record how much the indirect effect moves.
  4. Write a two-sentence conclusion that states the assumptions the finding depends on.

What is an indirect effect in mediation analysis?

The part of the effect of X on Y that operates through the mediator M, estimated as the product of the X→M path (a) and the M→Y path (b). It is reported with a confidence interval, usually bootstrapped, and is distinct from the direct effect that bypasses M.

Do I need a significant total effect to test mediation?

No. That was a Baron and Kenny requirement and it is now considered incorrect. Opposing direct and indirect pathways can cancel, leaving a total effect near zero while the indirect effect is substantial. Estimate the indirect effect directly.

Why is the Sobel test no longer recommended?

It assumes the product of coefficients is normally distributed, which it is not: the sampling distribution is typically skewed. That makes Sobel intervals too narrow and p-values too small. Bootstrap intervals make no such assumption and are the standard.

How many bootstrap resamples do I need?

Five thousand is a common and adequate default for confidence intervals; ten thousand is used for BCa intervals or when the estimate is unstable. Report the number used, because a small number makes the interval itself noisy.

What is the biggest threat to a mediation analysis?

Unmeasured confounding of the mediator-outcome relationship. Because the mediator is not randomised, any variable that predicts both the mediator and the outcome will bias the indirect effect. It cannot be tested from the data and must be argued and probed with sensitivity analysis.

Can I do mediation analysis with cross-sectional data?

You can estimate the decomposition, but you cannot establish the temporal ordering it requires, so the result is an association consistent with mediation, not evidence of a mechanism. Say so explicitly rather than implying a causal pathway.

Should I report the proportion mediated?

Only cautiously, and never as the headline. It is a ratio of estimated quantities, becomes unstable when the total effect is small, and can exceed 1 or go negative when pathways oppose each other. Report absolute direct and indirect effects instead.

Last updated on · Written by