# Simulate infections using the renewal equation

Source:`R/simulate_infections.R`

`simulate_infections.Rd`

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()`

.

## Usage

```
simulate_infections(
estimates,
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",
pop = 0,
...
)
```

## Arguments

- estimates
deprecated; use

`forecast_infections()`

instead- R
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.- initial_infections
numeric; the initial number of infections.

- day_of_week_effect
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`

.- generation_time
A call to

`generation_time_opts()`

defining the generation time distribution used. For backwards compatibility a list of summary parameters can also be passed.- delays
A call to

`delay_opts()`

defining delay distributions and options. See the documentation of`delay_opts()`

and the examples below for details.- truncation
A call to

`trunc_opts()`

defining the truncation of observed data. Defaults to`trunc_opts()`

. See`estimate_truncation()`

for an approach to estimating truncation from data.- obs
A list of options as generated by

`obs_opts()`

defining the observation model. Defaults to`obs_opts()`

.- 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".

- pop
Integer, defaults to 0. Susceptible population initially present. Used to adjust Rt estimates when otherwise fixed based on the proportion of the population that is susceptible. When set to 0 no population adjustment is done.

- ...
deprecated; only included for backward compatibility

## Value

A data.table of simulated infections (variable `infections`

) and
reported cases (variable `reported_cases`

) by date.

## Details

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 previous function called `simulate_infections()`

that simulates from a
given model fit has been renamed `forecast_infections()`

. Using
`simulate_infections()`

with existing estimates is now deprecated. This
option will be removed in version 2.1.0.

## Examples

```
# \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_dist(example_generation_time)
),
delays = delay_opts(fix_dist(example_reporting_delay)),
obs = obs_opts(family = "poisson")
)
# }
```