Mediation Analysis

Mediation analysis is a decomposition of causal effects with mediation.


Background

Mediation looks like the following diagram.

path.png

where the true causal effects are as follows:


Description

Sobel Test

The Sobel test is a common approach for identifying and decomposing the mediated effects.

This example uses the multilevel package:

library(multilevel)

sorel(data$X, data$M, data$Y)

This displays:

Bootstrapping

A bootstrapping approach is more accurate.

This example also uses the mediation package:

XonY <- lm(Y ~ X, data = data)
XonM <- lm(M ~ X, data = data)
XMonY <- lm(Y ~ X + M, data = data)

library(mediation)

mediate(XonM, XMonY, treat='X', mediator='M', boot=TRUE, sims=500)

This displays:


CategoryRicottone

Statistics/MediationAnalysis (last edited 2026-02-17 15:42:31 by DominicRicottone)