Tutorials › Econometrics (Graduate) › A Worked Causal Forest Analysis

Treatment Effect Heterogeneity · Tutorial 841 of 952

A Worked Causal Forest Analysis

Work through a causal-forest analysis from prepared covariates to subgroup summaries, while keeping the sign, target population, and uncertainty of each estimate clear.

Advanced 10 min read

What You'll Learn

  • Define the CATE as a treated-minus-control contrast and interpret its sign in outcome units.
  • Prepare baseline covariates for a causal forest without conditioning on post-treatment variables.
  • Describe a forest prediction as a conditional average, not an individual's treatment effect.
  • Aggregate CATE predictions over a specified subgroup and calculate the weighted overall mean.
  • Check covariate support, reported standard errors, and sensitivity to reasonable fitting choices.
  • Distinguish exploratory uncertainty checks from formal pointwise inference.

From a Study Question to Forest Outputs

A causal forest can return a different estimated treatment effect for people with different measured characteristics. The practical challenge is to carry the analysis from a defensible covariate set to predictions and summaries without changing the quantity being estimated along the way. In particular, a predicted effect is an average for people with similar covariates, not a measurement of what treatment did to one specific person.

We will follow a fully hypothetical simulated study of a treatment intended to reduce a symptom score measured at follow-up. Lower scores mean fewer symptoms. Treatment is randomized, and the score is measured in points, so a negative treated-minus-control contrast represents a reduction in symptoms under treatment. All sample sizes and forest outputs below are illustrative.

Definition: Let \(Y(1)\) and \(Y(0)\) denote the potential follow-up outcomes under treatment and control, and let \(X\) be a vector of measured baseline covariates. The conditional average treatment effect (CATE) is $$ \tau(x)=E[Y(1)-Y(0)\mid X=x]. $$ For a symptom score where lower values are better, \(\tau(x)<0\) means that the average score under treatment is lower than the average score under control for people with covariates \(x\). The CATE is not an individual's treatment effect \(Y(1)-Y(0)\), because only one of those two potential outcomes is observed for any individual.

The target in this example is the CATE for people represented in the simulated study. Identification requires consistency (the observed outcome agrees with the potential outcome for the treatment received), no interference between units, and treatment assignment independent of potential outcomes. Randomization with positive probability of assignment to both arms supplies the latter condition here. For observational data, conditional exchangeability given \(X\) and positivity would instead be needed; a forest does not make those assumptions true.

Preparing Covariates and Fitting the Forest

Suppose the simulated study contains 4,000 participants, with 2,000 assigned to treatment and 2,000 to control. The outcome \(Y\) is the symptom score at follow-up. The baseline covariates are age in years, symptom severity on a 0–10 scale, and the number of prior episodes. In the simulation, treatment is assigned with probability one-half. The outcome-generating pattern has larger average symptom reductions at higher baseline severity, but the forest is not told that pattern.

Covariate preparation starts by defining the prediction target and time order. Age, baseline severity, and prior episodes are measured before assignment, so they can be used as \(X\). Follow-up adherence and the follow-up symptom score are not baseline covariates; adding them as predictors would condition on post-treatment information and change the analysis. Categorical baseline variables, if present, should be encoded consistently. Missing values need an explicit, defensible handling rule, rather than silently treating a missing value as a meaningful numerical value. Tree-based methods generally do not require predictors to be put on a common measurement scale, but clear units and coding still matter for interpretation and reproducibility.

Worked Example: Checking a Covariate Record

A hypothetical participant is 45 years old, has baseline severity 9 out of 10, and reports 2 prior episodes. Treatment was randomized. Decide what enters the forest prediction and what the treatment contrast means.

Covariate record. The prediction uses \(X=(45,9,2)\): age is in years, severity is on the 0–10 scale, and prior episodes is a count. Each value is observed before treatment assignment, so the record does not use treatment consequences.

Assignment and outcome. The participant is assigned to one arm, but the forest estimates a contrast between potential outcomes for people with this covariate profile. The participant's observed follow-up score alone cannot reveal both \(Y(1)\) and \(Y(0)\).

Sign check. Because the outcome is the symptom score and lower is better, a predicted value such as \(-1.42\) points would mean an estimated 1.42-point lower average score under treatment than under control for people with these covariates. It would not mean a positive 1.42-point reduction in the treated-minus-control outcome contrast.

For fitting, use the causal-forest procedure appropriate to the target CATE and its treatment-assignment design. In this randomized example, the known assignment probability is \(e(x)=P(W=1\mid X=x)=0.5\), where \(W\) indicates treatment. A forest uses covariate-dependent neighborhoods and treatment-outcome information to estimate conditional contrasts; its predictions are not obtained by simply fitting a separate treatment effect to each person. Follow the procedure's honesty or sample-separation options as intended, and record the covariates, treatment coding, outcome definition, forest settings, and random seed. These choices make the analysis auditable, but do not replace the causal assumptions.

Identification in this randomized example: Under consistency, no interference, and randomized assignment with positive treatment probability, $$ \tau(x)=E[Y\mid W=1,X=x]-E[Y\mid W=0,X=x]. $$ This equality identifies a conditional average contrast from observed data. The forest approximates how that contrast varies with \(x\); it does not identify an effect for each individual.

Reading CATE Predictions

Imagine that one illustrative forest fit returns a predicted CATE of \(-1.42\) symptom-score points at age 45, baseline severity 9, and 2 prior episodes. The value is an estimated conditional average, based on the fitted forest and the available study data. It is not a guarantee that a participant with those covariates will improve by 1.42 points, nor does it describe the difference between that participant's two unobserved potential outcomes.

Worked Example: Interpreting a Forest Prediction

For the covariate profile above, suppose the illustrative prediction is \(\widehat{\tau}(x)=-1.42\) points. State the contrast in context and check its direction.

By definition, the estimated contrast is treatment minus control. Thus the prediction says that the estimated average follow-up symptom score for people with this profile is 1.42 points lower under treatment than under control: $$ \widehat{E[Y(1)-Y(0)\mid X=x]}=-1.42\text{ points}. $$

The negative sign matches the outcome scale: lower symptom scores are better, so the estimated contrast favors a lower score under treatment. The prediction does not say that every person with this profile has a 1.42-point response. Individuals with the same measured \(X\) can have different outcomes and different unobserved individual treatment effects.

It is also important to separate an estimated CATE at a covariate value from a subgroup effect. A point prediction refers to a conditional mean at \(x\); a subgroup effect averages that conditional mean over a defined population. The subgroup definition and its target population must be explicit. A threshold selected after inspecting many forest predictions is a data-adaptive discovery, not automatically a prespecified subgroup result.

Summarizing Effects Over a Subgroup

For a subgroup \(G\) defined using baseline covariates, its average treatment effect is the average of \(\tau(X)\) among members of \(G\). The relationship follows directly from iterated expectations: $$ E[Y(1)-Y(0)\mid X\in G] =E\{E[Y(1)-Y(0)\mid X]\mid X\in G\} =E[\tau(X)\mid X\in G]. $$ Thus subgroup summaries can be formed by averaging CATE predictions for the subgroup's covariate profiles. The average must use the subgroup's target-population weights; an unweighted average of arbitrary profile predictions need not represent that population.

Worked Example: Averaging Predictions by Baseline Severity

In an illustrative assessment sample of 1,200 people, 480 have baseline severity below 8 and 720 have severity of at least 8. The forest's average predicted CATE is \(-0.72\) points in the lower-severity group and \(-1.55\) points in the higher-severity group. Calculate the sample-weighted average prediction and interpret the subgroup contrast.

The weighted average across the 1,200 people is $$ \frac{480(-0.72)+720(-1.55)}{1200} =\frac{-345.6-1116}{1200} =\frac{-1461.6}{1200} =-1.218\text{ points}. $$

In this illustrative sample, the model's average predicted treated-minus-control contrast is \(-1.218\) points. The high-severity group has a more negative average predicted contrast than the low-severity group: \(-1.55-(-0.72)=-0.83\) points. This is a difference between subgroup average predictions, not proof that every high-severity person benefits more. Nor should it be read as a causal subgroup finding without considering the analysis design, uncertainty, and how the grouping was chosen.

Uncertainty and Support Checks

A point prediction can look precise while being based on little relevant information. Before interpreting a pattern, check that the covariate profiles or subgroups occur in the data and have treated and control observations. In this randomized example, treatment probability is one-half by design, but sparse combinations of severity, age, and prior episodes may still yield unstable local estimates. A forest cannot manufacture information for profiles far outside the observed covariate support.

If the implementation reports a standard error for a prediction, record it with the prediction and check its scale. Its meaning and inferential validity depend on the estimator and the procedure used to calculate it. Reasonable sensitivity checks include refitting with a different random seed or modestly varied forest settings and examining whether the broad pattern persists. These checks are diagnostics, not substitutes for formal inference or a validation analysis.

Worked Example: Checking the Uncertainty of a Prediction

Suppose the forest reports an illustrative prediction of \(-1.42\) points with a reported standard error of \(0.48\) points for the profile used above. A modest refit gives \(-1.28\) points. Use these numbers for a diagnostic check, not as a formal hypothesis test.

The standard error is about \(0.48/1.42=0.338\), or 33.8% of the absolute prediction. The refit changes the prediction by \(|-1.28-(-1.42)|=0.14\) points, which is smaller than the reported \(0.48\)-point standard error. These comparisons suggest that the displayed estimate has nontrivial uncertainty and that this particular change in fitting choices did not move it greatly.

Neither calculation establishes that the effect differs from zero, and the standard error alone does not guarantee a valid confidence interval. Formal pointwise inference requires the relevant inferential procedure and its conditions. Also inspect covariate support: a small standard error should not be treated as reassurance if the queried profile is poorly represented or the uncertainty calculation is inappropriate for that profile.

Why the Workflow Matters

A causal-forest analysis is most useful when each output is tied to its estimand. Covariate preparation determines which conditional comparisons are being made. The fitted forest supplies estimated CATEs; subgroup averages describe those estimates for a stated population; uncertainty checks indicate how cautiously to read them. The causal interpretation rests on design and assumptions, not on the complexity of the algorithm.

One short derivation helps keep subgroup summaries straight. Because \(\tau(X)\) is the conditional expectation of \(Y(1)-Y(0)\), conditioning on membership in \(G\) and taking an expectation gives $$ E[\tau(X)\mid X\in G] =E\{E[Y(1)-Y(0)\mid X]\mid X\in G\} =E[Y(1)-Y(0)\mid X\in G]. $$ This is why the target distribution within the subgroup matters: changing which covariate profiles receive weight changes the subgroup average even when the conditional effect function is unchanged.

Common pitfall: Calling a predicted \(-1.42\)-point symptom-score contrast a “1.42-point positive treatment effect” reverses the sign convention. With \(\tau(x)=E[Y(1)-Y(0)\mid X=x]\), the correct statement is that treatment is estimated to lower the average symptom score by 1.42 points for people with those covariates. A second error is to call that value an individual's response; it is a conditional average, not an individual treatment effect.

Check Your Understanding

Answer each question using the treatment-minus-control convention and the study context above.

  1. If a predicted CATE is \(-0.60\) symptom-score points, what does its sign mean?
  2. Why should follow-up adherence generally not be included as a baseline covariate in this analysis?
  3. In one sentence, distinguish a CATE prediction from an individual treatment effect.
  4. Why is the overall average prediction in the severity example weighted by 480 and 720 rather than formed as an unweighted average of the two subgroup means?
  5. What can a forest prediction standard error tell you, and what does it not establish by itself?
Clinical Biostats