Skip to content

Uncertainty, structured prediction, and causal learning · Uncertainty, structured prediction, and causal learning · UNC015 · Model

Honest causal forests

Estimate how a conditional average treatment effect varies with observed covariates. Trees adapt neighborhoods to treatment-effect heterogeneity, while honesty separates observations used for splitting from those used…

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through causal.forest. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Estimate how a conditional average treatment effect varies with observed covariates. Trees adapt neighborhoods to treatment-effect heterogeneity, while honesty separates observations used for splitting from those used for leaf estimation. Modern orthogonalized implementations use nuisance regressions to reduce confounding and regularization bias.

Question / hypotheses

For binary treatment, what is τ(x)=E[Y(1)−Y(0)∣X=x]\tau(x)=\mathbb E[Y(1)-Y(0)\mid X=x] under the stated assumptions? This conditional average effect is not the unobservable individual treatment effect for a particular person.

Architecture / computational structure

Grow randomized trees using treatment-effect-oriented splitting criteria and honest estimation subsamples. Forest co-membership defines adaptive weights around a query x. A local residualized moment estimates the effect from weighted treatment/outcome residuals; suitable grouped-tree or influence calculations support uncertainty estimation.

Assumptions

Binary-treatment interpretation requires consistency, no interference in the chosen unit definition, unconfounded treatment given included pre-treatment covariates, and overlap. Forest inference adds sampling, regularity, subsampling and honesty conditions. Randomization helps identification but does not remove limited-support or small-leaf problems.

Formula / computational definition

With estimated m(x)=E[Y∣X=x]m(x)=\mathbb E[Y\mid X=x], e(x)=E[W∣X=x]e(x)=\mathbb E[W\mid X=x], and forest weights αi(x)\alpha_i(x) summing to one, solve ∑iαi(x)(Wi−e^i)[Yi−m^i−τ(x)(Wi−e^i)]=0\sum_i\alpha_i(x)(W_i-\hat e_i)[Y_i-\hat m_i-\tau(x)(W_i-\hat e_i)]=0. Here W is the treatment indicator and the ratio of weighted cross-products gives the displayed scalar estimate when the denominator is positive.

Parameters and notation

Learned: tree partitions, adaptive weights, nuisance functions and treatment-effect surface. Hyperparameters: number of trees, candidate variables, minimum leaf size, sample fraction, honesty fraction, balance constraints and tuning policy. In implementations such as grf, an argument named alpha can describe split balance rather than a hypothesis-test significance level.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is not intrinsic to the forest. Refit nuisance models and honest forests for new data; expanding tree count improves Monte Carlo stability but cannot repair confounding. Transferring a fitted forest across populations requires overlap and transport assumptions; simply recalculating leaves is not enough.

How to use and calibrate

Audit propensity overlap and effective treatment/control support near each query. Use out-of-bag or held-out heterogeneity calibration, prespecified subgroup effects and appropriate policy evaluation. Report average effects separately from conditional predictions. Simulated individual treatment-effect error requires known counterfactual functions, unavailable in ordinary observational data.

Example application

Explore how an experimentally randomized teaching intervention’s average effect varies with baseline preparation. Plot conditional estimates with uncertainty and treatment overlap; avoid ranking students by unvalidated individualized benefit.

Interpretation / pitfalls

Watch out

Flexible heterogeneity searches can discover noise. Honest splitting addresses adaptive estimation bias under conditions, not unmeasured confounding or arbitrary subgroup selection. A small local residual-treatment denominator makes estimates unstable; extrapolation beyond support is not reliable.

Python and R code examples

Scope: Local orthogonal-moment component for supplied hypothetical forest weights and out-of-fold nuisance predictions. It verifies the moment equation; the weights are not learned by a forest and no confidence interval is claimed.

Dependencies / validation: use the shared NumPy/SciPy or base-R setup above. Python executed successfully with assertions; R reviewed but not executed.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Local orthogonal-moment component for supplied hypothetical forest weights and out-of-fold nuisance predictions. It verifies the moment equation; the weights are not learned by a forest and no confidence interval is claimed.

Shared setup for this chapter
import numpy as np
from scipy.special import logsumexp, gammaln
from scipy.linalg import expm
from itertools import product

def rbf(a, b, ell=1.0):
    a, b = np.atleast_2d(a), np.atleast_2d(b)
    return np.exp(-np.sum((a[:, None, :] - b[None, :, :])**2, axis=2)/(2*ell**2))
W=np.array([0.,1.,0.,1.,1.,0.]); Y=np.array([.3,1.4,.8,2.0,1.6,.4])
e=np.array([.4,.5,.5,.6,.5,.4]); m=np.array([.8,1.,1.,1.2,1.1,.7])
a=np.array([.1,.2,.15,.2,.25,.1]); rd=W-e; ry=Y-m
J=np.sum(a*rd**2); tau=np.sum(a*rd*ry)/J
moment=np.sum(a*rd*(ry-tau*rd)); effective_n=1/np.sum(a*a)
assert np.isclose(a.sum(),1) and J>0 and abs(moment)<1e-12
print({'local_effect':float(tau),'moment_residual':float(moment),'weight_effective_n':float(effective_n)})
R

Component demo, not a trained model — Local orthogonal-moment component for supplied hypothetical forest weights and out-of-fold nuisance predictions. It verifies the moment equation; the weights are not learned by a forest and no confidence interval is claimed.

W <- c(0,1,0,1,1,0); Y <- c(.3,1.4,.8,2,1.6,.4)
e <- c(.4,.5,.5,.6,.5,.4); m <- c(.8,1,1,1.2,1.1,.7)
a <- c(.1,.2,.15,.2,.25,.1); rd <- W-e; ry <- Y-m
J <- sum(a*rd^2); tau <- sum(a*rd*ry)/J
moment <- sum(a*rd*(ry-tau*rd)); effective_n <- 1/sum(a*a)
stopifnot(abs(sum(a)-1)<1e-12,J>0,abs(moment)<1e-12)
print(c(local_effect=tau,moment_residual=moment,weight_effective_n=effective_n))

Sources

From the CodeSplash reference, entry UNC015.