RANDOM_FOREST fits a bootstrap-aggregated CART regression forest. The first series in the input list is the dependent variable; all remaining series are predictors. RainbowStats aligns the series to a common date range before estimation.
RANDOM_FOREST(LIST(Y,X1,X2,...),TREES:500,MAX_DEPTH:12,MIN_LEAF:5,MTRY:2,SEED:12345)
| Argument | Description | Default |
|---|---|---|
| LIST(Y,X1,...) | Y is the dependent series. X1...Xp are predictor series. | Required |
| TREES | Number of bootstrap regression trees. | 500 |
| MAX_DEPTH | Maximum depth of each CART tree. | 12 |
| MIN_LEAF | Minimum observations allowed in a terminal leaf. | 5 |
| MTRY | Number of randomly selected predictors considered at each split. | max(1,p/3) |
| SEED | Random seed for reproducible results. | 12345 |
Each tree is estimated from a bootstrap sample. At each node, a random subset of predictors is considered and the split producing the largest reduction in squared error is selected. Forest fitted values are averages across trees.
Observations not selected in a tree's bootstrap sample are out-of-bag (OOB) observations. RainbowStats uses these observations to calculate OOB predictions, RMSE and R-squared. Predictor importance is measured by the increase in OOB squared prediction error after permuting each predictor.
Use EXTRACT(rf,extract_name) or its shorthand EX(rf,extract_name).
| Extract | Result |
|---|---|
summary / model | Model settings, training diagnostics and OOB diagnostics. |
fitted / predicted | Forest conditional-mean fitted-value series. |
residuals | Actual minus mean fitted series. |
oob / oob_prediction | Out-of-bag mean prediction series. |
importance | Raw OOB permutation-importance array in original predictor order. |
benchmark | Comparison of forest and OLS fit and validation diagnostics. |
ols_summary / ols_inference | OLS benchmark coefficients and inference table. |
ols_fitted | OLS benchmark fitted-value series. |
ols_oos / ols_loocv | OLS leave-one-out prediction series. |
regression / proposed_regression | Proposed regression using the forest input data. |
selected_data | Aligned dependent and predictor series used by the forest. |
equation | HTML explanation of the exact forest mean equation: the average of tree predictions expressed as terminal-region indicators. |
rules | Original table of up to 50 terminal leaf rules, ranked by influence; rules from different trees can overlap or repeat. |
consolidate_rules / consolidated_rules | Full table grouping identical terminal regions across trees. Includes exact conditions, supporting trees, leaf predictions, combined weight, active contribution, matching aligned rows and bootstrap counts. |
rules_charts / rule_charts | Slideshow containing the consolidated rule table and one contribution line chart per nonzero rule on the aligned observations. |
rules_bar_chart / bar_chart / bar_charts | Single horizontal bar chart of mean rule contributions. Shows the top 30 by absolute contribution, with remaining contributions grouped into Other positive rules and Other negative rules. |
predictor_bar_charts | Slideshow with one horizontal rule-contribution chart per predictor, followed by its matching rule-detail table. Shows up to 30 nonzero rules per predictor, selected by absolute mean contribution. |
regimes | Table grouping nearby split thresholds for each predictor, with threshold ranges, tree support, split support and mean right-minus-left subtree prediction contrast. |
regimes_bar_chart / regimes_bar_charts | Slideshow with one horizontal threshold-regime chart per predictor, followed by its matching detail table. Shows up to 30 nonzero clusters per predictor, selected by tree support and then split support. |
actual_vs_fitted | Actual-versus-mean-fitted chart. |
slideshow | Model slideshow with diagnostics and the original rule/regime tables. Use the chart extracts separately for contribution and regime slideshows. |
consolidate_rules combines regions with identical full-precision bounds after simplifying repeated bounds on a predictor. Nearby but different thresholds remain separate. Consolidation summarizes the fitted forest without changing its predictions. The full table retains zero-contribution rules; contribution charts omit rules whose contribution is zero throughout the aligned sample.
For a consolidated rule, its active contribution is the sum of its member leaf predictions divided by the total number of trees. Its line chart shows that contribution when all rule conditions hold and zero otherwise. Contributions from all consolidated rules sum to the forest mean fitted value at each observation. Its bar height is the active contribution multiplied by the fraction of aligned observations matching the rule. All bars in rules_bar_chart, including the Other bars, sum to the mean fitted prediction.
Labels such as R1 identify rules in the full consolidated table. Predictor charts shorten the displayed bounds; the next slide gives full conditions and exact thresholds for the displayed rules. A multivariate rule appears on each predictor chart whose predictor it constrains. These charts show the full conditional rule contribution, so contributions must not be summed across predictor charts. Remaining contributions are reported in subtitles rather than Other bars.
regimes groups nearby split thresholds within 2.5% of a predictor's observed range around a running weighted center. Labels such as G1 identify clusters in the full regime list. Chart ranges describe clusters of split locations, not disjoint intervals of predictor values. Bars show the observation-weighted mean right-minus-left subtree prediction contrast. Positive means the higher side predicts a higher target within the tree's other conditions; negative means a lower target. Supporting-tree counts show how widely the split cluster appears in the forest; a tree may support several clusters.
u=DIFF(SERIES_SINCE(UNRATE,20000101)) p=LOGDIFF(SERIES_SINCE(PAYEMS,20000101)) c=LOGDIFF(SERIES_SINCE(CPIAUCSL,20000101)) i=LOGDIFF(SERIES_SINCE(INDPRO,20000101)) rf=RANDOM_FOREST(LIST(u,p,c,i),TREES:500,MAX_DEPTH:12,MIN_LEAF:5,MTRY:1,SEED:12345) EXTRACT(rf,summary) EXTRACT(rf,importance) EXTRACT(rf,slideshow)
EX(rf,equation) EX(rf,rules) EX(rf,consolidate_rules) EX(rf,rules_charts) EX(rf,rules_bar_chart) EX(rf,predictor_bar_charts) EX(rf,regimes) EX(rf,regimes_bar_chart)