Highly Adaptive Lasso-Based Estimation of Causal Dose-Response Curves
halDRC is an R package for estimating causal marginal dose-response relationships using the Highly Adaptive Lasso (HAL). It supports both binary and continuous outcomes, with optional undersmoothing and smoothness-order adaptation.
The package provides a plugin estimator that is interpretable and flexible, suitable for both simulation studies and real-world observational data.
To install the development version from GitHub:
# Install the devtools package if you haven't already
install.packages("devtools")
# Install halDRC
devtools::install_github("SeraphinaShi/halDRC", build_vignettes = TRUE)Or clone and install locally:
git clone https://github.com/SeraphinaShi/halDRC.git
setwd("halDRC")
devtools::install(build_vignettes = TRUE)To install dependencies: hal9001 and sl3
install.packages("hal9001")
devtools::install_github("tlverse/sl3")library(halDRC)
# Simulate data
set.seed(123)
simulate_dose_response <- function(n, a = NA) {
W <- rnorm(500)
A <- if (is.na(a)) 0.5 * W + rnorm(n, sd = 0.8) else rep(a, n)
logit_Y <- 0.5 * A^2 + A + 0.3 * W + rnorm(n, sd = 0.5)
Y <- 1 / (1 + exp(-logit_Y))
data.frame(W, A, Y)
}
data <- simulate_dose_response(n = 100) # Replace with your generator
# Fit dose-response using HAL
library(dplyr)
fit <- fit_UHAL_DRC(
dat = data,
y_var_name = "Y",
trt_var_name = "A",
family = "gaussian"
)
# Plot results
library(ggplot2)
ggplot(fit$curve_est, aes(x = a, y = y_hat)) +
geom_line() +
geom_ribbon(aes(ymin = ci_lwr, ymax = ci_upr), alpha = 0.3) +
theme_minimal() +
labs(title = "Estimated Dose-Response Curve", x = "Treatment (A)", y = "Outcome (Y)")We provide a comprehensive walkthrough of the 'halDRC' package using both simulated datasets and the Right Heart Catheterization (RHC) dataset from the TMLE workshop.
View the online here.
Simulated Data Example
We demonstrate the entire analysis pipeline on simulated data, including:
- Generating synthetic datasets with binary or continuous outcomes
- Fitting the HAL plugin estimator to model the dose-response relationship
- Visualizing the estimated dose-response curve
- Comparing to the known ground-truth curve, enabling direct performance assessment
Real-World Data Example: RHC Dataset
We also apply the pipeline to real-world observational data from the RHC study:
- Loading and preprocessing the RHC dataset
- Choosing treatment and confounder variables
- Fitting the HAL plugin estimator
- Visualizing the estimated dose-response curve to explore potential causal effects
fit_UHAL_DRC()– Estimate dose-response curve using HAL
- Shi, Junming, et al. "Hal-based plugin estimation of the causal dose-response curve." arXiv preprint arXiv:2406.05607 (2024).
If you want to contribute, feel free to submit an issue or pull request!
MIT © Junming Shi
