Generates a new infection history matrix and corresponding individual likelihoods, using a gibbs sampler from the infection history prior. See inf_hist_prop_prior_v3, as inputs are very similar.

inf_hist_prop_prior_v2_and_v4(
  theta,
  infection_history_mat,
  old_probs_1,
  sampled_indivs,
  n_years_samp_vec,
  age_mask,
  strain_mask,
  n_alive,
  n_infections,
  n_infected_group,
  prior_lookup,
  proposal_inf_hist_indiv_swap_ratio,
  swap_distance,
  propose_from_prior,
  alpha,
  beta,
  circulation_times,
  circulation_times_indices,
  sample_times,
  rows_per_indiv_in_samples,
  cum_nrows_per_individual_in_data,
  cum_nrows_per_individual_in_repeat_data,
  nrows_per_blood_sample,
  group_id_vec,
  measurement_strain_indices,
  antigenic_map_long,
  antigenic_map_short,
  antigenic_distances,
  data,
  repeat_data,
  repeat_indices,
  titre_shifts,
  proposal_iter,
  accepted_iter,
  proposal_swap,
  accepted_swap,
  overall_swap_proposals,
  overall_add_proposals,
  time_sample_probs,
  mus,
  boosting_vec_indices,
  total_alive,
  temp = 1,
  solve_likelihood = TRUE
)

Arguments

theta

NumericVector, the named model parameters used to solve the model

infection_history_mat

IntegerMatrix the matrix of 1s and 0s corresponding to individual infection histories

old_probs_1

NumericVector, the current likelihoods for each individual

sampled_indivs

IntegerVector, indices of sampled individuals

n_years_samp_vec

int, for each individual, how many time periods to resample infections for?

age_mask

IntegerVector, length of the number of individuals, with indices specifying first time period that an individual can be infected (indexed from 1, such that a value of 1 allows an individual to be infected in any time period)

strain_mask

IntegerVector, length of the number of individuals, with indices specifying last time period that an individual can be infected (ie. last time a sample was taken)

n_alive

IntegerMatrix, number of columns is the number of time periods that an individual could be infected, giving the number of individual alive in each time period. Number of rows is the number of distinct groups.

n_infections

IntegerMatrix, the number of infections in each year (columns) for each group (rows)

n_infected_group

IntegerVector, the total number of infections across all times in each group

prior_lookup

NumericMatrix, the pre-computed lookup table for the beta prior on infection histories

proposal_inf_hist_indiv_swap_ratio

double, gives the proportion of proposals that will be swap steps (ie. swap contents of two cells in infection_history rather than adding/removing infections)

swap_distance

int, in a swap step, how many time steps either side of the chosen time period to swap with

alpha

double, alpha parameter for beta prior on infection probability

beta

double, beta parameter for beta prior on infection probability

circulation_times

NumericVector, the times that each strain circulated

circulation_times_indices

IntegerVector, indexing vector from 0:(number of strains-1)

sample_times

NumericVector, the vector of real times that samples were taken

rows_per_indiv_in_samples

IntegerVector, How many rows in titre data correspond to each individual, sample and repeat?

cum_nrows_per_individual_in_data

IntegerVector, How many rows in the titre data correspond to each individual?

cum_nrows_per_individual_in_repeat_data

IntegerVector, For the repeat data (ie. already calculated these titres), how many rows in the titre data correspond to each individual?

nrows_per_blood_sample

IntegerVector, Split the sample times and runs for each individual

group_id_vec

IntegerVector, vector with 1 entry per individual, giving the group ID of that individual

measurement_strain_indices

IntegerVector, For each titre measurement, corresponding entry in antigenic map

antigenic_map_long

NumericVector, the collapsed cross reactivity map for long term boosting, after multiplying by sigma1, see create_cross_reactivity_vector

antigenic_map_short

NumericVector, the collapsed cross reactivity map for short term boosting, after multiplying by sigma2, see create_cross_reactivity_vector

antigenic_distances

NumericVector matching the dimensions of antigenic_map_long and antigenic_map_short, but with the raw antigenic distances between strains

data

NumericVector, data for all individuals for the first instance of each calculated titre

repeat_data

NumericVector, the repeat titre data for all individuals (ie. do not solve the same titres twice)

repeat_indices

IntegerVector, which index in the main data vector does each entry in repeat_data correspond to ie. which calculated titre in predicted_titres should be used for each observation?

titre_shifts

NumericVector, if length matches the length of data, adds these as measurement shifts to the predicted titres. If lengths do not match, is not used.

proposal_iter

IntegerVector, vector with entry for each individual, storing the number of infection history add/remove proposals for each individual.

accepted_iter

IntegerVector, vector with entry for each individual, storing the number of accepted infection history add/remove proposals for each individual.

proposal_swap

IntegerVector, vector with entry for each individual, storing the number of proposed infection history swaps

accepted_swap

IntegerVector, vector with entry for each individual, storing the number of accepted infection history swaps

mus

NumericVector, if length is greater than one, assumes that strain-specific boosting is used rather than a single boosting parameter

boosting_vec_indices

IntegerVector, same length as circulation_times, giving the index in the vector mus that each entry should use as its boosting parameter.

total_alive

IntegerVector, giving the total number of potential infection events for each group. This only applies to prior version 4. If set to a vector of values -1, then this is ignored.

temp

double, temperature for parallel tempering MCMC

solve_likelihood

bool, if FALSE does not solve likelihood when calculating acceptance probability

Value

an R list with 6 entries: 1) the vector replacing old_probs_1, corresponding to the new likelihoods per individual; 2) the matrix of 1s and 0s corresponding to the new infection histories for all individuals; 3-6) the updated entries for proposal_iter, accepted_iter, proposal_swap and accepted_swap.

See also

Other infection_history_proposal: inf_hist_prop_prior_v3()