Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 055
Research workflow/5 steps

Causal mediation analysis (mediation)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 5 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 5
01
Data prep

Load package and data

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Load the mediation package and the JOBS II field-experiment data shipped with it.

Reads fromNot specified Feeds into#2
Key code
# Install:  install.packages("mediation")
library(mediation)
data(jobs)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

A fitted mediator model and a fitted outcome model sharing the same data with a treatment, a mediator, an outcome, and covariates.

Show data format & exampleHide example
id treat mediator outcome age
1 1 4.2 7 34
2 0 2.1 3 51
3 1 3.8 6 29
4 0 1.9 2 47
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureACME (mediated), ADE (direct) and total effect, each with a 95% confidence interval.

Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.

The estimate

\delta(t)=\mathbb E\big[\,Y!\big(t,M(1)\big)-Y!\big(t,M(0)\big)\big]

Context & interpretation

⚠️ Unofficial community showcase of mediation (docs). Not affiliated with the authors — all credit to Kosuke Imai & coauthors; this summarizes public documentation.

What it does: mediation implements the Imai-Keele-Tingley-Yamamoto framework for causal mediation, estimating the Average Causal Mediation Effect (ACME), the Average Direct Effect (ADE), and the total effect. How it works: you fit two models—a mediator model (mediator ~ treatment + covariates) and an outcome model (outcome ~ treatment + mediator + covariates)—then pass both to mediate(), which uses a quasi-Bayesian Monte Carlo or nonparametric bootstrap to simulate counterfactuals and produce point estimates with confidence intervals. It supports linear, GLM, ordered, quantile, GAM, and survival models. Assumptions: identification rests on sequential ignorability—no unmeasured treatment-outcome, treatment-mediator, or mediator-outcome confounding given covariates. Because this is untestable, medsens() provides a sensitivity analysis quantifying how strong unobserved confounding would need to be to nullify the estimated mediation effect.

What you get — ACME (indirect effect), ADE (direct effect), total effect, and proportion mediated, each with confidence intervals; plus optional sensitivity bounds.

Example output

Causal Mediation Analysis 

Quasi-Bayesian Confidence Intervals

                Estimate 95% CI Lower 95% CI Upper p-value
ACME            -0.01593     -0.03190         0.00    0.10
ADE             -0.03762     -0.08940         0.01    0.14
Total Effect    -0.05355     -0.10670         0.00    0.06
Prop. Mediated   0.29746     -0.06204         1.04    0.14

Sample Size Used: 899 

Simulations: 1000 

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion