Skip to contents

Provides a wrapper for different EpiSoon model wrappers and generates a mixture model of these models based on the (Continuous) Rank Probability Score

A list of models is supplied. These models are fit to the data up until a period of observations of size weighting_period. Forecasts are generated from all the models for all time points in the weighting_period. Predictive samples generated by the individual models are then used to create model weights in an ensemble based on CRPS. All models are then refitted for the entire timeseries and predictions are generated from these models. Draws from the individual model predictive samples are then used to generate a mixture model with the weights obtained in the previous step.

The weights are computed using crps_weights from the package stackr to minimise CRPS. The function mixture_from_samples from the same package is used to draw samples from the individual models to form the mixture models.

Usage

stackr_model(
  y = NULL,
  models = NULL,
  samples = NULL,
  horizon = NULL,
  weighting_period = 5,
  verbose = TRUE
)

Arguments

y

Numeric vector of time points to forecast

models

A list of models. Models must be analogous to the form function(...){EpiSoon::fable_model(model = , ...)} or function(...){EpiSoon::bsts_model(model = , ...)}.

samples

Numeric, number of samples to take.

horizon

Numeric, the time horizon over which to predict.

weighting_period

The number of most recent timepoints to hold out to generate the weights for the mixture model

verbose

if TRUE, gives a message if number of observations is too small to do crps weighting

Value

A dataframe of predictions (with columns representing the time horizon and rows representing samples).

Examples

if (FALSE) {

# make list with models
models <- list(
  "ARIMA" = function(...) {
    EpiSoon::fable_model(model = fable::ARIMA(y), ...)
  },
  "ETS" = function(...) {
    EpiSoon::fable_model(model = fable::ETS(y), ...)
  },
  "Drift" = function(...) {
    EpiSoon::fable_model(model = fable::RW(y ~ drift()), ...)
  }
)

# make forecast on its own
forecast <- stackr_model(
  y = EpiSoon::example_obs_rts[1:10, ]$rt,
  models = models,
  samples = 10,
  horizon = 7,
  weighting_period = 5
)


# together with forecast_rt
fc_rt <- forecast_rt(EpiSoon::example_obs_rts[1:10, ],
  model = function(...) {
    stackr_model(
      models = models,
      weighting_period = 5,
      ...
    )
  },
  samples = 10,
  horizon = 7
)

forecast_eval <- evaluate_model(EpiSoon::example_obs_rts,
  EpiSoon::example_obs_cases,
  model = function(...) {
    stackr_model(
      models = models,
      weighting_period = 5,
      ...
    )
  },
  horizon = 7, samples = 10,
  serial_interval = example_serial_interval,
  min_points = 10
)

plot_forecast_evaluation(forecast_eval$forecast_rts,
  EpiSoon::example_obs_rts,
  horizon_to_plot = 7
)
}