A function to estimate univariate forecasts out-of-sample. Methods available include all forecast methods from the forecast package. The function will take in a data frame of the target variable, and a observation date column (named 'date'), while outputting a data frame with a date column and one column per forecast method selected.

forecast_univariate(
  Data,
  forecast.dates,
  methods,
  horizon,
  recursive = TRUE,
  rolling.window = NA,
  freq,
  outlier.clean = FALSE,
  outlier.variables = NULL,
  outlier.bounds = c(0.05, 0.95),
  outlier.trim = FALSE,
  outlier.cross_section = FALSE,
  impute.missing = FALSE,
  impute.method = "kalman",
  impute.variables = NULL,
  impute.verbose = FALSE,
  parallel.dates = NULL,
  return.models = FALSE,
  return.data = FALSE
)

Arguments

Data

data.frame: data frame of variable to forecast and a date column; may alternatively be a ts, xts, or zoo object to forecast

forecast.dates

date: dates forecasts are created

methods

string or vector: models to estimate forecasts

horizon

int: number of periods to forecast

recursive

boolean: use sequential one-step-ahead forecast if TRUE, use direct projections if FALSE

rolling.window

int: size of rolling window, NA if expanding window is used

freq

string: time series frequency; day, week, month, quarter, year

outlier.clean

boolean: if TRUE then clean outliers

outlier.variables

string: vector of variables to standardize, default is all but 'date' column

outlier.bounds

double: vector of winsorizing minimum and maximum bounds, c(min percentile, max percentile)

outlier.trim

boolean: if TRUE then replace outliers with NA instead of winsorizing bound

outlier.cross_section

boolean: if TRUE then remove outliers based on cross-section (row-wise) instead of historical data (column-wise)

impute.missing

boolean: if TRUE then impute missing values

impute.method

string: select which method to use from the imputeTS package; 'interpolation', 'kalman', 'locf', 'ma', 'mean', 'random', 'remove','replace', 'seadec', 'seasplit'

impute.variables

string: vector of variables to impute missing values, default is all numeric columns

impute.verbose

boolean: show start-up status of impute.missing.routine

parallel.dates

int: the number of cores available for parallel estimation

return.models

boolean: if TRUE then return list of models estimated each forecast.date

return.data

boolean: if True then return list of information.set for each forecast.date

Value

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

Examples

if (FALSE) { forecast_univariate( Data = data, forecast.dates = date.vector, method = c('naive','auto.arima', 'ets'), horizon = 1, recursive = FALSE, freq = 'month')}