hte3 estimates conditional average treatment effects (CATE) and conditional
risk ratios (CRR) in R. Fit DR-, R-, T-, and efficient plug-in (EP) learners,
compare models by cross-validation, and predict effects for new observations.
Use learners from sl3 or fit forests with the optional grf package.
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
remotes::install_github("Larsvanderlaan/hte3", dependencies = TRUE)To use grf_cate() or grf_crr(), also install grf:
install.packages("grf")Create a task with your data and covariates, fit a model, and predict treatment effects. This example uses simulated data and simple mean learners.
library(hte3)
library(sl3)
data <- hte3_example_data(n = 150, seed = 1)
task <- hte_task(
data = data,
modifiers = c("W1", "W2", "W3"),
confounders = c("W1", "W2", "W3"),
treatment = "A",
outcome = "Y",
propensity_learner = Lrnr_mean$new(),
outcome_learner = Lrnr_mean$new(),
mean_learner = Lrnr_mean$new(),
cross_fit = FALSE
)
fit <- fit_cate(
task,
method = "dr",
base_learner = Lrnr_mean$new(),
cross_validate = FALSE
)
pred <- predict(fit, data)
head(pred)
summary(fit)| Guide | What it covers |
|---|---|
| Quickstart | Fit and predict with hte_task() and fit_cate(). |
| Treatment effects | Choose among DR-, R-, T-, and EP-learners for conditional mean differences. |
| Risk ratios | Estimate conditional risk ratios with fit_crr(). |
| Causal forests | Fit models with grf_cate() and grf_crr(), with optional nuisance estimates supplied by you. |
| EP-learner | Choose a sieve basis size and compare EP-DR with EP-R. |
| Using sl3 directly | Construct tasks, train learners, and compare custom sets of models. |
See the function reference for arguments and return values.
fit_crr()andgrf_crr()require a non-negative outcome.grf_cate()andgrf_crr()currently support binary treatment only.- For continuous treatments, use
fit_cate(..., method = "r"), which assumes a partially linear effect modelA * tau(X).