Skip to contents

Plot a Forecast

Usage

plot_forecast(
  forecast = NULL,
  observations = NULL,
  horizon_cutoff = NULL,
  obs_cutoff_at_forecast = TRUE
)

Arguments

forecast

A dataframe with summarised forecasts as produced by summarise_forecast or summarise_case_forecast .

observations

A dataframe of observations containing the following variables:

  • either rt or cases

  • and date.

horizon_cutoff

Numeric, defaults to NULL. Forecast horizon to plot up to.

obs_cutoff_at_forecast

Logical defaults to TRUE. Should observations only be shown up to the date of the forecast.

Value

A ggplot2 object

Examples

if (FALSE) {
## Forecast an Rt sample
samples <- forecast_rt(EpiSoon::example_obs_rts[1:10, ],
  model = function(...) {
    EpiSoon::bsts_model(
      model =
        function(ss, y) {
          bsts::AddSemilocalLinearTrend(ss, y = y)
        }, ...
    )
  },
  horizon = 21, samples = 10
)

## Summarise forecast
summarised_forecast <- summarise_forecast(samples)

## Plot forecast_cases
plot_forecast(summarised_forecast, EpiSoon::example_obs_rts)

## Forecast a case sample
pred_cases <- forecast_cases(EpiSoon::example_obs_cases, samples,
  serial_interval = EpiSoon::example_serial_interval
)

summarised_case_forecast <- summarise_case_forecast(pred_cases)

plot_forecast(summarised_case_forecast, EpiSoon::example_obs_cases)
}