This function performs hindcasting over a specified segment of the time series. The hindcasting is intended to simulate the use of a forecasting method in practice. For a given time series of length m, suppose that the last n points are used for forecast evaluation, then the procedure is:

  1. fit the model to the first m - n time points

  2. make a 1-step ahead forecast

  3. add the next observation to the training data, refit the model, and make another forecast

  4. repeat for the n forecasts

The value of n is determined in one of several ways, depending on the hindcast_selection argument:

last_n

make hindcasts for the last last_n points of the time series

pred_frac

make hindcasts for the last pred_frac fraction of the time series

pred_start

make hindcasts starting with the pred_start point of the time series

hindcast(fun, timeseries, hindcast_method = c("pred_frac", "last_n",
  "pred_start"), pred_frac = 1/3, last_n = 5, pred_start = 31, ...)

Arguments

fun

a function for doing the forecasting. It should have arguments:

training

the data for training the model

observed

optional observation of the next point

...

any optional arguments

and should return a data.frame with at least the predicted forecast (in a column named predicted). Other columns are optional, and may be specific to the forecasting method.

timeseries

the time series to forecast

hindcast_method

the method for determining # of hindcasts

pred_frac

the fraction of points at the end of the time series to forecast

last_n

the number of points at the end of the time series to forecast

pred_start

the index of the point of the time series at which to begin forecasts

...

arguments to pass to fun

Value

a data.frame of the observed and predicted values, with any other remaining values returned by fun. If any error occurs, then NA values for the observed and predicted