Finds the median, mean and 95

calculate_infection_history_statistics(
  inf_chain,
  burnin = 0,
  possible_exposure_times = NULL,
  n_alive = NULL,
  known_ar = NULL,
  group_ids = NULL,
  known_infection_history = NULL,
  solve_cumulative = FALSE,
  pad_chain = FALSE
)

Arguments

inf_chain

the infection-history chain returned by load_mcmc_chains, in long format

burnin

if not already discarded, discards rows with `samp_no <= burnin`

possible_exposure_times

vector of possible exposure times, in the same order as the infection-history columns

n_alive

data frame giving the number of people alive for each exposure time and population group. This is used to calculate attack rates.

known_ar

optional data frame of known attack rates, with `j`, `population_group`, and `AR` columns

group_ids

optional data frame assigning individuals to `population_group` values for group-specific summaries

known_infection_history

optional matrix or data frame of known infection histories, with individuals in rows and possible exposure times in columns

solve_cumulative

if TRUE, also finds cumulative infection histories for each individual. This takes a while, so is left FALSE by default.

pad_chain

if TRUE, adds zero-valued entries for infection events that are absent from the sparse chain

Value

A list with `by_year`, `by_indiv`, `by_year_cumu`, and `by_indiv_cumu` data frames containing posterior summaries. The cumulative individual result is `NULL` unless `solve_cumulative = TRUE`.

Examples

data(example_inf_chain)
data(example_antigenic_map)
data(example_antibody_data)
data(example_inf_hist)
example_antibody_data$population_group <- 1
possible_exposure_times <- example_antigenic_map$inf_times
## Find number alive in each time period
n_alive <- get_n_alive(example_antibody_data, possible_exposure_times)
## Get actual number of infections per time
n_infs <- colSums(example_inf_hist)
## Create data frame of true ARs
known_ar <- n_infs/n_alive
known_ar <- data.frame("j"=possible_exposure_times,"AR"=known_ar,"population_group"=1)
## Get true infection histories
known_inf_hist <- data.frame(example_inf_hist)
colnames(known_inf_hist) <- possible_exposure_times

## Need to get population_group specific n_alive and adjust to correct time frame 
n_alive_group <- get_n_alive_group(example_antibody_data, possible_exposure_times,melt_data = TRUE)
n_alive_group$j <- possible_exposure_times[n_alive_group$j]
results <- calculate_infection_history_statistics(example_inf_chain, 0, possible_exposure_times,
                                                  n_alive=n_alive_group, known_ar=known_ar,
                                                  known_infection_history=known_inf_hist,
                                                  pad_chain=TRUE)