*! version 1.0 10Dec2018
help crtrees_p

Syntax for predict after Random Forests using crtrees

predict [type] newvar [type] 2 [if] [in] [, opentrees(filename)]

Syntax for predict after Regression and Classification Trees using crtrees

predict [type] newvar [if] [in]

newvar is the name for the new variable containing the model predictions.
For Random Forest (Regression), newvar2 is the name for the new variable containing the bootstrap standard error of the model prediction.
For Random Forest (Classification), newvar2 is the name for the new variable containing the bootstrap misclassification cost (by default, the probability of misclassification).

Random Forests
opentrees(string) name of file with mata matrices of bootstrapped trees, their node criteria and coefficients

Description

predict after crtrees creates a variable containing the predictions of the last estimated model.
If option rforests was used with crtrees, then it creates two variables.
The first one contains the predictions.
The second one contains either the boootstrap standard error of the predictions (under Regression) or the bootstrap misclassification cost of the classifier (under Classification).

Options

Random Forests

opentrees(string) string containing the name of the file where to find mata matrices of bootstrapped trees and coefficients in terminal nodes for each tree.
The file must exist and the directory must be readable.
When option opentrees is not specified, predict attemps first to load mata matrices from file e(matatree).
If unsuccessful, then it attempts to load mata matrices from file matatree in the current working directory.

Remarks

The model predictions are computed using the honest tree under CART, the average prediction of all bootstrapped trees under Random Forest (Regression), or the most popular vote from all bootstrapped trees under Random Forest (Classification).

Under Random Forest, standard errors/misclassification costs are computed using all bootstrapped trees saved after command crtrees.

Examples

sysuse auto, clear

Regression Trees with partition, learning sample size 0.5, and 0 SE rule.
The model predicts within-node constant expectations:

. crtrees price trunk weight length, seed(12345)

. predict price_hat

Under Random Forest, crtrees creates mata matrix file where all trees in the forest are stored.
predict uses by default, if it still exists, the file last saved with crtrees:

. crtrees price trunk weight length, rforests generate(p_hat) bootstraps(2500) savetrees("mymatafile1")

. predict price_hat price_stdp

And we get the same result using opentrees

. predict price_hat price_stdp, opentrees("mymatafile1")

Author

Ricardo Mora

email:ricmora@eco.uc3m.es

Departament of Economics, Universidad Carlos III Madrid

Madrid, Spain

References

Breiman, Leo ; Friedman, Jerome H ; Olshen, Richard A ; Stone, Charles J (1984).
Classification and Regression Trees.
Monterey, CA : Wadsworth & Brooks/Cole Advanced Books & Software.

Breiman, Leo (2001).
Random Forests, Machine Learning, Vol. 45, 5-32.

Sexton, Joseph; Laake, Peter (2009).
Standard errors for bagged and random forest estimators, Computational Statistics and Data Analysis, Vol. 53, 801-811.

Efron, Bradley (2014)
Estimation and accuracy after model selection, Journal of the American Statistical Association, 109:507, 991-1007.

Scornet, Erwan; Biau, Gérard; Vert, Jean-Philippe (2015).
Consistency of random forests, The Annals of Statistics, Vol. 43, No. 4, 1710-1741.

Update: February - 2019