-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
189 lines (142 loc) · 6.36 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
---
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/`medshift`
<!-- badges: start -->
[![R-CMD-check](https://github.com/nhejazi/medshift/workflows/R-CMD-check/badge.svg)](https://github.com/nhejazi/medshift/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/medshift/master.svg)](https://app.codecov.io/github/nhejazi/medshift)
[![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)
<!-- badges: end -->
> Causal Mediation Analysis for Stochastic Interventions
__Authors:__ [Nima Hejazi](https://nimahejazi.org) and [Iván
Díaz](https://idiaz.xyz)
---
## What's `medshift`?
The `medshift` R package is designed to provide facilities for estimating a
parameter that arises in a decomposition of the population intervention causal
effect into the (in)direct effects under stochastic interventions in the setting
of mediation analysis. `medshift` is designed as an implementation to accompany
the methodology described in @diaz2020causal. Implemented estimators include the
classical substitution (G-computation) estimator, an inverse probability
weighted (IPW) estimator, an efficient one-step estimator using cross-fitting
[@pfanzagl1985contributions; @zheng2011cross; @chernozhukov2018double], and a
cross-validated targeted minimum loss (TML) estimator [@vdl2011targeted;
@zheng2011cross]. `medshift` integrates with the [`sl3` R
package](https://github.com/tlverse/sl3) [@coyle-gh-sl3] to allow constructed
estimators to leverage machine learning for nuisance estimation.
---
## Installation
Install the _most recent version_ from the `master` branch on GitHub via
[`remotes`](https://CRAN.R-project.org/package=remotes):
```{r gh-master-installation, eval=FALSE}
remotes::install_github("nhejazi/medshift")
```
---
## Example
To illustrate how `medshift` 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(medshift)
# produces a simple data set based on ca causal model with mediation
make_simple_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_simple_mediation_data()
# compute one-step estimate for an incremental propensity score intervention
# that triples (delta = 3) the individual-specific odds of receiving treatment
os_medshift <- medshift(W = example_data$W, A = example_data$A,
Z = example_data$Z, Y = example_data$Y,
delta = 3, estimator = "onestep",
estimator_args = list(cv_folds = 3))
summary(os_medshift)
```
For details on how to use data adaptive regression (machine learning) techniques
in the estimation of nuisance parameters, consider consulting the vignette that
accompanies this package.
---
## Issues
If you encounter any bugs or have any specific feature requests, please [file an
issue](https://github.com/nhejazi/medshift/issues).
---
## Contributions
Contributions are very welcome. Interested contributors should consult our
[contribution
guidelines](https://github.com/nhejazi/medshift/blob/master/CONTRIBUTING.md)
prior to submitting a pull request.
---
## Citation
After using the `medshift` R package, please cite the following:
@article{diaz2020causal,
title={Causal mediation analysis for stochastic interventions},
author={D{\'\i}az, Iv{\'a}n and Hejazi, Nima S},
year={2020},
url = {https://doi.org/10.1111/rssb.12362},
doi = {10.1111/rssb.12362},
journal={Journal of the Royal Statistical Society: Series B
(Statistical Methodology)},
volume={},
number={},
pages={},
publisher={Wiley Online Library}
}
@manual{hejazi2020medshift,
author = {Hejazi, Nima S and D{\'\i}az, Iv{\'a}n},
title = {{medshift}: Causal mediation analysis for stochastic
interventions},
year = {2020},
url = {https://github.com/nhejazi/medshift},
note = {R package version 0.1.4}
}
---
## License
© 2018-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) 2018-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