Description Usage Arguments Details Value Examples
Predict from a fit_seir()
object, possibly with a future prediction. By default, the
projection uses the estimated f values (fraction of normal
contacts encountered for those physical distancing). The function also includes
functionality to specify a vector of fixed f values starting on a given
future date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
obj |
Output from |
forecast_days |
Number of projection days. |
f_fixed_start |
Optional day to start changing f. Must be set if
|
f_fixed |
An optional vector of fixed f values for the projection.
Should be length |
f_multi |
Multiplicative vector of f values. Same structure as |
f_multi_seg |
Which |
iter |
MCMC iterations to include. Defaults to all. |
return_states |
Logical for whether to return the ODE states. |
imported_cases |
Number of cases to import starting on first projection day. |
imported_window |
Number of days over which to distribute imported cases. |
parallel |
Use parallel processing via future and furrr? |
X |
An optional model matrix that acts additively on log expected cases. |
... |
Other arguments to pass to |
Set a future::plan()
and this function will operate in parallel
across MCMC iterations using future and furrr.
A data frame:
Day
Data-type column from the case data
Expected number of cases
Posterior predictive replicate observation
Posterior draw of phi, the NB2 dispersion parameter, if included
The MCMC iteration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | cases <- c(
0, 0, 1, 3, 1, 8, 0, 6, 5, 0, 7, 7, 18, 9, 22, 38, 53, 45, 40,
77, 76, 48, 67, 78, 42, 66, 67, 92, 16, 70, 43, 53, 55, 53, 29,
26, 37, 25, 45, 34, 40, 35
)
# Example fixed sample fractions:
s1 <- c(rep(0.1, 13), rep(0.2, length(cases) - 13))
# To use parallel processing with multiple chains:
# options(mc.cores = parallel::detectCores() / 2)
# Using the MAP estimate for speed in this example:
m <- fit_seir(
cases,
iter = 100,
i0_prior = c(log(8), 0.2),
samp_frac_fixed = s1,
fit_type = "optimizing"
)
print(m)
p <- project_seir(m)
p
obs_dat <- data.frame(day = seq_along(cases), value = cases)
library(magrittr) # for %>%
tidy_seir(p) %>% plot_projection(obs_dat = obs_dat)
tidy_seir(p) %>%
plot_residuals(obs_dat = obs_dat, obj = m)
# for parallel processing (optional)
# future::plan(future::multisession)
p <- project_seir(m,
forecast_days = 100,
f_fixed_start = 53,
f_fixed = c(rep(0.7, 60), rep(0.2, 30)),
iter = 1:25
)
p
tidy_seir(p) %>% plot_projection(obs_dat = obs_dat)
# fake example to show optional Rt colouring:
proj <- tidy_seir(p)
plot_projection(proj, obs_dat = obs_dat, Rt = rlnorm(nrow(proj)), col = "#00000050")
# Get threshold for increase:
# future::plan(future::multisession) # for parallel processing (optional)
# (only using 40 iterations for a fast example)
thresh <- get_threshold(m, iter = 1:40, show_plot = TRUE)
mean(thresh)
# Get doubling time (prevalence is declining in this example)
get_doubling_time(m, iter = 1:40, show_plot = TRUE)
states_with_Rt <- get_rt(m)
states_with_Rt
library(ggplot2)
ggplot(states_with_Rt, aes(time, Rt, group = .iteration)) +
geom_line(alpha = 0.5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.