QUANTILE_RANDOM_FOREST

QUANTILE_RANDOM_FOREST extends the RainbowStats regression forest from conditional-mean prediction to estimation of a conditional distribution. It reports lower, median and upper conditional quantiles while retaining the ordinary forest diagnostics.

Syntax

QUANTILE_RANDOM_FOREST(LIST(Y,X1,X2,...),TREES:500,MAX_DEPTH:12,MIN_LEAF:5,MTRY:2,SEED:12345,LOWER:0.05,MEDIAN:0.50,UPPER:0.95)

Arguments

ArgumentDescriptionDefault
LIST(Y,X1,...)Y is the dependent series. X1...Xp are predictor series.Required
TREESNumber of bootstrap regression trees.500
MAX_DEPTHMaximum depth of each tree.12
MIN_LEAFMinimum observations allowed in a terminal leaf.5
MTRYNumber of randomly selected predictors considered at each split.max(1,p/3)
SEEDRandom seed.12345
LOWERLower conditional quantile, between 0 and 1.0.05
MEDIANMiddle conditional quantile.0.50
UPPERUpper conditional quantile, between 0 and 1.0.95

The quantiles must satisfy 0 < LOWER < MEDIAN < UPPER < 1.

Method

The operator grows the same bootstrap CART regression forest used by RANDOM_FOREST, but retains the training observations associated with terminal leaves. For a query observation, each tree identifies its terminal leaf. Observations sharing that leaf receive equal within-tree weight; weights are then aggregated across trees to form a conditional empirical distribution of Y. Requested quantiles are read from that weighted distribution.

Bootstrap multiplicity is retained: if an observation occurs more than once in a bootstrap leaf, its repeated membership contributes correspondingly to that tree's conditional distribution.

Extracts

Use EXTRACT(qrf,extract_name) or its shorthand EX(qrf,extract_name).

ExtractResult
summary / modelForest settings, requested quantiles and training/OOB diagnostics.
lower / q_lowerLower conditional-quantile series.
median / q50Middle conditional-quantile series (median with the default MEDIAN:0.50).
upper / q_upperUpper conditional-quantile series.
quantilesDataList containing lower, middle and upper conditional-quantile series.
fitted / predictedForest conditional-mean fitted-value series.
residualsActual minus mean fitted series.
oob / oob_predictionOut-of-bag mean prediction series.
importanceNamed and sorted OOB permutation-importance table.
importance_valuesRaw OOB permutation-importance array in original predictor order.
benchmarkComparison of forest and OLS fit and validation diagnostics.
ols_summary / ols_inferenceOLS benchmark coefficients and inference table.
ols_fittedOLS benchmark fitted-value series.
ols_oos / ols_loocvOLS leave-one-out prediction series.
ols / ols_regression / regressionOLS benchmark regression operator, or its inference table when the operator is unavailable.
equationHTML explanation of the exact forest mean equation: the average of tree predictions expressed as terminal-region indicators.
rulesOriginal table of up to 50 terminal leaf rules, ranked by influence; rules from different trees can overlap or repeat.
consolidate_rules / consolidated_rulesFull 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_chartsSlideshow containing the consolidated rule table and one contribution line chart per nonzero rule on the aligned observations.
rules_bar_chart / bar_chart / bar_chartsSingle 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_chartsSlideshow 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.
regimesTable 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_chartsSlideshow 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_fittedActual-versus-mean-fitted chart.
slideshowModel slideshow with diagnostics and the original rule/regime tables and requested quantiles. Use the chart extracts separately for contribution and regime slideshows.

Interpreting rules and regime charts

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.

Chart interpretation: rule bars decompose mean fitted predictions; their sign does not indicate the direction of a predictor's effect. Regime bars summarize conditional prediction contrasts and are not additive contributions. Neither chart establishes causal effects or out-of-sample performance. Matching-observation counts refer to unique aligned rows; bootstrap counts include repeated observations.

Quantile forest: equation, rule and regime extracts explain the conditional-mean forest. They do not decompose the lower, middle or upper quantiles. Use lower, median, upper and quantiles for conditional-quantile estimates.

Example

u=DIFF(SERIES_SINCE(UNRATE,20000101))
p=LOGDIFF(SERIES_SINCE(PAYEMS,20000101))
c=LOGDIFF(SERIES_SINCE(CPIAUCSL,20000101))
i=LOGDIFF(SERIES_SINCE(INDPRO,20000101))
qrf=QUANTILE_RANDOM_FOREST(LIST(u,p,c,i),TREES:500,MAX_DEPTH:12,MIN_LEAF:5,MTRY:1,SEED:12345,LOWER:0.05,MEDIAN:0.50,UPPER:0.95)
EXTRACT(qrf,summary)
EXTRACT(qrf,quantiles)
EXTRACT(qrf,importance)
EXTRACT(qrf,slideshow)

Why use quantiles?

An ordinary random forest estimates the conditional mean. A quantile forest also describes how the conditional distribution changes. A widening Q05-Q95 range indicates increased conditional uncertainty or tail risk even when the conditional mean changes little. This is useful for financial stress, market-liquidity and other applications where the tails of the distribution are economically important.

Caution: the displayed quantile series are conditional estimates from the fitted forest, not confidence intervals for the mean and not guaranteed future bounds.

Rule and regime examples

EX(qrf,equation)
EX(qrf,rules)
EX(qrf,consolidate_rules)
EX(qrf,rules_charts)
EX(qrf,rules_bar_chart)
EX(qrf,predictor_bar_charts)
EX(qrf,regimes)
EX(qrf,regimes_bar_chart)