Continuous Treatment: Average Dose-Response Function
Source:vignettes/continuous.Rmd
continuous.RmdOverview
This vignette demonstrates frengression for continuous treatment data. We generate synthetic data with a known causal effect (ADRF), train a frengression model, and verify it recovers the true dose-response curve.
Data Generating Process
The DGP has a confounder Z that affects both treatment X and outcome Y:
- , where
- , where
The true ADRF is .
Train Frengression
Training is two-stage: first the outcome model (model_y + model_eta), then the marginal model (model_xz).
model <- frengression(x_dim = 1, y_dim = 1, z_dim = 1, noise_dim = 5)
# Stage 1: Train outcome model
model <- train_y(model, x, z, y, num_iters = 500, lr = 1e-3,
print_every = 100)
# Stage 2: Train marginal model
model <- train_xz(model, x, z, num_iters = 500, lr = 1e-4,
print_every = 100)
print(model)Plot Results
plot(x_grid, y_pred, type = "l", lwd = 2, col = "blue",
xlab = "Treatment (X)", ylab = "E[Y | do(X)]",
main = "Average Dose-Response Function")
lines(x_grid, y_true, lty = 2, lwd = 2, col = "red")
if (is.array(y_quant) && length(dim(y_quant)) == 3) {
lines(x_grid, y_quant[, 1, 1], lty = 3, col = "blue")
lines(x_grid, y_quant[, 1, 2], lty = 3, col = "blue")
}
legend("topleft", c("Estimated ADRF", "True ADRF", "90% band"),
col = c("blue", "red", "blue"), lty = c(1, 2, 3), lwd = c(2, 2, 1))