-
Notifications
You must be signed in to change notification settings - Fork 18
/
README.Rmd
183 lines (131 loc) · 8.82 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
---
output: github_document
---
<!-- 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%"
)
```
# lmtp <img src="man/figures/lmtp.png" align="right" height="139"/></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/lmtp)](https://CRAN.R-project.org/package=lmtp) ![](http://cranlogs.r-pkg.org/badges/grand-total/lmtp) [![R build status](https://github.com/nt-williams/lmtp/workflows/R-CMD-check/badge.svg)](https://github.com/nt-williams/lmtp/actions) [![codecov](https://codecov.io/gh/nt-williams/lmtp/branch/master/graph/badge.svg)](https://app.codecov.io/gh/nt-williams/lmtp) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![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)
<!-- badges: end -->
> Non-parametric Causal Effects of Feasible Interventions Based on Modified Treatment Policies
Nick Williams and Ivan Diaz
------------------------------------------------------------------------
**lmtp** is an R package that provides an estimation framework for the casual effects of feasible interventions based on point-treatment and longitudinal modified treatment policies as described in Diaz, Williams, Hoffman, and Schenck (2020). Two primary estimators are supported, a targeted maximum likelihood (TML) estimator and a sequentially doubly robust (SDR) estimator (a G-computation and an inverse probability of treatment weighting estimator are provided for the sake of being thorough but their use is recommended against in favor of the TML and SDR estimators). Both binary and continuous outcomes (both with censoring) are allowed. **lmtp** is built atop the [`SuperLearner`](https://CRAN.R-project.org/package=SuperLearner) package to utilize ensemble machine learning for estimation. The treatment mechanism is estimated via a density ratio classification procedure irrespective of treatment variable type providing decreased computation time when treatment is continuous. Dynamic treatment regimes are also supported.
A list of papers using **lmtp** is [here](https://gist.github.com/nt-williams/15068f5849a67ff4d2cb7f2dcf97b3de).
For an in-depth look at the package's functionality, please consult the accompanying technical paper in [Observational Studies](https://muse.jhu.edu/article/883479).
## Installation
**lmtp** can be installed from CRAN with:
``` r
install.packages("lmtp")
```
The stable, development version can be installed from GitHub with:
``` r
devtools::install_github("nt-williams/lmtp@devel")
```
A version allowing for different covariates sets for the treatment, censoring, and outcome regressions:
``` r
devtools::install_github("nt-williams/lmtp@separate-variable-sets")
```
## What even is a modified treatment policy?
Modified treatment policies (MTP) are interventions that can depend on the *natural* value of the treatment (the treatment value in the absence of intervention). A key assumption for causal inference is the *positivity assumption* which states that all observations have a non-zero probability of experiencing a treatment value. **When working with continuous or multivalued treatments, violations of the positivity assumption are likely to occur. MTPs offer a solution to this problem.**
## Can lmtp estimate other effects?
Yes! **lmtp** can estimate the effects of deterministic, static treatment effects (such as the ATE) and deterministic, dynamic treatment regimes for binary, continuous, and survival outcomes.
### Features
| Feature | Status |
|---------------------------------------------------------|:-------------:|
| Point treatment | ✓ |
| Longitudinal treatment | ✓ |
| Modified treatment intervention | ✓ |
| Incremental Propensity Score Intervention (Using the risk ratio) | ✓ |
| Static intervention | ✓ |
| Dynamic intervention | ✓ |
| Continuous treatment | ✓ |
| Binary treatment | ✓ |
| Categorical treatment | ✓ |
| Multivariate treatment | ✓ |
| Missingness in treatment | |
| Continuous outcome | ✓ |
| Binary outcome | ✓ |
| Censored outcome | ✓ |
| Mediation | |
| Survey weights | ✓ |
| Super learner | ✓ |
| Clustered data | ✓ |
| Parallel processing | ✓ |
| Progress bars | ✓ |
## Example
```{r}
library(lmtp)
# the data: 4 treatment nodes with time varying covariates and a binary outcome
head(sim_t4)
```
We're interested in a treatment policy, `d`, where exposure is decreased by 1 only among subjects whose exposure won't go below 1 if intervened upon. The true population outcome under this policy is about 0.305.
```{r}
# a treatment policy function to be applied at all time points
policy <- function(data, trt) {
(data[[trt]] - 1) * (data[[trt]] - 1 >= 1) + data[[trt]] * (data[[trt]] - 1 < 1)
}
```
In addition to specifying a treatment policy, we need to specify our treatment variables and time-varying covariates.
```{r}
# treatment nodes, a character vector of length 4
A <- c("A_1", "A_2", "A_3", "A_4")
# time varying nodes, a list of length 4
L <- list(c("L_1"), c("L_2"), c("L_3"), c("L_4"))
```
We can now estimate the effect of our treatment policy, `d`. In this example, we'll use the cross-validated TML estimator with 10 folds.
```{r, eval = FALSE}
lmtp_tmle(sim_t4, A, "Y", time_vary = L, shift = policy, intervention_type = "mtp", folds = 10)
#> LMTP Estimator: TMLE
#> Trt. Policy: (policy)
#>
#> Population intervention estimate
#> Estimate: 0.2526
#> Std. error: 0.0223
#> 95% CI: (0.2089, 0.2962)
```
## Data structure
#### Single time point
<img src="man/figures/pointtrt.png" height="300"/>
#### Time-varying exposure and confounders, not survival outcome
<img src="man/figures/timevary.png" height="300"/>
#### Single exposure, survival outcome
<img src="man/figures/survival.png" height="300"/>
#### Time-varying exposure and confounders, survival outcome
<img src="man/figures/timevarysurvival.png" height="300"/>
## Similar Implementations
A variety of other R packages perform similar tasks as **lmtp**. However, **lmtp** is the only R package currently capable of estimating causal effects for binary, categorical, and continuous exposures in both the point treatment and longitudinal setting using traditional causal effects or modified treatment policies.
- [`txshift`](https://github.com/nhejazi/txshift)\
- [`tmle3`](https://github.com/tlverse/tmle3)\
- [`tmle3shift`](https://github.com/tlverse/tmle3shift)
- [`ltmle`](https://CRAN.R-project.org/package=ltmle)\
- [`tmle`](https://CRAN.R-project.org/package=tmle)
## Citation
Please cite the following when using **lmtp** in publications. Citation should include both the R package article and the paper establishing the statistical methodology.
```
@article{,
title = {lmtp: An R package for estimating the causal effects of modified treatment policies},
author = {Nicholas T Williams and Iván Díaz},
journal = {Observational Studies},
year = {2023},
url = {https://muse.jhu.edu/article/883479}
}
@article{
doi:10.1080/01621459.2021.1955691,
author = {Iván Díaz and Nicholas Williams and Katherine L. Hoffman and Edward J. Schenck},
title = {Non-parametric causal effects based on longitudinal modified treatment policies},
journal = {Journal of the American Statistical Association},
year = {2021},
doi = {10.1080/01621459.2021.1955691},
URL = {https://doi.org/10.1080/01621459.2021.1955691},
}
```
## References
Iván Díaz, Nicholas Williams, Katherine L. Hoffman & Edward J. Schenck (2021) Non-parametric causal effects based on longitudinal modified treatment policies, Journal of the American Statistical Association, DOI: 10.1080/01621459.2021.1955691