View source: R/proposal_infection_history.R
infection_history_symmetric | R Documentation |
Performs a flipping/swapping infection history update step for a matrix of infection histories. 50/50 chance of performing a flip or a swap
infection_history_symmetric(
new_inf_hist,
sampled_indivs,
age_mask,
sample_mask,
proposal_inf_hist_distances,
n_infs,
rand_ns,
proposal_inf_hist_indiv_swap_ratio = 0.5
)
new_inf_hist |
a matrix of infection histories - rows for individuals, columns for infection epochs. Contents should be 1s and 0s |
sampled_indivs |
a vector of indices describing rows in the infection history matrix that should be updated |
age_mask |
a vector (one value for each individual) giving the first infection epoch that an individual could have been exposed in. That is, if an individual was born in the 7th epoch, their entry in age_mask would be 7. |
sample_mask |
a vector (one value for each individual) giving the last infection epoch that an individual could have been exposed in. |
proposal_inf_hist_distances |
when performing a move step, how far should two epochs be swapped? |
n_infs |
number of infection epochs to flip |
rand_ns |
pre-computed random numbers (0-1) for each individual, deciding whether to do a flip or swap |
proposal_inf_hist_indiv_swap_ratio |
threshold for deciding if swap or add/remove step |
a matrix of infection histories matching the input new_inf_hist
Other proposals:
inf_hist_swap_phi()
,
inf_hist_swap()
,
mvr_proposal()
,
univ_proposal()
data(example_inf_hist)
data(example_antibody_data)
data(example_antigenic_map)
times <- example_antigenic_map$inf_times
ages <- unique(example_antibody_data[,c("birth","individual")])
## Create age and strain mask
age_mask <- create_age_mask(ages$birth, times)
sample_mask <- create_sample_mask(example_antibody_data, times)
## Index of individuals to be resampled
indivs <- 1:nrow(example_inf_hist)
n_indiv <- length(indivs)
## Parameters controlling proposal sizes for each individual
proposal_inf_hist_distances <- rep(3, n_indiv)
n_infs <- rep(10, n_indiv)
## Pre-compute random numbers
rand_ns <- runif(n_indiv)
new_inf_hist <- infection_history_symmetric(example_inf_hist, indivs,age_mask ,sample_mask, proposal_inf_hist_distances, n_infs, rand_ns, 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.