Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 079
Research workflow/3 steps

Causal forests for heterogeneous effects (grf)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 3 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 3
01
Data prep

Assemble X, W, Y

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Provide covariates, a treatment indicator, and an outcome (observational or experimental).

Reads fromNot specified Feeds into#2
Key code
# 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)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

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
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureDistribution of causal-forest CATE estimates τ̂(x) across units — spread away from the ATE reveals real effect heterogeneity.

Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.

The estimate

\tau(x)=\mathbb E[\,Y(1)-Y(0)\mid X=x\,],\qquad \hat\tau(x)=\sum_i \alpha_i(x)\,\big(Y_i-\hat\mu(X_i)\big)

Context & interpretation

⚠️ 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 

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion