Simulate secondary observations from primary observations
Source:R/simulate_secondary.R
simulate_secondary.Rd
Simulations are done from a given trajectory of primary observations by applying any given delays and observation parameters.
Usage
simulate_secondary(
primary,
day_of_week_effect = NULL,
secondary = secondary_opts(),
delays = delay_opts(),
truncation = trunc_opts(),
obs = obs_opts(),
CrIs = c(0.2, 0.5, 0.9),
backend = "rstan",
...
)
Arguments
- primary
a data frame of primary reports (column
primary
) by date (columndate
). Columnprimary
must be numeric anddate
must be in date format. it will be assumed thatprimary
is zero on the missing days.- day_of_week_effect
either
NULL
(no day of the week effect) or a numerical vector of length specified inobs_opts()
asweek_length
(default: 7) ifweek_effect
is set to TRUE. Each element of the vector gives the weight given to reporting on this day (normalised to 1). The default isNULL
.- secondary
A call to
secondary_opts()
or a list containing the following binary variables: cumulative, historic, primary_hist_additive, current, primary_current_additive. These parameters control the structure of the secondary model, seesecondary_opts()
for details.- delays
A call to
delay_opts()
defining delay distributions and options. See the documentation ofdelay_opts()
and the examples below for details.- truncation
A call to
trunc_opts()
defining the truncation of the observed data. Defaults totrunc_opts()
, i.e. no truncation. See theestimate_truncation()
help file for an approach to estimating this from data where thedist
list element returned byestimate_truncation()
is used as thetruncation
argument here, thereby propagating the uncertainty in the estimate.- obs
A list of options as generated by
obs_opts()
defining the observation model. Defaults toobs_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".
- ...
deprecated; only included for backward compatibility
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 function of the same name that was previously based on a reimplementation of that model in R with potentially time-varying scalings and delays is available as `convolve_and_scale()
Examples
# \donttest{
## load data.table to manipulate `example_confirmed` below
library(data.table)
cases <- as.data.table(example_confirmed)[, primary := confirm]
sim <- simulate_secondary(
cases,
delays = delay_opts(fix_parameters(example_reporting_delay)),
obs = obs_opts(family = "poisson")
)
# }