σ StatsDoge Causal inference workflows
9
Workflow·4 steps·branched

Causal mediation: natural direct & indirect effects (CMAverse)

Source CMAverse — Shi, Valeri et al.
Summary by StatsDoge

Decompose a total effect into what flows through the mediator (NIE) and what doesn't (NDE) using a g-formula / weighting backend. Pair with a sensitivity analysis: how strong an unmeasured mediator–outcome confounder would need to be to overturn the conclusion.

1

Input · what goes in

A treatment, a mediator on the causal path, an outcome, and the confounders of each link.

Show data format & exampleHide example

Format — one row per unit: treatment a, mediator m, outcome y, confounders C.

  a    m     y    c1   c2
  1   0.6   3.2  0.4  -1.1
  0   0.2   1.8 -0.1   0.6
2

Pipeline · the recipe ⑂ has parallel branches

↑ Click any step in the diagram to read its logic, code, assumptions & discussion.

1
Data prep

Treatment, mediator, outcome, confounders

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

What happens here

Lay out the mediation DAG and the confounders of the A→M, A→Y and M→Y links.

Formula
\mathrm{TE}=\underbrace{\mathrm{NDE}}_{ ext{not through }M}+\underbrace{\mathrm{NIE}}_{ ext{through }M}
Reads from the input data Feeds into the final output
Key code
library(CMAverse)
# a (treatment), m (mediator), y (outcome), C (confounders)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
2
Estimation

Fit mediator & outcome models

The core estimate — where the causal quantity itself is computed.

What happens here

A regression/g-formula (or weighting) approach to both models.

Formula
\mathrm{NDE}=\mathbb{E}ig[\,Y(1,M(0))-Y(0,M(0))\,ig]
Reads from the input data Feeds into the final output
Key code
cmest(data=df, model='rb', outcome='y', exposure='a',
      mediator='m', basec=C, EMint=TRUE)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3
Inference

Decompose the total effect

Uncertainty quantification — standard errors, intervals, and aggregation.

What happens here

Report the natural direct and indirect effects (and the mediated proportion).

Formula
\mathrm{NIE}=\mathbb{E}ig[\,Y(1,M(1))-Y(1,M(0))\,ig]
Reads from the input data Feeds into the final output
Key code
summary(res)  # NDE, NIE, total, proportion mediated

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
4
Robustness check

Sensitivity to mediator–outcome confounding

A robustness check — does the headline result survive a different lens?

What happens here

How strong an unmeasured M–Y confounder would overturn the conclusion.

Formula
\mathrm{NIE}( ho) o 0\ ext{as confounding } ho\ ext{grows}
Reads from the input data Feeds into the final output
Key code
cmsens(res, sens='uc')

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3

Output · what you get 2 figures

The causal diagram: treatment → mediator → outcome, with confounders of each link.
Fig 1The causal diagram: treatment → mediator → outcome, with confounders of each link.
Decomposition of the total effect into direct and mediated (indirect) components.
Fig 2Decomposition of the total effect into direct and mediated (indirect) components.

Figures reproduced from CMAverse — Shi, Valeri et al. — unofficial community showcase; all credit to the original authors.

⚠️ Unofficial community showcase of cmaverse. Not affiliated with the authors; all credit to them.

Split a total effect into what flows through a mediator (indirect) and what doesn't (direct) — with a sensitivity analysis for mediator–outcome confounding.

Discussion (0)

  • No comments yet — start the conversation.