A function to combine forecasts out-of-sample. Methods available include: uniform weights, median forecast, trimmed (winsorized) mean, n-best, ridge regression, lasso regression, elastic net, peLASSO, random forest, tree-based gradient boosting machine, and single-layer neural network. The function will take in a data frame of forecasts, observed values (named 'observed', when the method requires it), and the observation date (i.e. the foretasted date, named 'date'), while outputting a data frame with a date column and one column per combination method selected.

forecast_combine(
  Data,
  method = "unform",
  n.max = NULL,
  rolling.window = NA,
  trim = c(0.5, 0.95),
  burn.in = 1,
  parallel.dates = NULL
)

Arguments

Data

data.frame: data frame of forecasted values to combine, assumes 'date' and 'observed' columns, but `observed' is not necessary for all methods

method

string or vector: the method to use; 'uniform', 'median', 'trimmed.mean', 'n.best', 'peLasso', 'lasso', 'ridge', 'elastic', 'RF', 'GBM', 'NN'

n.max

int: maximum number of forecasts to select

rolling.window

int: size of rolling window to evaluate forecast error over, use entire period if NA

trim

numeric: a two element vector with the winsorizing bounds for the trimmed mean method; c(min, max)

burn.in

int: the number of periods to use in the first model estimation

parallel.dates

int: the number of cores available for parallel estimation

Value

data.frame with a date column and one column per forecast method selected

Examples

if (FALSE) { forecast_combine( forecasts, method = c('uniform','median','trimmed.mean', 'n.best','lasso','peLasso','RF'), burn.in = 5, n.max = 2)}