knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
tmle3mediate
Targeted Learning for Causal Mediation Analysis
Authors: Nima Hejazi, James Duncan, David McCoy, and Mark van der Laan
tmle3mediate
?tmle3mediate
is an adapter/extension R package in the tlverse
ecosystem that
provides support for causal mediation analysis, for a range of target
parameters applicable in settings with mediating variables. Causal effects for
which estimation machinery is provided include the popular natural (in)direct
effects [@robins1992identifiability; @zheng2012targeted;
@vanderweele2015explanation], and the less restrictive population intervention
(in)direct effects [@diaz2020causal]. By building on the core tlverse
grammar
exposed by the tmle3
R package, tmle3mediate
accommodates targeted maximum
likelihood (or targeted minimum loss-based) estimation of these causal effect
parameters through a unified interface. For a general discussion of the
framework of targeted minimum loss-based estimation and its relationship to
statistical causal inference, the motivated reader may consider consulting
@vdl2011targeted and @vdl2018targeted. A practical and accessible introduction
using the tlverse
software ecosystem is provided in @vdl2021targeted (see
https://tlverse.org/tlverse-handbook).
Install the most recent stable release from GitHub via
remotes
:
remotes::install_github("tlverse/tmle3mediate")
To illustrate how tmle3mediate
may be used to estimate the effect of applying
a stochastic intervention to the treatment (A
) while keeping the mediator(s)
(Z
) fixed, consider the following example:
library(data.table) library(origami) library(sl3) library(tmle3) library(tmle3mediate) # produces a simple data set based on ca causal model with mediation make_mediation_data <- function(n_obs = 1000) { # baseline covariate -- simple, binary W <- rbinom(n_obs, 1, prob = 0.50) # create treatment based on baseline W A <- as.numeric(rbinom(n_obs, 1, prob = W / 4 + 0.1)) # single mediator to affect the outcome z1_prob <- 1 - plogis((A^2 + W) / (A + W^3 + 0.5)) Z <- rbinom(n_obs, 1, prob = z1_prob) # create outcome as a linear function of A, W + white noise Y <- Z + A - 0.1 * W + rnorm(n_obs, mean = 0, sd = 0.25) # full data structure data <- as.data.table(cbind(Y, Z, A, W)) setnames(data, c("Y", "Z", "A", "W")) return(data) } # set seed and simulate example data set.seed(75681) example_data <- make_mediation_data(100) node_list <- list(W = "W", A = "A", Z = "Z", Y = "Y") # consider an incremental propensity score intervention that triples (i.e., # delta = 3) the individual-specific odds of receiving treatment delta_ipsi <- 3 # make learners for nuisance parameters g_learners <- e_learners <- m_learners <- phi_learners <- Lrnr_cv$new(Lrnr_glm$new(), full_fit = TRUE) learner_list <- list(Y = m_learners, A = g_learners) # compute one-step estimate for an incremental propensity score intervention tmle_spec <- tmle_medshift(delta = delta_ipsi, e_learners = e_learners, phi_learners = phi_learners, max_iter = 5) tmle_out <- tmle3(tmle_spec, example_data, node_list, learner_list) tmle_out
If you encounter any bugs or have any specific feature requests, please file an issue.
Contributions are very welcome. Interested contributors should consult our contribution guidelines prior to submitting a pull request.
After using the tmle3mediate
R package, please cite the following:
@software{hejazi2021tmle3mediate-rpkg, author = {Hejazi, Nima S and Duncan, James and McCoy, David and {van der Laan}, Mark J}, title = {{tmle3mediate}: Targeted Learning for Causal Mediation Analysis}, year = {2021}, doi = {}, url = {https://github.com/tlverse/tmle3mediate}, note = {R package version 0.0.3} }
R/medshift
- An R package providing
tools to estimate the causal effect of stochastic treatment regimes in
the mediation setting, including classical (G-computation, IPW) and doubly
robust (one-step) estimators. This is an implementation of the methodology
explored by @diaz2020causal.
R/medoutcon
- An R package providing
doubly robust estimators (one-step, TMLE) of the interventional (in)direct
effects, which are defined by joint static and stochastic interventions
applied to the exposure and mediators, respectively. These effect definitions
are similar to but more general than the natural (in)direct effects. This is
an implementation of the methodology explored by @diaz2020nonparametric.
The development of this software was supported in part through UC Berkeley's Biomedical Big Data training program, made possible by grant T32 LM012417 from the National Institutes of Health.
The contents of this repository are distributed under the GPL-3 license. See
file LICENSE
for details.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.