Given infection probabilities and potential infection times, simulates infections for each individual in `demographics`. Infections are only added while an individual is alive and within their observation period.

simulate_infection_histories(
  p_inf,
  possible_exposure_times = 1:ncol(p_inf),
  demographics
)

Arguments

p_inf

a vector or data frame of attack rates (infection probabilities) for each possible exposure time and population group

possible_exposure_times

the vector of possible infection times

demographics

data frame giving `individual`, `birth`, and `population_group` for each individual. `last_sample` and time-varying demographic values can also be supplied.

Value

A list containing an infection-history matrix and a data frame of empirical attack rates for each population group and exposure time.

See also

Other simulation_functions: simulate_attack_rates(), simulate_data()

Examples

possible_exposure_times <- seq_len(25)
p_inf <- simulate_attack_rates(possible_exposure_times,n_groups=2)
n_indiv <- 100
demographics <- data.frame(individual = 1:n_indiv,birth=sample(1:5,n_indiv,replace=TRUE),population_group=c(rep(1,n_indiv/2),rep(2,n_indiv/2)))
inf_hist <- simulate_infection_histories(p_inf, possible_exposure_times, demographics)