-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
244 lines (189 loc) · 8.62 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
---
output:
rmarkdown::github_document
always_allow_html: yes
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 = "#>",
out.width = "100%",
fig.path = "README-"
)
```
# R/`haldensify`
<!-- badges: start -->
[![R-CMD-check](https://github.com/nhejazi/haldensify/workflows/R-CMD-check/badge.svg)](https://github.com/nhejazi/haldensify/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/nhejazi/haldensify/master.svg)](https://codecov.io/github/nhejazi/haldensify?branch=master)
[![CRAN](http://www.r-pkg.org/badges/version/haldensify)](https://www.r-pkg.org/pkg/haldensify)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/haldensify)](https://CRAN.R-project.org/package=haldensify)
[![CRAN total downloads](http://cranlogs.r-pkg.org/badges/grand-total/haldensify)](https://CRAN.R-project.org/package=haldensify)
[![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)](https://opensource.org/licenses/MIT)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3698329.svg)](https://doi.org/10.5281/zenodo.3698329)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04522/status.svg)](https://doi.org/10.21105/joss.04522)
<!-- badges: end -->
> Highly Adaptive Lasso Conditional Density Estimation
__Authors:__ [Nima Hejazi](https://nimahejazi.org), [David
Benkeser](https://www.sph.emory.edu/faculty/profile/#!dbenkes), and [Mark
van der Laan](https://vanderlaan-lab.org/about/)
---
## What's `haldensify`?
The `haldensify` R package is designed to provide facilities for nonparametric
conditional density estimation based on a flexible procedure proposed initially
by @diaz2011super. The core of the implemented methodology involves recovering
conditional density estimates by performing pooled hazards regressions so as to
assess the conditional hazard that an observed value falls in a given bin over
the (conditional) support of the variable of interest. Such conditional density
estimates are useful, for example, in causal inference problems in which the
_generalized propensity score_ (for continuous-valued exposures) must be
estimated [@diaz2012population; @diaz2018stochastic; @diaz2020causal].
`haldensify` implements this conditional density estimation strategy for use
only with the highly adaptive lasso (HAL) [@benkeser2016highly;
@vdl2017generally; @vdl2018highly; @coyle2022hal9001-rpkg;
@hejazi2020hal9001-joss]. Since the generalized propensity score is a key
ingredient in inverse probability weighting (IPW) methods, `haldensify` builds
on the advances of @ertefaie2020nonparametric and @hejazi2022efficient to
provide nonparametric IPW estimators of the causal effects for continuous
treatments, which achieve the semiparametric efficiency bound by undersmoothing
along a family of HAL conditional density estimators.
---
## Installation
For standard use, we recommend installing the package from
[CRAN](https://CRAN.R-project.org/package=haldensify) via
```{r cran-installation, eval = FALSE}
install.packages("haldensify")
```
To contribute, install the _development version_ of `haldensify` from GitHub
via [`remotes`](https://CRAN.R-project.org/package=remotes):
```{r gh-master-installation, eval = FALSE}
remotes::install_github("nhejazi/haldensify")
```
---
## Example
A simple example illustrates how `haldensify` may be used to train a highly
adaptive lasso model to obtain conditional density estimates:
```{r example-fit}
library(haldensify)
set.seed(76924)
# simulate data: W ~ U[-4, 4] and A|W ~ N(mu = W, sd = 0.25)
n_train <- 100
w <- runif(n_train, -4, 4)
a <- rnorm(n_train, w, 0.25)
# HAL-based density estimate of A|W
haldensify_fit <- haldensify(
A = a, W = w,
n_bins = 10, grid_type = "equal_range",
lambda_seq = exp(seq(-1, -10, length = 100)),
# arguments passed to hal9001::fit_hal()
max_degree = 3,
reduce_basis = 1 / sqrt(n_train)
)
haldensify_fit
```
We can also visualize the empirical risk (with respect to density loss) in terms
of the solution path of the lasso regularization parameter:
```{r example-plot, out.width = "80%", fig.path = "man/figures/"}
# just use the built-in plot method
plot(haldensify_fit)
```
Finally, we can obtain conditional density estimates from the trained model on
the training (or on new) data:
```{r example-predict}
# use the built-in predict method to get predictions
pred_haldensify <- predict(haldensify_fit, new_A = a, new_W = w)
head(pred_haldensify)
```
For more details, check out the [package
vignette](https://code.nimahejazi.org/haldensify/articles/intro_haldensify) on
the corresponding `pkgdown` site.
---
## Issues
If you encounter any bugs or have any specific feature requests, please [file
an issue](https://github.com/nhejazi/haldensify/issues).
---
## Contributions
Contributions are very welcome. Interested contributors should consult our
[contribution
guidelines](https://github.com/nhejazi/haldensify/blob/master/CONTRIBUTING.md)
prior to submitting a pull request.
---
## Citation
After using the `haldensify` R package, please cite the following:
@article{hejazi2022efficient,
author = {Hejazi, Nima S and Benkeser, David and D{\'\i}az, Iv{\'a}n
and {van der Laan}, Mark J},
title = {Efficient estimation of modified treatment policy effects
based on the generalized propensity score},
year = {2022},
journal = {},
publisher = {},
volume = {},
number = {},
pages = {},
doi = {},
url = {https://arxiv.org/abs/2205.05777}
}
@article{hejazi2022haldensify-joss,
author = {Hejazi, Nima S and {van der Laan}, Mark J and Benkeser,
David C},
title = {{haldensify}: Highly adaptive lasso conditional density
estimation in {R}},
year = {2022},
doi = {10.21105/joss.04522},
url = {https://doi.org/10.21105/joss.04522},
journal = {Journal of Open Source Software},
publisher = {The Open Journal}
}
@software{hejazi2022haldensify-rpkg,
author = {Hejazi, Nima S and Benkeser, David C and {van der Laan},
Mark J},
title = {{haldensify}: Highly adaptive lasso conditional density
estimation},
year = {2022},
howpublished = {\url{https://github.com/nhejazi/haldensify}},
doi = {10.5281/zenodo.3698329},
url = {https://doi.org/10.5281/zenodo.3698329},
note = {{R} package version 0.2.5}
}
---
## Related
* [R/`hal9001`](https://github.com/tlverse/hal9001) -- The highly adaptive
lasso estimator used internally to constructed conditional density estimates.
---
## Funding
The development of this software was supported in part through grants from the
National Library of Medicine (award number [T32
LM012417](https://reporter.nih.gov/project-details/9248418)), the
National Institute of Allergy and Infectious Diseases (award number
[R01 AI074345](https://reporter.nih.gov/project-details/9926564)) of the
National Institutes of Health, and the National Science Foundation (award
number [DMS 2102840](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2102840)).
---
## License
© 2019-2024 [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) 2019-2024 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