Run a specified number of simulations with identical parameters

scenario_sim(
  n,
  initial_cases,
  r0_community,
  r0_isolated,
  r0_asymptomatic,
  disp_community,
  disp_isolated,
  disp_asymptomatic,
  incubation_period,
  prop_presymptomatic,
  onset_to_isolation,
  prop_ascertain,
  prop_asymptomatic,
  cap_max_days,
  cap_cases,
  quarantine = FALSE
)

Arguments

n

a positive integer scalar: number of simulations to run

initial_cases

a nonnegative integer scalar: number of initial or starting cases which are all assumed to be missed.

r0_community

a positive numeric scalar: reproduction number for non-isolated cases (must be >0)

r0_isolated

a positive numeric scalar: reproduction number for isolated cases (must be >0)

r0_asymptomatic

a positive numeric scalar: reproduction number for sub-clinical non-isolated cases (must be >0)

disp_community

a positive numeric scalar: dispersion parameter for non-isolated cases (must be >0)

disp_isolated

a positive numeric scalar: dispersion parameter for isolated cases (must be >0)

disp_asymptomatic

a positive numeric scalar: dispersion parameter for sub-clincial non-isolated cases (must be >0)

incubation_period

a function: a random number generating function that samples from incubation period distribution, the function accepts a single integer argument specifying the number of times to sample the incubation period (i.e. length of the function output).

prop_presymptomatic

a numeric scalar probability (between 0 and 1 inclusive): proportion of transmission that occurs before symptom onset.

onset_to_isolation

a function: a random number generating function that accepts a single integer argument specifying the length of the function output.

prop_ascertain

a numeric scalar probability (between 0 and 1 inclusive): proportion of infectious contacts ascertained by contact tracing

prop_asymptomatic

a numeric scalar probability (between 0 and 1 inclusive): proportion of cases that are completely asymptomatic (subclinical)

cap_max_days

a positive integer scalar: stop the simulation when this many days is reached.

cap_cases

a positive integer scalar: number of cumulative cases at which the branching process (simulation) was terminated

quarantine

a logical scalar: whether quarantine is in effect, if TRUE then traced contacts are isolated before symptom onset; defaults to FALSE

Value

A data.table object returning the results for multiple simulations using the same set of parameters. The table has columns

  • week: The week in the simulation.

  • weekly_cases: The number of new cases that week.

  • cumulative: The cumulative cases.

  • effective_r0: The effective reproduction rate for the whole simulation

  • cases_per_gen: A list column with the cases per generation. This is repeated each row.

  • sim: Index column for which simulation.

Author

Joel Hellewell

Examples

res <- scenario_sim(
  n = 5,
  initial_cases = 5,
  cap_max_days = 365,
  cap_cases = 2000,
  r0_isolated = 0,
  r0_community = 2.5,
  disp_isolated = 1,
  disp_community = 0.16,
  prop_presymptomatic = 0.3,
  onset_to_isolation = \(x) rweibull(n = x, shape = 2.5, scale = 5),
  incubation_period = \(x) rweibull(n = x, shape = 2.32, scale = 6.49),
  prop_asymptomatic = 0,
  prop_ascertain = 0,
  quarantine = TRUE
)
res
#>        sim  week weekly_cases cumulative effective_r0
#>      <int> <num>        <num>      <num>        <num>
#>   1:     1     0            4          4     3.071364
#>   2:     1     1           14         18     3.071364
#>   3:     1     2           84        102     3.071364
#>   4:     1     3          341        443     3.071364
#>   5:     1     4          804       1247     3.071364
#>  ---                                                 
#> 261:     5    48            0       3720     2.031944
#> 262:     5    49            0       3720     2.031944
#> 263:     5    50            0       3720     2.031944
#> 264:     5    51            0       3720     2.031944
#> 265:     5    52            0       3720     2.031944
#>                      cases_per_gen
#>                             <list>
#>   1:   29, 103, 183, 423,1133,2617
#>   2:   29, 103, 183, 423,1133,2617
#>   3:   29, 103, 183, 423,1133,2617
#>   4:   29, 103, 183, 423,1133,2617
#>   5:   29, 103, 183, 423,1133,2617
#>  ---                              
#> 261:    13, 16, 52, 88,133,186,...
#> 262:    13, 16, 52, 88,133,186,...
#> 263:    13, 16, 52, 88,133,186,...
#> 264:    13, 16, 52, 88,133,186,...
#> 265:    13, 16, 52, 88,133,186,...