Predict cases for a single Rt sample forecasts
predict_cases.RdPredict 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
dateandcasesvariables- rts
A dataframe of containing two variables
rtanddatewithrtbeing numeric anddatebeing a date.- serial_interval
A numeric vector describing the probability distribution the serial interval. See
EpiNow::covid_serial_intervalfor an example of the format.- forecast_date
A character string date (format "yyyy-mm-dd") indicating the forecast date. Defaults to
NULLin which case it will be assumed that the forecast date is the last data present in thecasesdataframe- 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
rpoisif 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 166.
#> 2 2020-03-12 191.
#> 3 2020-03-13 219.
#> 4 2020-03-14 243.
#> 5 2020-03-15 274.
#> 6 2020-03-16 299.
#> 7 2020-03-17 324.