Tutorials › Propensity Score Matching and Instrumental Variables › Random Forest Propensity Score Estimation

The Balancing Property and Estimation · Tutorial 140 of 699

Random Forest Propensity Score Estimation

You will learn how random forests estimate treatment probabilities, what controls their predictions, and how to assess their calibration and limitations.

Intermediate 12 min read

What You'll Learn

  • Define a random-forest estimate of the probability of treatment given covariates.
  • Calculate a forest prediction by averaging terminal-node treatment proportions.
  • Explain how bootstrap aggregation and randomized feature selection make trees differ.
  • Compare the piecewise-constant predictions of forests with logistic-model predictions.
  • Diagnose calibration, overfitting, and instability without treating a high-performing classifier as a sufficient propensity model.

Why Use a Random Forest for a Propensity Score?

A propensity score is the probability of receiving treatment conditional on measured covariates. Write \(A_i=1\) for a treated unit and \(A_i=0\) for a control unit, and let \(X_i\) denote that unit’s covariate vector. The true propensity score is \(e(X_i)=P(A_i=1\mid X_i)\); a fitted score is an estimate of this probability. The estimation challenge is to represent how treatment assignment changes with covariates without relying on an overly restrictive functional form.

A logistic model gives predictions through a specified linear predictor, possibly expanded with transformations, interactions, or splines. A random forest instead averages predictions from many classification trees. This can represent nonlinear patterns and interactions that were not entered explicitly. The trade-off is important: the forest’s probability estimates are built from tree leaves, so they are generally piecewise constant rather than smoothly varying, and the algorithm does not guarantee good probability calibration.

A treatment model is only one part of a causal analysis. For causal interpretation using measured covariates, the usual conditions include consistency, conditional exchangeability given \(X\), and positivity: each relevant covariate pattern must have a nonzero probability of receiving either treatment. Estimating a propensity score with a forest does not establish these conditions, repair unmeasured confounding, or ensure adequate overlap.

Definition: A random-forest propensity-score estimate is an estimate \(\hat e(X_i)\) of \(P(A_i=1\mid X_i)\) obtained by averaging treatment-probability predictions from many classification trees. In a common implementation, each tree predicts the proportion treated among the observations in the terminal leaf containing \(X_i\), and the forest prediction is the mean of those tree predictions.

How Bootstrap Aggregation and Randomized Features Work

A classification tree recursively divides the covariate space into regions. At a split, a candidate covariate and cut point are chosen to separate treated from control observations according to a splitting criterion, such as Gini impurity. A terminal leaf contains observations that are not split further. If \(n_{\ell}\) observations in leaf \(\ell\) are used to fit the tree and \(n_{\ell,1}\) are treated, the leaf’s estimated treatment probability is \(n_{\ell,1}/n_{\ell}\). A tree predicts that same value for every covariate vector falling in that leaf.

A forest creates variation among trees in two main ways. First, each tree is grown using a bootstrap sample: a sample of size \(n\) drawn with replacement from the \(n\) observed units. Some units can appear multiple times and some are absent from a particular tree’s sample. Second, at each candidate split, the algorithm considers a randomly selected subset of covariates rather than always searching all covariates. The number of candidate covariates is commonly called mtry. The specific split, tree structure, and leaf proportions can therefore vary across trees.

For \(B\) trees, write \(\hat e_b(X_i)\) for the treatment-probability prediction from tree \(b\). The forest prediction is

$$ \hat e_{\mathrm{RF}}(X_i)=\frac{1}{B}\sum_{b=1}^{B}\hat e_b(X_i). $$

Averaging is the bootstrap-aggregation, or bagging, step. The randomized feature selection helps make trees less alike: when one strong predictor would otherwise dominate the first split in nearly every tree, restricting the candidates gives other predictors opportunities to shape some trees. Neither mechanism means that every tree is an equally good model of the treatment mechanism. They are design choices intended to produce a useful average.

Why Averaging Can Stabilize Predictions

The variance calculation below explains one benefit of averaging, while also showing why more trees cannot remove every source of variation. Suppose that, for a fixed covariate vector \(X\), the tree predictions have variance \(\sigma_T^2\), and any two distinct tree predictions have common correlation \(\rho\). These are simplifying conditions for the calculation, not claims that real trees always have identical variances and correlations. The variance of their average is

$$ \begin{aligned} \operatorname{Var}\left(\frac{1}{B}\sum_{b=1}^{B}\hat e_b(X)\right) &=\frac{1}{B^2}\left[B\sigma_T^2+B(B-1)\rho\sigma_T^2\right]\\ &=\sigma_T^2\left[\rho+\frac{1-\rho}{B}\right]. \end{aligned} $$

To obtain the first line, add the \(B\) individual variances and the \(B(B-1)\) ordered covariance terms, each covariance being \(\rho\sigma_T^2\), then divide by \(B^2\). If tree predictions are positively correlated, the variance approaches \(\rho\sigma_T^2\), not zero, as \(B\) grows. Bootstrap samples and randomized feature selection can reduce dependence among trees, but they do not eliminate shared information in the data or bias from a poor modeling setup.

Worked Example: Averaging Tree Probabilities

Suppose four fitted trees predict treatment probabilities of \(0.20\), \(0.40\), \(0.60\), and \(0.80\) for the same hypothetical unit. The forest prediction is their arithmetic mean:

$$ \hat e_{\mathrm{RF}}(X) =\frac{0.20+0.40+0.60+0.80}{4} =\frac{2.00}{4} =0.50. $$

The forest’s fitted treatment probability for this unit is \(0.50\). This is not a statement that the unit has a 50% chance of being treated after its treatment has already been observed; it is the model’s estimated conditional probability given the covariates. The example also shows that the forest prediction need not equal any one tree’s prediction.

Worked Example: A Terminal-Leaf Prediction

Consider a hypothetical tree whose terminal leaf contains five bootstrap-sample observations with treatment indicators \(1,1,1,0,0\). A unit whose covariates fall in that leaf receives the leaf treatment proportion:

$$ \hat e_{\ell}=\frac{n_{\ell,1}}{n_{\ell}}=\frac{3}{5}=0.60. $$

If three other trees predict \(0.40\), \(0.60\), and \(0.80\) for the same unit, the four-tree forest prediction is

$$ \hat e_{\mathrm{RF}}(X)=\frac{0.60+0.40+0.60+0.80}{4} =\frac{2.40}{4}=0.60. $$

The leaf proportion is a probability estimate, not a treatment classification threshold. In particular, converting \(0.60\) into a label such as “treated” would answer a classification question, not provide the propensity score needed for analyses that use treatment probabilities.

Calibration, Smoothness, and Comparison with Logistic Predictions

A probability model should be assessed as a probability model. Calibration concerns whether units assigned probabilities near a value \(q\) experience treatment at a rate near \(q\), considered across suitable groups of units. A forest can classify treated and control observations well while still systematically overpredicting or underpredicting treatment probabilities. Classification accuracy or area under a receiver operating characteristic curve does not, by itself, establish calibration.

A logistic model with a linear predictor gives predictions of the form \(1/(1+\exp(-\eta(X)))\), where \(\eta(X)\) is the specified predictor. With finite coefficients, these predictions lie strictly between zero and one and change smoothly as \(\eta(X)\) changes. A forest prediction is an average of leaf proportions. It is generally piecewise constant over regions defined by the trees: a small covariate change may leave the prediction unchanged, while crossing a split can change it abruptly. Averaging many trees can make predictions less irregular than those of a single tree, but it does not make the forest a smooth model in the logistic-regression sense.

Neither approach is automatically better calibrated. Logistic predictions depend on whether the chosen functional form captures the treatment mechanism; a misspecified linear predictor can give systematic errors. Forest predictions can capture complex patterns but may be poorly calibrated, especially with small leaves, sparse treatment categories, or excessive adaptation to the observed sample. Calibration plots and numerical summaries should be evaluated on data not used to judge the same fitted predictions; cross-validation for model tuning provides relevant background on separating fitting from evaluation.

Worked Example: Overall Calibration Can Hide Group Differences

Suppose a hypothetical sample is divided into three covariate-defined groups of 10 units each. The observed treated counts are 3, 5, and 7, so the observed treatment proportions are \(0.30\), \(0.50\), and \(0.70\). Imagine that a forest assigns mean predictions \(0.20\), \(0.50\), and \(0.80\) to these groups, while a logistic model assigns \(0.30\), \(0.50\), and \(0.70\).

For the forest, the mean predicted probability over all 30 units is

$$ \frac{10(0.20)+10(0.50)+10(0.80)}{30} =\frac{15}{30}=0.50. $$

The overall observed treatment proportion is also \((3+5+7)/30=15/30=0.50\). Nevertheless, the forest underpredicts the observed rate in the first group by \(0.10\), matches the second group, and overpredicts the third by \(0.10\). The logistic predictions match the three observed group proportions in this constructed example. Overall agreement alone therefore cannot establish calibration across covariate patterns. These hypothetical grouped summaries illustrate a diagnostic; they do not imply that logistic models are generally better calibrated.

Practical Choices and Failure Modes

The forest’s behavior depends on tuning choices. The number of trees \(B\) controls how well the finite forest approximates its own averaging process; increasing \(B\) often reduces Monte Carlo variation in the forest prediction, but does not cure bias or guarantee calibration. The number of candidate covariates at each split affects how strongly trees resemble one another. Minimum leaf size and other restrictions affect the granularity of the fitted probabilities: very small leaves can yield noisy proportions, including values of zero or one, while larger leaves can smooth predictions by pooling more observations.

These choices should be made with the propensity-score objective in mind. A split criterion optimized for separating treated from control units need not optimize probability calibration or covariate balance for a later causal analysis. Use probability-sensitive diagnostics, inspect the distribution of estimated scores by treatment group, and check whether relevant covariate patterns have support in both groups. Calibration is not the same as balance, and neither a visually good calibration plot nor a high classification score proves that all confounders have been controlled.

The major failure modes include overly pure leaves that produce extreme estimates, sparse covariate regions where predictions depend on very few observations, and covariates that are influential but represented inconsistently across trees. A forest can also fail to represent a genuine pattern if the available data provide little information about it. As with logistic models, estimated scores near zero or one can indicate weak overlap; they deserve investigation rather than automatic acceptance or removal.

Common pitfall: “The forest classifies treatment accurately, so its propensity scores must be good.” This is incorrect because classification evaluates treatment labels at a decision threshold, whereas propensity estimation requires useful probabilities. Check calibration and the covariate support relevant to the intended causal analysis; do not infer either from classification accuracy alone.

When a Forest Is a Sensible Alternative

A random forest is a useful candidate when treatment assignment may involve nonlinearities or interactions that are difficult to specify in advance, and when there are enough observations to support flexible partitions. It avoids requiring the analyst to write every interaction explicitly. Its limitations are equally practical: predictions can be locally rough, probabilities may need calibration assessment, and the fitted model is less directly summarized by a small set of coefficients than a logistic model.

A single classification tree is easier to inspect but can be unstable: modest changes in data may alter its splits and predictions. A forest reduces dependence on any one tree by averaging many varied trees. Logistic regression offers a smoother, more compact functional form when its specification is adequate, while a forest can offer greater flexibility at the cost of less transparent structure. These are alternative modeling strategies, not guarantees about which estimated score will be preferable in a particular analysis.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A forest has five tree predictions for a unit: \(0.10\), \(0.30\), \(0.50\), \(0.70\), and \(0.90\). What is its estimated propensity score?
  2. A leaf contains 12 observations, of whom 9 are treated. What probability does that tree assign to a unit in the leaf?
  3. Why can increasing the number of trees reduce some prediction variation without removing all variation?
  4. What is one reason a forest can be well calibrated overall but poorly calibrated within covariate-defined groups?
  5. Why is classification accuracy not enough to evaluate a propensity-score estimator?

Solutions. (1) The mean is \((0.10+0.30+0.50+0.70+0.90)/5=2.50/5=0.50\). (2) The leaf proportion is \(9/12=0.75\). (3) Averaging reduces the component of variation due to differences among trees, but correlated trees leave a shared component; under the equal-correlation calculation, the variance approaches \(\rho\sigma_T^2\). (4) Errors in different groups can cancel in the overall average, as in the worked example where underprediction and overprediction offset. (5) Accuracy evaluates treatment labels at a threshold, not whether estimated probabilities agree with observed treatment rates; probability calibration and covariate support need separate assessment.

Clinical Biostats