-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
286 lines (204 loc) · 10.9 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
---
output:
rmarkdown::github_document
bibliography: "inst/REFERENCES.bib"
always_allow_html: true
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# `CVtreeMLE` <img src="man/figures/CVtreeMLE_sticker.png" style="float:right; height:200px;">
<!-- badges: start -->
[![R-CMD-check](https://github.com/blind-contours/CVtreeMLE/workflows/R-CMD-check/badge.svg)](https://github.com/blind-contours/CVtreeMLE/actions)
[![Coverage Status](https://codecov.io/gh/blind-contours/CVtreeMLE/branch/main/graph/badge.svg?token=HJP5PYQSG4)](https://codecov.io/github/blind-contours/CVtreeMLE?branch=master)
[![CRAN](https://www.r-pkg.org/badges/version/CVtreeMLE)](https://www.r-pkg.org/pkg/CVtreeMLE)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/CVtreeMLE)](https://CRAN.R-project.org/package=CVtreeMLE)
[![CRAN total downloads](http://cranlogs.r-pkg.org/badges/grand-total/CVtreeMLE)](https://CRAN.R-project.org/package=CVtreeMLE)
[![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](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
<!-- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4070042.svg)](https://doi.org/10.5281/zenodo.4070042) -->
<!-- [![DOI](https://joss.theoj.org/papers/10.21105/joss.02447/status.svg)](https://doi.org/10.21105/joss.02447) -->
[![Codecov test coverage](https://codecov.io/gh/blind-contours/CVtreeMLE/branch/main/graph/badge.svg)](https://app.codecov.io/gh/blind-contours/CVtreeMLE?branch=main)
<!-- badges: end -->
> Discovery of Critical Thresholds in Mixed Exposures and Estimation of Policy Intervention Effects using Targeted Learning
__Author:__ [David McCoy](https://davidmccoy.org)
---
## What is `CVtreeMLE`?
This package operationalizes the methodology presented here:
https://arxiv.org/abs/2302.07976
People often encounter multiple simultaneous exposures (e.g. several drugs or pollutants). Policymakers are interested in setting safe limits, interdictions, or recommended dosage combinations based on a combination of thresholds, one per exposure. Setting these thresholds is difficult because all relevant interactions between exposures must be accounted for. Previous statistical methods have used parametric estimators which do not directly address the question of safe exposure limits, rely on unrealistic assumptions, and do not result in a threshold based statistical quantity that is directly relevant to policy regulators.
Here we present an estimator that a) identifies thresholds that minimize/maximize the expected outcome controlling for covariates and other exposures; and which b) efficiently estimates a policy intervention which compares the expected outcome if everyone was forced to these safe levels compared to the observed outcome under observed exposure distribution.
This is done by using cross-validation where in training folds of the data, a custom g-computation tree-based search algorithm finds the minimizing region, and an estimation sample is used to estimate the policy intervention using targeted maximum likelihood estimation.
## Inputs and Outputs
This package takes in a mixed exposure, covariates, outcome, super learner stacks
of learners if determined (if not default are used), number of folds, minimum observations in a region, if the desired region is minimizer or maximizer and parallelization parameters.
The output are k-fold specific results for the region found in each fold with valid inference, a pooled estimate of the overall oracle parameter across all folds and pooled exposure sets if the region has some inconsistency across the folds.
---
## Installation
*Note:* Because `CVtreeMLE` package (currently) depends on `sl3` that
allows ensemble machine learning to be used for nuisance parameter
estimation and `sl3` is not on CRAN the `CVtreeMLE` package is not
available on CRAN and must be downloaded here.
There are many dependencies for `CVtreeMLE` so it's easier to break up
installation of the various packages to ensure proper installation.
`CVtreeMLE` uses the `sl3` package to build ensemble machine learners for each nuisance parameter.
Install `sl3` on devel:
```{r sl3_devel, eval = FALSE}
remotes::install_github("tlverse/sl3@devel")
```
Make sure `sl3` installs correctly then install `CVtreeMLE`
```{r CVtreeMLE_install, eval = FALSE}
remotes::install_github("blind-contours/CVtreeMLE@main")
```
---
## Example
First load the package and other packages needed
```{r libraries, warning=FALSE, message=FALSE}
library(CVtreeMLE)
library(sl3)
library(dplyr)
library(kableExtra)
library(ggplot2)
seed <- 98484
set.seed(seed)
```
To illustrate how `CVtreeMLE` may be used to find and estimate a region that, if intervened on would lead to the biggest reduction in an outcome we use synthetic data from the National Institute of Environmental Health:
## National Institute of Environmental Health Data
The 2015 NIEHS Mixtures Workshop was
developed to determine if new mixture methods detect ground-truth interactions
built into the simulated data. In this way we can simultaneously show
`CVtreeMLE` output, interpretation and validity.
For detailed information on this simulated data please see:
https://github.com/niehs-prime/2015-NIEHS-MIxtures-Workshop
```{r load_NIEHS_data, warning=FALSE}
niehs_data <- NIEHS_data_1
head(niehs_data) %>%
kableExtra::kbl(caption = "NIEHS Data") %>%
kableExtra::kable_classic(full_width = FALSE, html_font = "Cambria")
```
Briefly, this synthetic data can be considered the results of a prospective
cohort epidemiologic study. The outcome cannot cause the exposures (as might
occur in a cross-sectional study). Correlations between exposure variables can
be thought of as caused by common sources or modes of exposure. The nuisance
variable Z can be assumed to be a potential confounder and not a collider.
There are 7 exposures which have a complicated dependency structure. $X_3$ and
$X_6$ do not have an impact on the outcome.
One issue is that many machine learning algorithms will fail given only 1
variable passed as a feature so let's add some other covariates.
```{r add_covariates, warning=FALSE}
niehs_data$Z2 <- rbinom(nrow(niehs_data),
size = 1,
prob = 0.3
)
niehs_data$Z3 <- rbinom(nrow(niehs_data),
size = 1,
prob = 0.1
)
```
## Run `CVtreeMLE`
```{r run_simulation, warnings = FALSE, message=FALSE}
ptm <- proc.time()
# Convert continuous X variables to their corresponding deciles for example
niehs_data <- niehs_data %>%
mutate(across(starts_with("X"), ~ ntile(., 10), .names = "decile_{col}"))
niehs_results <- CVtreeMLE(
data = as.data.frame(niehs_data),
w = c("Z", "Z2", "Z3"),
a = c("decile_X1", "decile_X2", "decile_X3", "decile_X4", "decile_X5", "decile_X6", "decile_X7"),
y = "Y",
n_folds = 7,
seed = seed,
parallel_cv = TRUE,
parallel = TRUE,
family = "continuous",
num_cores = 8,
min_max = "min",
max_depth = 2,
min_obs = 25
)
proc.time() - ptm
```
## Mixture Results
First let's look at the k-fold specific estimates:
```{r k_fold_results}
k_fold_results <- niehs_results$`V-Specific Mix Results`
k_fold_results %>%
kableExtra::kbl(caption = "K-fold Results") %>%
kableExtra::kable_classic(full_width = FALSE, html_font = "Cambria")
```
This indicates that the exposure X2 was found in every fold to have the most minimizing impact on endocrine disruption if all individuals were were forced to be exposed to levels less around 0.41. This resembles a policy where, if everyone were still exposed to the other exposures but we created a regulation that restricted individuals to only exposure of X2 less than 0.41.
The pooled estimates, leveraging all the folds for our estimates oracle target parameter looks like:
```{r oracle_results}
pooled_mixture_results <- niehs_results$`Oracle Region Results`
pooled_mixture_results %>%
kableExtra::kbl(caption = "Oracle Mixture Results") %>%
kableExtra::kable_classic(full_width = FALSE, html_font = "Cambria")
```
Additional details for this and other features are given in the vignette.
---
## Issues
If you encounter any bugs or have any specific feature requests,
please [file an
issue](https://github.com/blind-contours/CVtreeMLE/issues). Further details
on filing
issues are provided in our [contribution
guidelines](https://github.com/blind-contours/
CVtreeMLE/blob/main/CONTRIBUTING.md).
---
## Contributions
Contributions are very welcome. Interested contributors should consult our
[contribution
guidelines](https://github.com/blind-contours/CVtreeMLE/blob/main/contributing.md)
prior to submitting a pull request.
---
## Citation
After using the `CVtreeMLE` R package, please cite the following:
@article{McCoy2023,
doi = {10.21105/joss.04181},
url = {https://doi.org/10.21105/joss.04181},
year = {2023}, publisher = {The Open Journal},
volume = {8}, number = {82}, pages = {4181},
author = {David McCoy and Alan Hubbard and Mark Van der Laan},
title = {CVtreeMLE: Efficient Estimation of Mixed Exposures using Data Adaptive Decision Trees and Cross-Validated Targeted Maximum Likelihood Estimation in R},
journal = {Journal of Open Source Software} }
---
## Related
* [R/`sl3`](https://github.com/tlverse/sl3) - An R package
providing implementation for Super Learner ensemble machine learning
algorithms.
---
## Funding
The development of this software was supported in part through grants from the
NIH-funded Biomedical Big Data Training Program at UC Berkeley where I was a
biomedical big data fellow.
---
## License
© 2017-2024 David B. McCoy
The contents of this repository are distributed under the MIT license. See
below for details:
```
MIT License
Copyright (c) 2017-2024 David B. McCoy
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