Modern Causal Mediation Analysis

Authors
Affiliations

Ivan Diaz

NYU Population Health

Nima Hejazi

Harvard Biostatistics

Kara Rudolph

Columbia Epidemiology

Nick Williams

University of California, Berkeley

Welcome!

This open source, reproducible vignette accompanies a half-day workshop on modern methods for causal mediation analysis. This version is adapted from our SER workshop to be slightly shorter and for a more applied audience.

About this workshop

Causal mediation analysis can provide a mechanistic understanding of how an exposure impacts an outcome, a central goal in epidemiology and health sciences. However, rapid methodologic developments coupled with few formal courses presents challenges to implementation. Beginning with an overview of classical direct and indirect effects, this workshop will present recent advances that overcome limitations of previous methods, allowing for: (i) continuous exposures, (ii) multiple, non-independent mediators, and (iii) effects identifiable in the presence of intermediate confounders affected by exposure. Emphasis will be placed on flexible, stochastic and interventional direct and indirect effects, highlighting how these may be applied to answer substantive epidemiological questions from real-world studies. Multiply robust, nonparametric estimators of these causal effects, and free and open source R packages (crumble) for their application, will be introduced.

To aid translation to real-world data analysis, this workshop will incorporate hands-on R programming exercises to allow participants practice in implementing the statistical tools presented. It is recommended that participants have working knowledge of the basic notions of causal inference, including counterfactuals and identification (linking the causal effect to a parameter estimable from the observed data distribution). Familiarity with the R programming language is also recommended.

Tentative schedule

  • Introductions + mediation set-up
  • Controlled direct effects, natural direct/indirect effects, interventional direct/indirect effects
  • Choosing an estimand in real-world examples
  • What is the EIF?!
  • Using the EIF for estimating the natural direct effect
  • Example walkthrough with R packages for effect estimation

Reproducibility note

These workshop materials were written using the Quarto, an open-source, cross-platform technical publishing system built on RMarkdown, and the complete source is available on GitHub. This version of the book was built with R version 4.5.1 (2025-06-13), pandoc version 3.6.3, and quarto version 1.8.24. See the renv.lock file in the source repository for an up-to-date list of the packages used.

Setup instructions

R and RStudio

R and RStudio are separate downloads and installations. R is the underlying statistical computing environment. RStudio is a graphical integrated development environment (IDE) that makes using R much easier and more interactive. You need to install R before you install RStudio.

Virtual environment setup with renv

These instructions are intended to help with setting up the included renv virtual environment, which ensures all participants are using the same exact set of R packages (and package versions). A few important notes to keep in mind:

  • When R is started from the top level of this repository, renv is activated automatically. There is no further action required on your part. If renv is not installed, it will be installed automatically, assuming that you have an active internet connection.
  • While renv is active, the R session will only have access to the packages (and their dependencies) that are listed in the renv.lock file—that is, you should not expect to have access to any other R packages that may be installed elsewhere on the computing system in use.
  • Upon an initial attempt, renv will prompt you to install packages listed in the renv.lock file, by printing a message.

In any such case, please call renv::status() to review the list of packages missing and to view renv’s recommendations for fixing the issue; usually, renv::restore() will be the next step necessary to install any missing packages. Note that you do not need to manually install the packages via install.packages(), remotes::install_github(), or similar, as renv will attempt do this for you.

While unnecessary for the purposes of this workshop, if you’d like to learn more about the details of how the renv virtual environment system works, the following references may be helpful:

  1. Collaborating with renv
  2. Introduction to renv

In some rare cases, R packages that renv automatically tries to install as part of the renv::restore() process may fail due to missing systems-level dependencies. In such cases, a reference to the missing dependencies and system-specific instructions their installation involving, e.g., Ubuntu Linux’s apt or homebrew for macOS, will usually be displayed.