σ StatsDoge Causal inference workflows
12
Workflow·5 steps·branched

An introduction to GRF (getting started)

Source grf — Athey, Tibshirani & Wager
Summary by StatsDoge

A minimal first-contact recipe: regression forest, quantile forest, and a causal forest on the same data.

1

Input · what goes in

2,000 obs, 10 covariates X, a binary treatment W, continuous outcome Y.

Show data format & exampleHide example

Format — one row per unit. A covariate matrix X (numeric), a binary treatment W ∈ {0,1}, and an outcome Y.

  X1     X2    X3    W    Y
 0.42  -1.1   0     1   3.10
-0.07   0.6   1     0   1.85
 1.20   0.3   0     1   4.02
2

Pipeline · the recipe ⑂ has parallel branches

↑ Click any step in the diagram to read its logic, code, assumptions & discussion.

1
Data prep

Assemble X, W, Y; check overlap

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

What happens here

One row per unit; numeric design matrix X, treatment W, outcome Y. Eyeball propensity overlap.

Reads from the input data Feeds into #2#3#4
Discussion on this step (0)
  • No comments on this step yet — be the first.
2
Estimation

[GRF] Regression forest

The core estimate — where the causal quantity itself is computed.

What happens here

Fit E[Y|X]; read off OOB predictions and variable_importance().

Formula
\hat\mu(x)=\mathbb{E}\!\left[\,Y\mid X=x\, ight]
The estimator

Regression forest — Honest non-parametric regression for E[Y|X], with out-of-bag predictions and pointwise CIs.

Reads from #1 Feeds into #5
Key code
rf <- regression_forest(X, Y)
Y.hat <- predict(rf)$predictions
Discussion on this step (0)
  • No comments on this step yet — be the first.
3
Estimation

[GRF] Quantile forest

The core estimate — where the causal quantity itself is computed.

What happens here

Fit conditional quantiles to see distributional, not just mean, structure.

Formula
\hat q_\alpha(x)=\inf\{y:\hat F(y\mid X=x)\ge\alpha\}
The estimator

Quantile forest — Conditional quantile estimation — the full predictive distribution, not just the mean.

Reads from #1 Feeds into #5
Key code
qf <- quantile_forest(X, Y, quantiles = c(.1, .5, .9))
predict(qf, X.test)
Discussion on this step (0)
  • No comments on this step yet — be the first.
4
Estimation

[GRF] Causal forest

The core estimate — where the causal quantity itself is computed.

What happens here

Fit CATEs with the same call shape; predict with estimate.variance = TRUE.

Formula
au(x)=\mathbb{E}\!\left[\,Y(1)-Y(0)\mid X=x\, ight]
The estimator

Causal forest — Honest random forest for heterogeneous treatment effects — CATE for a binary treatment via GRF moment conditions.

Reads from #1 Feeds into #5
Key code
cf <- causal_forest(X, Y, W)          # Y.hat, W.hat cross-fit
tau.hat <- predict(cf)$predictions    # OOB CATEs
Discussion on this step (0)
  • No comments on this step yet — be the first.
5
Reporting

OOB predictions & variable importance

Reporting — turn the numbers into a figure or table a reader can act on.

What happens here

Compare the three forests; show importance and a CATE histogram.

Reads from #2#3#4 Feeds into the final output
Discussion on this step (0)
  • No comments on this step yet — be the first.
3

Output · what you get 4 figures

Out-of-bag CATE estimates across 2,000 simulated units.
Fig 1Out-of-bag CATE estimates across 2,000 simulated units.
Predicted τ̂(x) against the true effect — the forest recovers the underlying signal.
Fig 2Predicted τ̂(x) against the true effect — the forest recovers the underlying signal.
CATE estimates with 95% confidence bands along a single covariate.
Fig 3CATE estimates with 95% confidence bands along a single covariate.
A RATE / TOC curve summarising how much heterogeneity the forest found.
Fig 4A RATE / TOC curve summarising how much heterogeneity the forest found.

Figures reproduced from grf — Athey, Tibshirani & Wager — unofficial community showcase; all credit to the original authors.

The GRF 'introduction' vignette, distilled to a teaching recipe. Shows the shared API across forest types and where OOB predictions and variable importance come from. Unofficial summary.

Discussion (2)

  • 6

    Perfect first-contact recipe. Showing the identical call shape across regression/quantile/causal forests is the fastest way to 'get' the package.

  • 2

    Would hand this to any new grad student. Clean.