R/calculate_infection_history_stats.R
calculate_infection_history_statistics.RdFinds 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
)the infection-history chain returned by load_mcmc_chains, in long format
if not already discarded, discards rows with `samp_no <= burnin`
vector of possible exposure times, in the same order as the infection-history columns
data frame giving the number of people alive for each exposure time and population group. This is used to calculate attack rates.
optional data frame of known attack rates, with `j`, `population_group`, and `AR` columns
optional data frame assigning individuals to `population_group` values for group-specific summaries
optional matrix or data frame of known infection histories, with individuals in rows and possible exposure times in columns
if TRUE, also finds cumulative infection histories for each individual. This takes a while, so is left FALSE by default.
if TRUE, adds zero-valued entries for infection events that are absent from the sparse chain
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`.
Other infection_history_plots:
plot_antibody_data(),
plot_antibody_predictions(),
plot_cumulative_infection_histories(),
plot_estimated_antibody_model(),
plot_individual_number_infections(),
plot_infection_history_chains_indiv(),
plot_infection_history_chains_time(),
plot_infection_history_posteriors(),
plot_model_fits(),
plot_total_number_infections()
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)