Other implementations

forest-stream’s estimators are standard methods with several well-known implementations. This page says what each function is compared with, which options correspond to which, and where the results are expected to differ and why.

What is compared with what

The references are made by benchmarks/external/forest_references.R on the cases in tests/data/cases.json, and saved in tests/data/references.json; the tests in tests/test_references.py read them, so R is not needed to run them.

Function

Compared with

How it agrees

decision_tree (also weighted)

rpart

The same splits, on the same rows, and the same predictions and class probabilities, to 1e-8. The test data have few distinct feature values, so binning loses nothing.

Robust variances (best_linear_projection, calibration_test; also weighted)

the sandwich package

Coefficients and the HC0 to HC3 and CRV1 variances, to 1e-8 (sandwich’s vcovHC and vcovCL(type="HC1")).

quantile_forest

grf

The out-of-bag quantiles at the levels the forest was grown for and at others: the pinball loss, the coverage, and the estimates themselves, within tolerances.

instrumental_forest

grf

The out-of-bag estimates, their variances, the average of the local effects and its standard error, and the best linear projection, within tolerances.

causal_forest

grf

The out-of-bag estimates, their variances, the average effect and its standard error, the best linear projection, the calibration test and the variable importance, within tolerances.

regression_forest

grf

The out-of-bag predictions and their variances, within tolerances.

random_forest

ranger

The out-of-bag R-squared (regression), and the out-of-bag accuracy and log loss (classification), within tolerances.

Forests are random, and the implementations draw their random numbers differently, so agreement is judged on the same data by the size of the differences: for example the average treatment effect within half a standard error of grf’s, with a standard error within 10 percent of grf’s; the best linear projection’s coefficients within half a standard error; a regression forest’s variance within 10 percent. benchmarks/validation/compare.py runs a Monte Carlo of the same comparison, over replicates of simulated designs, for the bias, spread and coverage of the average effect and the error and coverage of the conditional estimates, against grf and (if it is installed) EconML.

Options

forest-stream

grf

ranger

rpart

scikit-learn

num_trees

num.trees

num.trees

n_estimators

min_node_size

min.node.size

min.node.size

minbucket

min_samples_leaf

node_size_rule="split"

the rule of min.node.size

the rule of min.node.size

node_size_rule="leaf"

minsplit = 2 * minbucket

min_samples_leaf

features_per_split

mtry

mtry

max_features

sample_fraction

sample.fraction

sample.fraction

max_samples

replace

(without)

replace

bootstrap

honesty, honesty_fraction

honesty, honesty.fraction

min_child_fraction

alpha (regression)

min_treatment_variation

alpha (causal)

variance_group_size

ci.group.size

max_depth

max.depth

maxdepth (the root is 0)

max_depth (the root is 0)

criterion

splitrule

parms = list(split = ...)

criterion

cluster

clusters

weights

sample.weights

(case.weights sets sampling probabilities)

weights

sample_weight

Where the results differ

  • Leaf sizes. Two conventions are in use. grf, ranger and R’s randomForest do not split a node of at most min_node_size rows, and a split’s children can be any size, so leaves can be smaller than min_node_size (node_size_rule="split"). scikit-learn and rpart require every leaf to have at least that many rows, so a node of fewer than twice as many is not split (node_size_rule="leaf"). regression_forest and random_forest use the first; decision_tree the second. A causal forest’s rule is grf’s: each child needs min_node_size treated and control rows (or, for a continuous treatment, rows below and above the parent’s mean treatment).

  • Binning. Features are cut into at most 256 quantile bins once, and splits are made between bins. Other implementations consider every value. With more than 256 distinct values this is an approximation; with fewer, it loses nothing.

  • Sampling with replacement. A bootstrap draws each row a Poisson number of times (mean sample_fraction) and not exactly n rows with replacement, so the sample size varies from tree to tree. The out-of-bag share is exp(-sample_fraction).

  • Random forests’ probabilities. ranger’s probability forests give smoother out-of-bag probabilities than a forest grown to full depth, with the same accuracy; scikit-learn’s do not, and forest-stream’s are like scikit-learn’s. The log loss is therefore only expected to be of the same size.

  • Nuisance functions of a causal forest. grf estimates the outcome’s and the treatment’s conditional means with out-of-bag regression forests; so does causal_forest(nuisance="forest"), and handles fixed effects in them by backfitting (see Fixed effects). The weights that debias the average effect of a continuous treatment come from a regression forest of the squared residualized treatment here and from grf’s own debiasing weights there. nuisance="linear" is not grf’s.

  • Quantile forests. A leaf keeps the outcomes of its estimation rows, and a quantile is the weighted quantile of the outcomes in a row’s leaves over all trees (Meinshausen 2006), with trees grown by the generalized random forests rule for quantiles (Athey, Tibshirani and Wager 2019): rows are labeled by the intervals that the node’s own quantiles cut, and the split is chosen on those labels. grf’s quantile forest, quantile regression forests that grow ordinary regression trees (Meinshausen’s quantregForest, ranger with quantreg=TRUE, scikit-learn-based packages such as quantile-forest), and this one differ in how the trees are grown and in whether they are honest. Features are binned to at most 256 values, as in the other forests. There is no variance estimate.

  • Instrumental forests. The splits, the leaf estimates and their variances follow grf’s instrumental forest: the same pseudo-outcomes and balance rules, with three centering forests. The doubly robust scores of the average effect divide by an estimate of the covariance of the treatment and the instrument given the features, which grf obtains for a binary instrument from a causal forest of the treatment on the instrument (times the instrument’s variance); here it is a regression forest of the product of the centered treatment and instrument, which is the same quantity and also serves a continuous instrument. grf’s average is for binary instruments only.

  • Weights. ranger’s case.weights are sampling probabilities; forest-stream’s (and grf’s, rpart’s and lm’s) weight the criteria and the estimates, so there is no ranger counterpart. Sizes count rows, as in rpart and grf. The criteria, estimates and standard errors with weights are compared with weighted rpart, weighted lm with the sandwich variances, and grf with sample.weights.

  • Splits that gain nothing. A split must improve the criterion by more than rounding noise (a relative 1e-12). Among splits that are equal in exact arithmetic, such as one row set apart from the rest from either side, the first in the random feature order is taken, so the trees do not depend on the scale of the weights or on rounding.

  • Honest trees. Both prune leaves that no estimation row reaches. Both weight the trees equally in the prediction, and estimate variances by little bags with a Bayesian debiasing correction.

Variance estimators

The linear projection and the calibration test take vcov= spelled as in hdfe-stream: "HC0" to "HC3", "hetero" (HC1), and a clustering as {"CRV1": column}, which names the column the forest was fitted with as cluster=. CRV1 has hdfe-stream’s small-sample factor, G/(G-1) (n-1)/(n-k), and p-values from G-1 degrees of freedom. The result’s vcov_type is hdfe-stream’s key: "hetero" for HC1, the name for the other HC types, and "CRV1:<column>" for a clustering; the average effect’s is "iid" or "CRV1:<column>". The defaults are grf’s: HC3, and CRV1 by the forest’s clusters.

References

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

  • Breiman, L. (2001). Random forests. Machine Learning 45(1).

  • Breiman, L., Friedman, J., Olshen, R. and Stone, C. (1984). Classification and Regression Trees. Wadsworth.

  • Chernozhukov, V., Demirer, M., Duflo, E. and Fernández-Val, I. (2018). Generic machine learning inference on heterogeneous treatment effects in randomized experiments. NBER Working Paper 24678.

  • Nie, X. and Wager, S. (2021). Quasi-oracle estimation of heterogeneous treatment effects. Biometrika 108(2).

  • Oza, N. and Russell, S. (2001). Online bagging and boosting. Artificial Intelligence and Statistics 2001.

  • Robinson, P. (1988). Root-N-consistent semiparametric regression. Econometrica 56(4).

  • Wager, S. and Athey, S. (2018). Estimation and inference of heterogeneous treatment effects using random forests. Journal of the American Statistical Association 113(523).

  • Wright, M. and Ziegler, A. (2017). ranger: a fast implementation of random forests for high dimensional data in C++ and R. Journal of Statistical Software 77(1).