Instrumental forests

instrumental_forest estimates how the effect of a treatment varies with other characteristics when the treatment is not randomly assigned but an instrument moves it: a lottery that encourages enrollment, distance to a college, an assigned judge. It returns what causal_forest does, a standard error for the average effect and a variance for each estimate, for the effect among the rows the instrument moves.

import forest_stream as fs

fit = fs.instrumental_forest(
    "earnings ~ enrolled | age + education + prior_earnings",
    "jobs.parquet",
    instrument="offered",     # a column that moves enrollment and affects earnings only through it
)
fit.average_treatment_effect()          # the average of the local effects, with a standard error
fit.oob_predictions()                   # each row's local effect, from the trees that did not use it
fit.predict("new_people.parquet")       # effects (and variances) for other rows
fit.best_linear_projection("jobs.parquet", ["age", "prior_earnings"])
fit.plot("effects")

The formula is that of causal_forest: outcome ~ treatment | features, with fixed effects after a second |. The instrument is a separate argument, a numeric column (binary or continuous) that is not one of the formula’s columns. Everything else (cluster, weights, num_trees, nuisance, fixed_effects, the memory options) works as it does there.

What the forest estimates

At a row with features x, the instrument changes the outcome by some amount and the treatment by some amount, given the features. Their ratio is the local effect of the treatment: the effect among the rows whose treatment the instrument moves (Imbens and Angrist 1994; Angrist, Imbens and Rubin 1996). When the treatment is binary and no one is moved the wrong way by the instrument, it is the average effect on the compliers at x. When the effect does not differ between the rows the instrument moves and the rest, it is the effect at x. The conditional average effect that causal_forest estimates is the same ratio with the treatment as its own instrument.

The forest is grown as a causal forest is (Athey, Tibshirani and Wager 2019). Each node’s ratio gives every row a pseudo-outcome, the instrument’s departure from its mean times the residual from the node’s fit, and splits are chosen to separate rows whose ratios differ. The instrument takes the place of the treatment in the rules that keep the children balanced: each child needs min_node_size rows with the instrument below and above its parent’s mean, and at least min_treatment_variation of the parent’s variation in the instrument. Trees are honest, and variances come from little bags, as in the causal forest.

The outcome, the treatment and the instrument are first centered on the features (and the fixed effects). With nuisance="forest", the default, that is three out-of-bag regression forests, and with fixed effects each is backfitted: see Fixed effects. nuisance="linear" subtracts a linear fit of each.

The average effect

average_treatment_effect() averages the local effect over the rows, with each row’s score corrected by its own residual:

tau_i + (z_i / c_i) (y_i - tau_i w_i)

where y_i, w_i and z_i are the centered outcome, treatment and instrument, tau_i is the row’s out-of-bag estimate, and c_i is an estimate of the covariance of w_i and z_i given the features (a regression forest of their product). The average is consistent when either the forest’s estimates or the centering is good, and its standard error is that of a mean of the scores, clustered with cluster= (Chernozhukov et al. 2022). For a binary instrument, c_i is the instrument’s effect on the treatment times the variance of the instrument, given the features.

The average is over all rows, not only those the instrument moves: each row counts with its own local effect, however weakly the instrument moves its treatment. Where the instrument is weak the local effect is poorly determined, and the scores’ correction divides by a small, noisy number that can be near zero or of the wrong sign. To keep a few such rows from carrying the whole average, c_i is held at no less than a tenth of its average, in size and with its sign. That limits the correction at those rows, so the average leans on the forest’s own estimates there. The average effect and the projection warn when this applies to one percent of the rows or more; the average then depends more on the forest’s estimates where the instrument is weak, its standard error may be somewhat too small, and it is worth looking at where the instrument is weak.

What is different from the causal forest

  • calibration_test is not available. Its regression is not an instrumental-variable regression. best_linear_projection (the scores regressed on columns) is, and shows how the average differs with the terms.

  • A weak instrument is harder than a weak treatment. Estimates in regions where the instrument barely moves the treatment are noisy, and larger min_node_size (10 to 20) trades a little resolution for much less noise there.

  • Binning matters more. Features are cut into at most 256 quantile bins, and where the instrument is weak the splits that matter can be fine; features with fewer than 256 distinct values lose nothing.

  • The data hold one more column (8 bytes a row on disk, and in each tree’s sample).

Options that matter

The options are those of causal_forest. Two change meaning with the instrument: min_treatment_variation is the share of the parent’s variation in the instrument that each child keeps, and min_node_size counts rows with the instrument below and above its mean.

Other implementations says how the results compare with grf’s instrumental forest.

References

  • Angrist, J., Imbens, G. and Rubin, D. (1996). Identification of causal effects using instrumental variables. Journal of the American Statistical Association 91(434).

  • Athey, S., Tibshirani, J. and Wager, S. (2019). Generalized random forests. Annals of Statistics 47(2).

  • Chernozhukov, V., Escanciano, J., Ichimura, H., Newey, W. and Robins, J. (2022). Locally robust semiparametric estimation. Econometrica 90(4).

  • Imbens, G. and Angrist, J. (1994). Identification and estimation of local average treatment effects. Econometrica 62(2).