View source: R/simulate_infections.R
| simulate_infections | R Documentation |
Simulations are done from given initial infections and, potentially
time-varying, reproduction numbers. Delays and parameters of the observation
model can be specified using the same options as in estimate_infections().
simulate_infections(
R,
initial_infections,
day_of_week_effect = NULL,
generation_time = generation_time_opts(),
delays = delay_opts(),
truncation = trunc_opts(),
obs = obs_opts(),
CrIs = c(0.2, 0.5, 0.9),
backend = "rstan",
seeding_time = NULL,
pop = Fixed(0),
pop_period = c("forecast", "all"),
pop_floor = 1,
growth_method = c("infections", "infectiousness")
)
R |
a data frame of reproduction numbers (column |
initial_infections |
numeric; the initial number of infections (i.e.
before |
day_of_week_effect |
either |
generation_time |
A call to |
delays |
A call to |
truncation |
A call to |
obs |
A list of options as generated by |
CrIs |
Numeric vector of credible intervals to calculate. |
backend |
Character string indicating the backend to use for fitting stan models. Supported arguments are "rstan" (default) or "cmdstanr". |
seeding_time |
Integer; the number of days before the first time point
of |
pop |
A |
pop_period |
Character string, defaulting to "forecast". Controls when susceptible population adjustment is applied. "forecast" only applies the adjustment to forecasts whilst "all" applies it to both data and forecasts. |
pop_floor |
Numeric. Minimum susceptible population used as a floor when adjusting for population depletion. This prevents numerical instability (division by zero) when the susceptible population approaches zero. Defaults to 1.0. Can be interpreted as representing a minimal ongoing import level. Note that if pop_floor > 0, cumulative infections can exceed the population size, though this effect is negligible when pop_floor is very small compared to the population size. |
growth_method |
Method used to compute growth rates from Rt. Options are "infections" (default) and "infectiousness". The option "infections" uses the classical approach, i.e. computing the log derivative on the number of new infections. The option "infectiousness" uses an alternative approach by Parag et al., which computes the log derivative of the infectiousness (i.e. the convolution of past infections with the generation time) and shifts it by the mean generation time. This can provide better stability and temporal matching with Rt. Note that, due to the temporal shift the "infectiousness" method results in undefined (NaN) growth rates for the most recent time points (equal to the mean generation time). |
In order to simulate, all parameters that are specified such as the mean and standard deviation of delays or observation scaling, must be fixed. Uncertain parameters are not allowed.
A data.table of simulated infections (variable infections) and
reported cases (variable reported_cases) by date.
R <- data.frame(
date = seq.Date(as.Date("2023-01-01"), length.out = 14, by = "day"),
R = c(rep(1.2, 7), rep(0.8, 7))
)
sim <- simulate_infections(
R = R,
initial_infections = 100,
generation_time = generation_time_opts(
fix_parameters(example_generation_time)
),
delays = delay_opts(fix_parameters(example_reporting_delay)),
obs = obs_opts(family = "poisson")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.