Negative binomial branching process model

run_sim(
  n,
  n_length,
  mean_si,
  sd_si,
  serial_fn = NULL,
  R0,
  k = 0.16,
  tf = 37,
  kept_times = NULL,
  max_potential_cases,
  delay_sample
)

Arguments

n

Numeric, number of initial cases

n_length

Numeric, the number of days in the initial seeding event

mean_si

Numeric, the mean of the serial interval

sd_si

Numeric, the sd of the serial interval

serial_fn

Function from which to sample the serial interval must accepted a number of samples argument followed by a mean and standard deviation. If missing defaults to a normal distribution.

R0

Numeric, the estimated reproduction number

k

Numeric, the dispersion of the negative binomial branching process

tf

Numeric, the end time of the branching process

kept_times

Numeric, a vector of timepoints to keep information on. Defaults to all time points

max_potential_cases

Numeric, the maximum number of cases

delay_sample

A function to sample from reporting delays

Value

A dataframe containing the simulation time and outbreak size

Examples

## Example run_sim(n = 1, n_length = 7, mean_si = 5, sd_si = 2, R0 = 2, k=0.16, tf=37, max_potential_cases= 100, delay_sample = function(x) {rnorm(x, 6, 1)})
#> time size #> 1 0 0 #> 2 1 0 #> 3 2 0 #> 4 3 0 #> 5 4 0 #> 6 5 0 #> 7 6 0 #> 8 7 0 #> 9 8 0 #> 10 9 1 #> 11 10 1 #> 12 11 1 #> 13 12 1 #> 14 13 1 #> 15 14 2 #> 16 15 3 #> 17 16 9 #> 18 17 13 #> 19 18 14 #> 20 19 22 #> 21 20 28 #> 22 21 41 #> 23 22 46 #> 24 23 57 #> 25 24 62 #> 26 25 66 #> 27 26 71 #> 28 27 76 #> 29 28 83 #> 30 29 88 #> 31 30 96 #> 32 31 102 #> 33 32 106 #> 34 33 108 #> 35 34 113 #> 36 35 118 #> 37 36 120 #> 38 37 123
## Code run_sim
#> function (n, n_length, mean_si, sd_si, serial_fn = NULL, R0, #> k = 0.16, tf = 37, kept_times = NULL, max_potential_cases, #> delay_sample) #> { #> if (is.null(kept_times)) { #> kept_times <- 0:tf #> } #> if (is.null(serial_fn)) { #> serial_fn <- stats::rnorm #> } #> t0 <- sample(seq(1, n_length), n, replace = TRUE) #> sim <- bpmodels::chain_sim(n, "nbinom", serial = function(x) { #> serial_fn(x, mean_si, sd_si) #> }, mu = R0, size = k, t0 = t0, tf = tf, infinite = max_potential_cases) #> sim$time <- sim$time + delay_sample(length(sim$time)) #> sim <- sim[sim$time < tf, ] #> size <- data.frame(time = kept_times, size = unlist(lapply(kept_times, #> function(x) { #> tmp <- sim[sim$time < x, ] #> nrow(tmp) #> }))) #> return(size) #> } #> <bytecode: 0x55a6b5ec23d0> #> <environment: namespace:WuhanSeedingVsTransmission>