Skip to contents

Simulate a single chain using a branching process while accounting for depletion of susceptibles.

Usage

chain_sim_susc(
  offspring = c("pois", "nbinom"),
  mn_offspring,
  disp_offspring,
  serial,
  t0 = 0,
  tf = Inf,
  pop,
  initial_immune = 0
)

Arguments

offspring

offspring distribution: a character string corresponding to the R distribution function. Currently only "pois" & "nbinom" are supported. Internally truncated distributions are used to avoid infecting more people than susceptibles available.

mn_offspring

the average number of secondary cases for each case

disp_offspring

the dispersion coefficient (var/mean) of the number of secondary cases. Ignored if offspring == "pois". Must be > 1.

serial

the serial interval. A function that takes one parameter (n), the number of serial intervals to randomly sample. Value must be >= 0.

t0

start time

tf

end time

pop

the population

initial_immune

the number of initial immunes in the population

Value

a data frame with columns time, id (a unique ID for each individual element of the chain), ancestor (the ID of the ancestor of each element), and generation.

Details

This function has a couple of key differences with chain_sim: it can only simulate one chain at a time, it can only handle implemented offspring distributions ("pois" and "nbinom"), it always tracks and returns a data frame containing the entire tree, the maximal length of chains is limited with pop instead of infinite.

Author

Flavio Finger

Examples

chain_sim_susc("pois", mn_offspring = 0.5, serial = function(x) 3, pop = 100)
#>   id ancestor generation time
#> 1  1       NA          1    0