[Experimental] Provides optional tools for forecasting cases and Rt estimates using the timeseries methods (via the EpiSoon package). It requires the Episoon package. Installation instructions for the EpiSoon package are available here.

forecast_infections(
  infections,
  rts,
  gt_mean,
  gt_sd,
  gt_max = 30,
  ensemble_type = "mean",
  forecast_model,
  CrIs = c(0.2, 0.5, 0.9),
  horizon = 14,
  samples = 1000
)

Arguments

infections

A data frame of cases by date of infection containing the following variables: date, mean, sd

rts

A data frame of Rt estimates by date of infection containing the following variables: date, mean, sd

gt_mean

Numeric, the mean of the gamma distributed generation time.

gt_sd

Numeric, the standard deviation of the gamma distributed generation time.

gt_max

Numeric, the maximum allowed value of the gamma distributed generation time.

ensemble_type

Character string indicating the type of ensemble to use. By default this is an unweighted ensemble ("mean") with no other types currently supported.

forecast_model

An uninitialised forecast model function to be passed to EpiSoon::forecast_rt. Used for forecasting future Rt and case co An example of the required structure is: function(ss, y){bsts::AddSemilocalLinearTrend(ss, y = y)}.

CrIs

Numeric vector of credible intervals to calculate.

horizon

Numeric, defaults to 14. The horizon over which to forecast Rts and cases.

samples

Numeric, the number of forecast samples to take.

Value

A list of data.tables. The first entry ("samples") contains raw forecast samples and the second entry ("summarised") contains summarised forecasts.

Examples

# \donttest{
if (requireNamespace("EpiSoon")) {
  if (requireNamespace("forecastHybrid")) {
    # example case data
    reported_cases <- example_confirmed[1:40]

    generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani")
    incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer")
    reporting_delay <- estimate_delay(rlnorm(100, log(6), 1), max_value = 15)

    # estimate Rt and infections from data
    out <- estimate_infections(reported_cases,
      generation_time = generation_time,
      delays = delay_opts(incubation_period, reporting_delay),
      rt = rt_opts(prior = list(mean = 2, sd = 0.1))
    )

    # forecast Rt and infections from estimates
    forecast <- forecast_infections(
      infections = out$summarised[variable == "infections"],
      rts = out$summarised[variable == "R"],
      gt_mean = out$summarised[variable == "gt_mean"]$mean,
      gt_sd = out$summarised[variable == "gt_sd"]$mean,
      gt_max = 30,
      forecast_model = function(y, ...) {
        EpiSoon::forecastHybrid_model(
          y = y[max(1, length(y) - 21):length(y)],
          model_params = list(models = "aefz", weights = "equal"),
          forecast_params = list(PI.combination = "mean"), ...
        )
      },
      horizon = 14,
      samples = 1000
    )

    forecast$summarised
  }
}
#> Loading required namespace: EpiSoon
# }