-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
190 lines (141 loc) · 6.53 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
output:
rmarkdown::github_document
bibliography: "inst/REFERENCES.bib"
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# R/`tmle3mediate`
[![R-CMD-check](https://github.com/tlverse/tmle3mediate/workflows/R-CMD-check/badge.svg)](https://github.com/tlverse/tmle3mediate/actions)
[![Coverage Status](https://codecov.io/gh/tlverse/tmle3mediate/branch/master/graph/badge.svg)](https://codecov.io/gh/tlverse/tmle3mediate)
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
> Targeted Learning for Causal Mediation Analysis
__Authors:__ [Nima Hejazi](https://nimahejazi.org), [James
Duncan](https://statistics.berkeley.edu/people/james-duncan), [David
McCoy](http://bbd.berkeley.edu/cohort-4-2019-2020.html), and [Mark van der
Laan](https://vanderlaan-lab.org)
---
## What's `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).
---
## Installation
Install the most recent _stable release_ from GitHub via
[`remotes`](https://CRAN.R-project.org/package=remotes):
```{r gh-master-installation, eval=FALSE}
remotes::install_github("tlverse/tmle3mediate")
```
---
## Example
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:
```{r simple_example, message=FALSE, warning=FALSE}
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
```
---
## Issues
If you encounter any bugs or have any specific feature requests, please [file an
issue](https://github.com/tlverse/tmle3mediate/issues).
---
## Contributions
Contributions are very welcome. Interested contributors should consult our
[contribution
guidelines](https://github.com/tlverse/tmle3mediate/blob/master/CONTRIBUTING.md)
prior to submitting a pull request.
---
## Citation
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}
}
---
## Related
* [R/`medshift`](https://github.com/nhejazi/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`](https://github.com/nhejazi/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.
---
## Funding
The development of this software was supported in part through [UC Berkeley's
Biomedical Big Data training program](http://bbd.berkeley.edu/), made possible
by grant [T32 LM012417](https://projectreporter.nih.gov/project_info_description.cfm?aid=9248418&icde=37849831&ddparam=&ddvalue=&ddsub=&cr=1&csb=default&cs=ASC&pball=)
from the National Institutes of Health.
---
## License
The contents of this repository are distributed under the GPL-3 license. See
file `LICENSE` for details.
---
## References