Plots and calculates summary statistics from the infection-history MCMC chain.

plot_infection_history_posteriors(
  inf_chain,
  possible_exposure_times,
  n_alive,
  known_ar = NULL,
  known_infection_history = NULL,
  burnin = 0,
  samples = 100,
  pad_chain = FALSE
)

Arguments

inf_chain

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

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

known_infection_history

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

burnin

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

samples

number of MCMC samples to use for the plots

pad_chain

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

Value

A list containing trace plots by time and individual, a plot of the number of infections per individual, and the posterior estimates returned by calculate_infection_history_statistics.

Examples

if (FALSE) { # \dontrun{
## Load in example data
data(example_inf_chain)
data(example_antigenic_map)
data(example_antibody_data)

possible_exposure_times <- example_antigenic_map$inf_times
## Setup known attack rates
n_alive <- get_n_alive(example_antibody_data, possible_exposure_times)
n_infs <- colSums(example_inf_hist)
known_ar <- n_infs/n_alive
known_ar <- data.frame("j"=possible_exposure_times,"AR"=known_ar,"population_group"=1)

## Setup known infection histories
known_inf_hist <- data.frame(example_inf_hist)
colnames(known_inf_hist) <- possible_exposure_times

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]
all_plots <- plot_infection_history_posteriors(example_inf_chain, possible_exposure_times, n_alive_group,
                                     known_ar=known_ar,known_infection_history = known_inf_hist,
                                     samples=100)
} # }