RainbowStats Command Reference
BEST_REGRESSION
Search a collection of candidate explanatory variables and return the ordinary least-squares regression containing the N variables that provide the best in-sample fit.
Syntax
BEST_REGRESSION(DataSeriesList, N)| Argument | Description |
|---|---|
DataSeriesList |
A list of aligned series. The first series is the dependent variable; every remaining series is a candidate explanatory variable. |
N |
The exact number of explanatory variables to include in the returned model. |
The command returns a standard RainbowStats regression result, including coefficients, standard errors, test statistics, goodness-of-fit measures, and residual diagnostics.
How the search works
Internally, RainbowStats uses the VariableSearch class. This is an
exhaustive best-subset search: it evaluates every possible
combination of exactly N predictors rather than adding variables one at a time.
- Align the series to their common date range.
- Generate every combination of N candidate predictors.
- Reject combinations whose design matrix is singular.
- Keep the combination with the smallest residual sum of squares.
Each admissible combination is estimated by ordinary least squares with a
constant. The winning model is the one that minimizes
RSS = Σ(y − ŷ)². Because every candidate model contains the same
number of explanatory variables and uses the same observations, minimizing RSS
is equivalent to maximizing the in-sample R².
N is 3, the search returns the
best model containing exactly three explanatory variables. It does not stop at
one or two variables merely because a smaller model is more parsimonious.
Example
L=SAME_DATE_RANGE(LIST(UNRATE,DGS10,TCU,GDP,CORESTICKM159SFRBATL))
LD=LOGDIFF(L)
BEST_REGRESSION(LD,2)
BEST_COVID_REGRESSION(LD,2)
The series are first aligned to a common date range and then converted to log
differences. Because UNRATE is first in the list, its transformed
series is the dependent variable. RainbowStats examines every two-variable
combination drawn from DGS10, TCU, GDP, and
CORESTICKM159SFRBATL.
BEST_REGRESSION returns the best ordinary specification, while
BEST_COVID_REGRESSION repeats the exercise using the COVID-adjusted
regression. Running both makes it easy to see whether the pandemic period
materially changes the selected model or its estimated relationships.
With four candidates and two selected variables, each search considers
C(4,2) = 6 combinations. With 20 candidates and five selected
variables, it must estimate C(20,5) = 15,504 regressions.
COVID-adjusted search
BEST_COVID_REGRESSION(DataSeriesList, N)
Use BEST_COVID_REGRESSION when the sample includes the exceptional
pandemic disruption and an ordinary regression may treat that episode as if it
reflected the usual economic relationship. It accepts the same arguments and
returns the same style of regression output as BEST_REGRESSION.
Good practice
Prepare economically meaningful inputs
The command searches the series you provide; it does not decide whether levels, differences, growth rates, lags, or other transformations are economically appropriate. Prepare the candidate list before running the search.
Keep the candidate set focused
The number of models grows rapidly with the size of the candidate set. A focused list runs faster and makes the final model easier to interpret. The search count is:
number of models = C(P, N)
Here, P is the number of candidate explanatory variables and
N is the number selected.
Use the result as evidence, not automatic proof
A variable can improve in-sample fit without having a causal relationship with the dependent variable. Inspect coefficient signs, residuals, stability, timing, and the economic logic of the selected model.
- Do transform and align the inputs consistently.
- Do compare the chosen model with simpler specifications.
- Do test the result over other dates or an out-of-sample period.
- Do not interpret the selected variables as causal merely because they fit well.
- Do not use a very large candidate set without considering search time and data mining.
Implementation notes
- The dependent variable is always series 0 in the supplied list.
- The dependent variable is excluded from all candidate combinations.
- Singular combinations are skipped rather than estimated.
- The winning combination minimizes residual sum of squares.
- The final result is returned through the normal RainbowStats regression output.