Mediation analysis

Analytika TeamLast reviewed 7 min read

Knowing that X is related to Y often prompts the next question: why? Mediation analysis tests a proposed mechanism, a mediator variable through which X’s effect travels. For example, does a training programme improve performance by increasing self-efficacy?

The paths

  • a: X → M
  • b: M → Y, controlling for X
  • c: total effect of X on Y
  • c′: direct effect of X on Y, controlling for M
  • Indirect effect = a × b, and for linear models c = c′ + ab

Why bootstrap?

The product a × b doesn’t have a normal sampling distribution, so the classic Sobel test is often inaccurate and underpowered. The modern standard resamples the data thousands of times, recalculates a × b each time, and uses the middle 95% as the confidence interval. If it excludes zero, there’s evidence of an indirect effect. The older Baron and Kenny “causal steps” approach is no longer recommended as the main test.

Worked example

In R’s mtcars data: does horsepower (X) relate to fuel economy (Y) partly through car weight (M), since more powerful cars tend to be heavier? Effects are shown per 100 hp.

PathEstimatep
a: horsepower → weight+0.94 (thousand lb)< .001
b: weight → mpg (controlling for hp)−3.88 mpg per 1,000 lb< .001
c: total effect of horsepower−6.82 mpg< .001
c′: direct effect of horsepower−3.18 mpg.001
Indirect effect (a × b)−3.65 mpg, 95% bootstrap CI [−6.26, −2.00]

The bootstrap interval excludes zero, so there’s evidence of an indirect effect through weight, about half (53%) of the total. The direct effect remains significant, a pattern described as partial mediation. The path coefficients match R’s lm() in Analytika’s test suite. The bootstrap uses 5,000 resamples with a fixed seed, so the interval is reproducible.

APA write-up

The association between horsepower and fuel economy was partly accounted for by weight. The indirect effect through weight was −3.65 mpg per 100 hp, 95% bootstrap CI [−6.26, −2.00] (5,000 resamples), and the direct effect remained, −3.18 mpg per 100 hp, p = .001.

Big cautions

  • Mediation is causal language. It assumes X causes M and M causes Y, and that no unmeasured variable confounds the M → Y link. Cross-sectional observational data can’t establish this. Describe results as “consistent with” mediation.
  • Temporal order: ideally X, M and Y are measured at successive times.
  • Alternative models (Y → M, or a confounder of M and Y) can fit the same data equally well.

For “when” rather than “how” questions, see moderation. More complex pathways can be modelled with SEM.

References

  • Hayes, A. F. (2018). Introduction to mediation, moderation, and conditional process analysis (2nd ed.). Guilford Press.
  • Preacher, K. J., & Hayes, A. F. (2008). Asymptotic and resampling strategies for assessing and comparing indirect effects in multiple mediator models. Behavior Research Methods, 40(3), 879–891.

More in Regression

Run this on your own data

Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.

Try it free