-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.Rmd
242 lines (191 loc) · 8.21 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
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/`medoutcon`
<!-- badges: start -->
[![R-CMD-check](https://github.com/nhejazi/medoutcon/workflows/R-CMD-check/badge.svg)](https://github.com/nhejazi/medoutcon/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/medoutcon/master.svg)](https://codecov.io/github/nhejazi/medoutcon?branch=master)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5809519.svg)](https://doi.org/10.5281/zenodo.5809519)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.03979/status.svg)](https://doi.org/10.21105/joss.03979)
<!-- badges: end -->
> Efficient Causal Mediation Analysis for the Natural and Interventional Effects
__Authors:__ [Nima Hejazi](https://nimahejazi.org), [Iván
Díaz](https://idiaz.xyz), and [Kara
Rudolph](https://kararudolph.github.io/)
---
## What's `medoutcon`?
The `medoutcon` R package provides facilities for efficient estimation of
path-specific (in)direct effects that measure the impact of a treatment variable
$A$ on an outcome variable $Y$, through a direct path (through $A$ only) and an
indirect path (through a set of mediators $M$ only). In the presence of an
intermediate <b>med</b>iator-<b>out</b>come <b>con</b>founder $Z$, itself
affected by the treatment $A$, these correspond to the _interventional_
(in)direct effects described by @diaz2020nonparametric, though similar (yet less
general) effect definitions and/or estimation strategies have appeared i`n
@`vanderweele2014effect, @rudolph2017robust, @zheng2017longitudinal, and
@benkeser2020nonparametric. When no intermediate confounders are present, these
effect definitions simplify to the well-studied _natural_ (in)direct effects,
and our estimators are analogs of those formulated by @zheng2012targeted. Both
an efficient one-step bias-corrected estimator with cross-fitting
[@pfanzagl1985contributions; @zheng2011cross; @chernozhukov2018double] and a
cross-validated targeted minimum loss estimator (TMLE) [@vdl2011targeted;
@zheng2011cross] are made available. `medoutcon` integrates with the [`sl3` R
package](https://github.com/tlverse/sl3) [@coyle-gh-sl3] to leverage statistical
machine learning in the estimation procedure.
---
## 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("nhejazi/medoutcon")
```
---
## Example
To illustrate how `medoutcon` may be used to estimate stochastic interventional
(in)direct effects of the exposure (`A`) on the outcome (`Y`) in the presence of
mediator(s) (`M`) and a mediator-outcome confounder (`Z`), consider the
following example:
```{r example, warning=FALSE, message=FALSE}
library(data.table)
library(tidyverse)
library(medoutcon)
set.seed(1584)
# produces a simple data set based on ca causal model with mediation
make_example_data <- function(n_obs = 1000) {
## baseline covariates
w_1 <- rbinom(n_obs, 1, prob = 0.6)
w_2 <- rbinom(n_obs, 1, prob = 0.3)
w_3 <- rbinom(n_obs, 1, prob = pmin(0.2 + (w_1 + w_2) / 3, 1))
w <- cbind(w_1, w_2, w_3)
w_names <- paste("W", seq_len(ncol(w)), sep = "_")
## exposure
a <- as.numeric(rbinom(n_obs, 1, plogis(rowSums(w) - 2)))
## mediator-outcome confounder affected by treatment
z <- rbinom(n_obs, 1, plogis(rowMeans(-log(2) + w - a) + 0.2))
## mediator -- could be multivariate
m <- rbinom(n_obs, 1, plogis(rowSums(log(3) * w[, -3] + a - z)))
m_names <- "M"
## outcome
y <- rbinom(n_obs, 1, plogis(1 / (rowSums(w) - z + a + m)))
## construct output
dat <- as.data.table(cbind(w = w, a = a, z = z, m = m, y = y))
setnames(dat, c(w_names, "A", "Z", m_names, "Y"))
return(dat)
}
# set seed and simulate example data
example_data <- make_example_data()
w_names <- str_subset(colnames(example_data), "W")
m_names <- str_subset(colnames(example_data), "M")
# quick look at the data
head(example_data)
# compute one-step estimate of the interventional direct effect
os_de <- medoutcon(
W = example_data[, ..w_names],
A = example_data$A,
Z = example_data$Z,
M = example_data[, ..m_names],
Y = example_data$Y,
effect = "direct",
estimator = "onestep"
)
os_de
# compute targeted minimum loss estimate of the interventional direct effect
tmle_de <- medoutcon(
W = example_data[, ..w_names],
A = example_data$A,
Z = example_data$Z,
M = example_data[, ..m_names],
Y = example_data$Y,
effect = "direct",
estimator = "tmle"
)
tmle_de
```
For details on how to use data adaptive regression (machine learning) techniques
in the estimation of nuisance parameters, consider consulting the vignette that
accompanies the package.
---
## Issues
If you encounter any bugs or have any specific feature requests, please [file an
issue](https://github.com/nhejazi/medoutcon/issues).
---
## Contributions
Contributions are very welcome. Interested contributors should consult our
[contribution
guidelines](https://github.com/nhejazi/medoutcon/blob/master/CONTRIBUTING.md)
prior to submitting a pull request.
---
## Citation
After using the `medoutcon` R package, please cite the following:
@article{diaz2020nonparametric,
title={Non-parametric efficient causal mediation with intermediate
confounders},
author={D{\'\i}az, Iv{\'a}n and Hejazi, Nima S and Rudolph, Kara E
and {van der Laan}, Mark J},
year={2020},
url = {https://arxiv.org/abs/1912.09936},
doi = {10.1093/biomet/asaa085},
journal={Biometrika},
volume = {108},
number = {3},
pages = {627--641},
publisher={Oxford University Press}
}
@article{hejazi2022medoutcon-joss,
author = {Hejazi, Nima S and Rudolph, Kara E and D{\'\i}az,
Iv{\'a}n},
title = {{medoutcon}: Nonparametric efficient causal mediation
analysis with machine learning in {R}},
year = {2022},
doi = {10.21105/joss.03979},
url = {https://doi.org/10.21105/joss.03979},
journal = {Journal of Open Source Software},
publisher = {The Open Journal}
}
@software{hejazi2022medoutcon-rpkg,
author={Hejazi, Nima S and D{\'\i}az, Iv{\'a}n and Rudolph, Kara E},
title = {{medoutcon}: Efficient natural and interventional causal
mediation analysis},
year = {2022},
doi = {10.5281/zenodo.5809519},
url = {https://github.com/nhejazi/medoutcon},
note = {R package version 0.1.6}
}
---
## License
© 2020-2022 [Nima S. Hejazi](https://nimahejazi.org)
The contents of this repository are distributed under the MIT license. See below
for details:
```
MIT License
Copyright (c) 2020-2022 Nima S. Hejazi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
---
## References