This function performs a two-stage stacked forecast using ridge regression. In the first stage, it generates base forecasts from the training portion of the time series. In the second stage, these forecasts are used as external regressors to produce the final forecast on the testing set.

stackridge2f(y, h = 5L, split_fraction = 0.5, ...)

Arguments

y

A multivariate time series object.

h

Integer. Forecast horizon for the second-stage (final) forecast. Defaults to 5.

split_fraction

Numeric between 0 and 1. Fraction of the time series used for training. The rest is used for testing and generating stacking features. Defaults to 0.5.

...

Additional arguments passed to ahead::ridge2f in both stages (e.g., lags, lambda_1, lambda_2, nb_hidden, etc.).

Value

An object returned by ahead::ridge2f for the stacked forecast, typically a list including mean and prediction intervals.

Details

The function works as follows:

  1. Split the time series into training and testing sets according to split_fraction.

  2. Generate base forecasts from the training set using ahead::ridge2f

  3. Use these base forecasts as external regressors (xreg) to predict the testing set with a second ahead::ridge2f model.

This approach allows stacking of forecasts to potentially improve accuracy by leveraging the predictions of multiple first-stage models.

For multivariate base learners (e.g., tslm with multiple dependent variables), the function automatically extracts forecasts from each series and combines them into the feature matrix.

Examples

if (FALSE) { # \dontrun{

# Univariate example with default ridge2f base learner
result1 <- stackridge2f(fpp2::insurance, h = 10, 
                        split_fraction = 0.5)
} # }