Generalized random forests that estimate conditional average treatment effects τ(x) non-parametrically, with valid confidence intervals.
Input · what goes in
A covariate matrix X, a treatment vector W, and an outcome vector Y.
Show data format & exampleHide example
| Y | W | X1 | X2 |
|---|---|---|---|
| 1.2 | 1 | 0.4 | -0.7 |
| 0.3 | 0 | -1.1 | 0.2 |
| 2.1 | 1 | 0.9 | 1.3 |
| 0.1 | 0 | 0.0 | -0.4 |
Pipeline · the recipe
↑ Click any step in the diagram to read its logic, code, assumptions & discussion.
Assemble X, W, Y
Data preparation — shapes the raw inputs into what the estimator expects.
Provide covariates, a treatment indicator, and an outcome (observational or experimental).
# Install: install.packages("grf")
library(grf)
n <- 2000; p <- 10
X <- matrix(rnorm(n * p), n, p)
W <- rbinom(n, 1, 0.5)
Y <- pmax(X[, 1], 0) * W + X[, 2] + rnorm(n)
- No comments on this step yet — be the first.
Log in to comment on this step.
Fit a causal forest
The core estimate — where the causal quantity itself is computed.
causal_forest grows honest, heterogeneity-seeking trees and predicts each unit's conditional effect τ̂(x).
cf <- causal_forest(X, Y, W)
tau.hat <- predict(cf)$predictions
- No comments on this step yet — be the first.
Log in to comment on this step.
Aggregate to the ATE
Uncertainty quantification — standard errors, intervals, and aggregation.
average_treatment_effect aggregates the forest to a doubly-robust ATE with a standard error.
average_treatment_effect(cf, target.sample = "all")
- No comments on this step yet — be the first.
Log in to comment on this step.
Output · what you get
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
Result · the numbers
⚠️ Unofficial community showcase of grf (docs). Not affiliated with the authors — all credit to Susan Athey, Julie Tibshirani, Stefan Wager & Erik Sverdrup; this summarizes public documentation.
What it does. grf estimates heterogeneous treatment effects — how the effect τ(x) varies with covariates — using forests, with honest, asymptotically-normal confidence intervals. causal_forest() is the workhorse; average_treatment_effect() aggregates to the ATE.
How it works. It grows many honest trees that split to maximize heterogeneity in the treatment effect (a gradient-based generalization of random forests), then forms a weighted local moment estimator at each x. Out-of-bag predictions give each unit's τ(x); the forest also returns variance estimates for inference.
Assumptions. Unconfoundedness and overlap; honesty (separate splitting and estimation samples) underpins the valid intervals.
This forest-based causal-ML agenda was co-developed with Imbens's program on machine learning for causal inference.
What you get — A per-unit CATE estimate τ̂(x), plus the aggregated ATE with a standard error.
Example output
estimate std.err
0.4982731 0.0461145

Discussion (0)
Log in to join the discussion.