-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
234 lines (207 loc) · 7.63 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
---
output: github_document
bibliography: inst/references.bib
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
> crumble (verb): break or fall apart into small fragments
# crumble
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![CRAN status](https://www.r-pkg.org/badges/version/crumble)](https://CRAN.R-project.org/package=crumble) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
<!-- badges: end -->
*crumble* implements a modern, unified estimation strategy [@liu2024general] for common mediation estimands: natural effects [@pearl2022], organic effects [@lok2015], interventional effects [@vansteelandt2017], recanting twins [@vo2024], in causal inference in combination with modified treatment policies. It makes use of recent advancements in "Riesz-learning" to estimate a set of required nuisance parameters using deep learning. The result is a software package that is capable of estimating mediation effects with binary, categorical, continuous, or multivariate exposures with high-dimensional mediators and mediator-outcome confounders using machine learning.
This work was supported by the National Institute on Drug Abuse [R00DA042127].
### Installation
```{r eval=FALSE}
remotes::install_github("nt-williams/crumble")
```
### Features
| Feature | Status |
|---------------------------|:-------:|
| Recanting twins | ✓ |
| Natural effects | ✓ |
| Organic effects | ✓ |
| Interventional effects | ✓ |
| Modified treatment Policy | ✓ |
| Static intervention | ✓ |
| Dynamic intervention | ✓ |
| Continuous treatment | ✓ |
| Binary treatment | ✓ |
| Categorical treatment | ✓ |
| Multivariate treatment | ✓ |
| Missingness in treatment | |
| Continuous outcome | ✓ |
| Binary outcome | ✓ |
| Censored outcome | ✓ |
| Survey weights | Planned |
| Super learner | ✓ |
| Clustered data | Planned |
| Parallel processing | ✓ |
| GPU support | ✓ |
| Progress bars | ✓ |
### Example(s)
```{r eval=FALSE}
library(crumble)
library(mlr3extralearners)
data(weight_behavior, package = "mma")
weight_behavior <- na.omit(weight_behavior)
set.seed(2345)
```
##### Recanting twins
```{r eval=FALSE}
crumble(
data = weight_behavior,
trt = "sports",
outcome = "bmi",
covar = c("age", "sex", "tvhours"),
mediators = c("exercises", "overweigh"),
moc = "snack",
d0 = \(data, trt) factor(rep(1, nrow(data)), levels = c("1", "2")),
d1 = \(data, trt) factor(rep(2, nrow(data)), levels = c("1", "2")),
effect = "RT",
learners = c("mean", "glm", "earth", "ranger"),
nn_module = sequential_module(),
control = crumble_control(crossfit_folds = 1L, epochs = 20L)
)
#> ✔ Permuting Z-prime variables... 1/1 tasks [2.5s]
#> ✔ Fitting outcome regressions... 1/1 folds [25.6s]
#> ✔ Computing alpha n density ratios... 1/1 folds [39.7s]
#> ✔ Computing alpha r density ratios... 1/1 folds [41.6s]
#>
#> ══ Results `crumble()` ═════════════════════════════════════════
#>
#> ── E[Y(d1) - Y(d0)]
#> Estimate: 1.0537
#> Std. error: 0.3009
#> 95% CI: (0.4639, 1.6435)
#>
#> ── Path: A -> Y
#> Estimate: 0.0366
#> Std. error: 0.1842
#> 95% CI: (-0.3245, 0.3976)
#>
#> ── Path: A -> Z -> Y
#> Estimate: -0.0202
#> Std. error: 0.0238
#> 95% CI: (-0.0668, 0.0264)
#>
#> ── Path: A -> Z -> M -> Y
#> Estimate: -6e-04
#> Std. error: 0.0099
#> 95% CI: (-0.02, 0.0189)
#>
#> ── Path: A -> M -> Y
#> Estimate: 1.0506
#> Std. error: 0.2162
#> 95% CI: (0.627, 1.4743)
#>
#> ── Intermediate Confounding
#> Estimate: -0.0127
#> Std. error: 0.0261
#> 95% CI: (-0.0638, 0.0384)
```
##### Natural effects
```{r eval=FALSE}
crumble(
data = weight_behavior,
trt = "sports",
outcome = "bmi",
covar = c("age", "sex", "tvhours"),
mediators = c("exercises", "overweigh"),
d0 = \(data, trt) factor(rep(1, nrow(data)), levels = c("1", "2")),
d1 = \(data, trt) factor(rep(2, nrow(data)), levels = c("1", "2")),
effect = "N",
learners = c("mean", "glm", "earth", "ranger"),
nn_module = sequential_module(),
control = crumble_control(crossfit_folds = 1L, epochs = 20L)
)
#> ✔ Fitting outcome regressions... 1/1 folds [10.6s]
#> ✔ Computing alpha n density ratios... 1/1 folds [53.1s]
#>
#> ══ Results `crumble()` ═════════════════════════════════════════
#>
#> ── E[Y(d1) - Y(d0)]
#> Estimate: 1.0289
#> Std. error: 0.28
#> 95% CI: (0.48, 1.5777)
#>
#> ── Natural Direct Effect
#> Estimate: 0.0165
#> Std. error: 0.1717
#> 95% CI: (-0.3201, 0.3531)
#>
#> ── Natural Indirect Effect
#> Estimate: 1.0124
#> Std. error: 0.2178
#> 95% CI: (0.5856, 1.4393)
```
##### Organic effects
```{r eval=FALSE}
crumble(
data = weight_behavior,
trt = "sports",
outcome = "bmi",
covar = c("age", "sex", "tvhours"),
mediators = c("exercises", "overweigh"),
d0 = \(data, trt) factor(rep(1, nrow(data)), levels = c("1", "2")),
d1 = \(data, trt) factor(rep(2, nrow(data)), levels = c("1", "2")),
effect = "O",
learners = c("mean", "glm", "earth", "ranger"),
nn_module = sequential_module(),
control = crumble_control(crossfit_folds = 1L, epochs = 20L)
)
#> ✔ Fitting outcome regressions... 1/1 folds [10.7s]
#> ✔ Computing alpha n density ratios... 1/1 folds [48.2s]
#>
#> ══ Results `crumble()` ═════════════════════════════════════════
#>
#> ── Organic Direct Effect
#> Estimate: 0.011
#> Std. error: 0.1772
#> 95% CI: (-0.3364, 0.3584)
#>
#> ── Organic Indirect Effect
#> Estimate: 1.0278
#> Std. error: 0.2231
#> 95% CI: (0.5904, 1.4651)#>
```
##### Randomized interventional effects
```{r eval=FALSE}
crumble(
data = weight_behavior,
trt = "sports",
outcome = "bmi",
covar = c("age", "sex", "tvhours"),
mediators = c("exercises", "overweigh"),
moc = "snack",
d0 = \(data, trt) factor(rep(1, nrow(data)), levels = c("1", "2")),
d1 = \(data, trt) factor(rep(2, nrow(data)), levels = c("1", "2")),
effect = "RI",
learners = c("mean", "glm", "earth", "ranger"),
nn_module = sequential_module(),
control = crumble_control(crossfit_folds = 1L, epochs = 20L)
)
#> ✔ Permuting Z-prime variables... 1/1 tasks [2s]
#> ✔ Fitting outcome regressions... 1/1 folds [14.2s]
#> ✔ Computing alpha r density ratios... 1/1 folds [1m 23.2s]
#>
#> ══ Results `crumble()` ═════════════════════════════════════════
#>
#> ── Randomized Direct Effect
#> Estimate: 0.0162
#> Std. error: 0.1774
#> 95% CI: (-0.3315, 0.364)
#>
#> ── Randomized Indirect Effect
#> Estimate: 1.0304
#> Std. error: 0.2296
#> 95% CI: (0.5805, 0.4662)
```
#### References