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")
)A data.table of simulated infections (variable infections) and
reported cases (variable reported_cases) by date.
a data frame of reproduction numbers (column R) by date (column
date). Column R must be numeric and date must be in date format. If
not all days between the first and last day in the date are present,
it will be assumed that R stays the same until the next given date.
numeric; the initial number of infections (i.e.
before R applies). Note that results returned start the day after, i.e.
the initial number of infections is not reported again. See also
seeding_time
either NULL (no day of the week effect) or a
numerical vector of length specified in obs_opts() as week_length
(default: 7) if week_effect is set to TRUE. Each element of the vector
gives the weight given to reporting on this day (normalised to 1).
The default is NULL.
A call to gt_opts() (or its alias
generation_time_opts()) defining the generation time distribution used.
For backwards compatibility a list of summary parameters can also be passed.
A call to delay_opts() defining delay distributions and
options. See the documentation of delay_opts() and the examples below for
details.
A call to trunc_opts() defining the truncation of
the observed data. Defaults to trunc_opts(), i.e. no truncation. See the
estimate_truncation() help file for an approach to estimating this from
data where the dist list element returned by estimate_truncation() is
used as the truncation argument here, thereby propagating the uncertainty
in the estimate.
A list of options as generated by obs_opts() defining the
observation model. Defaults to obs_opts().
Deprecated; specify credible intervals when using summary() or
plot()
Character string indicating the backend to use for fitting stan models. Supported arguments are "rstan" (default) or "cmdstanr".
Integer; the number of days before the first time point
of R; default is NULL, in which case it is set to the maximum of the
generation time. The minimum is 1 , i.e. the first reproduction number
given applies on the day after the index cases given by
initial_infections. If the generation time is longer than 1 day on
average, a seeding time of 1 will always lead to an initial decline (as
there are no infections before the initial ones). Instead, if this is
greater than 1, an initial part of the epidemic (before the first value of
R given) of seeding_time days is assumed to have followed exponential
growth roughly in line with the growth rate implied by the first value of
R.
A <dist_spec> giving the initial susceptible population size.
Used to adjust Rt estimates based on the proportion of the population that
is susceptible. Defaults to Fixed(0) which means no population adjustment
is done. See also pop_floor for the numerical stability floor used when
population adjustment is enabled. When pop is specified, returned Rt
estimates are adjusted for susceptible depletion (accounting for population
immunity), and unadjusted Rt estimates are also provided in a separate
output variable R_unadjusted. Adjusted Rt represents the effective
reproduction number given the current susceptible population, whilst
unadjusted Rt represents the reproduction number that would occur in a fully
susceptible population.
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.
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.
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.
# \donttest{
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")
)
# }
Run the code above in your browser using DataLab