Predict cases for a single Rt sample forecasts
predict_cases.Rd
Predict cases for a single Rt sample forecasts
Usage
predict_cases(
cases = NULL,
rts = NULL,
serial_interval = NULL,
forecast_date = NULL,
horizon = NULL,
rdist = NULL
)
Arguments
- cases
A dataframe containing
date
andcases
variables- rts
A dataframe of containing two variables
rt
anddate
withrt
being numeric anddate
being a date.- serial_interval
A numeric vector describing the probability distribution the serial interval. See
EpiNow::covid_serial_interval
for an example of the format.- forecast_date
A character string date (format "yyyy-mm-dd") indicating the forecast date. Defaults to
NULL
in which case it will be assumed that the forecast date is the last data present in thecases
dataframe- horizon
Numeric, the time horizon over which to predict.
- rdist
A function to be used to sample the number of cases. Must take two arguments with the first specfying the number of samples and the second the mean. Defaults to
rpois
if not supplied
Examples
forecast <- forecast_rt(EpiSoon::example_obs_rts[1:10, ],
model = function(...) {
EpiSoon::bsts_model(
model =
function(ss, y) {
bsts::AddSemilocalLinearTrend(ss, y = y)
}, ...
)
},
horizon = 7, samples = 1
)
purrr::map_dfr(1:100, ~ predict_cases(
cases = EpiSoon::example_obs_cases,
rts = forecast,
forecast_date = as.Date("2020-03-10"),
serial_interval = example_serial_interval
)) %>%
dplyr::group_by(date) %>%
dplyr::summarise(cases = mean(cases))
#> # A tibble: 7 × 2
#> date cases
#> <date> <dbl>
#> 1 2020-03-11 168.
#> 2 2020-03-12 201.
#> 3 2020-03-13 233.
#> 4 2020-03-14 272.
#> 5 2020-03-15 314.
#> 6 2020-03-16 363.
#> 7 2020-03-17 408.