27. Mediation

Author
Affiliation

Johnny van Doorn

University of Amsterdam

Published

November 11, 2025

In this lecture we aim to:

  • Explore mediation analysis
  • Link it to regression
  • Demonstrate in JASP

Reading: Chapter 10

Mediation

Mediation

In statistics, a mediation model is one that seeks to identify and explain the mechanism or process that underlies an observed relationship between an independent variable and a dependent variable via the inclusion of a third hypothetical variable, known as a mediator variable (also a mediating variable, intermediary variable, or intervening variable).

Source: WIKIPEDIA

Venn diagrams - effect

Venn diagrams - mediator

Example

Does the speed of recovery after sickness improve with the use of alternative medicine or is this effect mediated by a healthy lifestyle?

Total effect

  1. Total effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_t \text{Predictor}_i\)

Mediation Image

Mediation paths

You found my sneaky text to create space! You are awesome. Muahahahahahahahahahahahahahahahahahahahahahahahaha haha…hah.. uhhhh

  1. Total effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_t \text{Predictor}_i\)
  2. Mediator effect (a):
    • \(\widehat{\text{Mediator}} = b_0 + b_a \text{Predictor}_i\)
  3. Combined effect (b + c):
    • \(\widehat{\text{Outcome}} = b_0 + b_{c} \text{Predictor}_i + b_b \text{Mediator}_i\)

The data

Fit 3 models

model.outcome.predictor  <- lm(speed.of.healing  ~ use.homeopathic.remedies)
model.mediator.predictor <- lm(healthy.lifestyle ~ use.homeopathic.remedies)
model.combined           <- lm(speed.of.healing  ~ use.homeopathic.remedies + healthy.lifestyle)
  1. Total effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_t \text{Predictor}_i\)
  2. Mediator effect:
    • \(\widehat{\text{Mediator}} = b_0 + b_a \text{Predictor}_i\)
  3. Combined effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_{c} \text{Predictor}_i + b_b \text{Mediator}_i\)

Extract beta coëfficients

b.outcome.predictor       <- model.outcome.predictor$coefficients[2]   # b.t
b.mediator.predictor      <- model.mediator.predictor$coefficients[2]  # b.a
b.combined.mediator       <- model.combined$coefficients[3]            # b.b
b.combined.predictor      <- model.combined$coefficients[2]            # b.c
  1. Total effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_t \text{Predictor}_i\)
  2. Mediator effect:
    • \(\widehat{\text{Mediator}} = b_0 + b_a \text{Predictor}_i\)
  3. Combined effect:
    • \(\widehat{\text{Outcome}} = b_0 + b_{c} \text{Predictor}_i + b_b \text{Mediator}_i\)

View beta coëfficients

b.mediator.predictor     # b.a
[1] 1.530447
b.combined.mediator      # b.b
[1] 0.9725824

View beta coëfficients

b.outcome.predictor      # b.t 
[1] 2.035573
b.mediator.predictor     # b.a 
[1] 1.530447
b.combined.mediator      # b.b
[1] 0.9725824
b.combined.predictor     # b.c
[1] 0.5470875

Path plot

Visual

Calculate indirect effect

\(a \times b = b_a \times b_b\)

indirect <- b.mediator.predictor * b.combined.mediator; indirect  # a * b
[1] 1.488485
indirect + b.combined.predictor # a * b + c 
[1] 2.035573
b.outcome.predictor         # total effect
[1] 2.035573

Calculate indirect effect (standardized)

\(\frac{ab}{s_{Outcome}} \times s_{Predictor} = \frac{b_a b_b}{s_{Outcome}} \times s_{Predictor}\)

b.mediator.predictor*b.combined.mediator / 
  sd(speed.of.healing)*sd(use.homeopathic.remedies)
[1] 0.67769

Calculate \(P_M\)

\(\frac{ab}{total} = \frac{b_a b_b}{b_t} = \frac{b_a b_b}{b_a b_b + b_c}\)

(b.mediator.predictor*b.combined.mediator) /
  b.outcome.predictor
[1] 0.7312366

The proportion of the total effect that can be attributed to the mediator

Does not take into account size of total effect

“although it is tempting to think of \(P_M\) as a proportion (because it is the ratio of the indirect effect to the total effect) it is not: it can exceed 1 and even take negative values (Preacher & Kelley, 2011).”

Caution with PROCESS

When we test such hypotheses with the help of path models applied to observational data, we are in the business of causal inference on the basis of observational data

More examples

JASP Data Library

Closing

Recap

  • Mediation analysis is a way to model dependence between predictors
  • PROCESS module is very flexible
  • Causal assumptions extremely important with PROCESS models

Contact

CC BY-NC-SA 4.0