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,
  strain_mask,
  proposal_inf_hist_distances,
  n_infs,
  rand_ns,
  proposal_inf_hist_indiv_swap_ratio = 0.5
)

Arguments

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.

strain_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

Value

a matrix of infection histories matching the input new_inf_hist

See also

Examples

data(example_inf_hist) data(example_titre_dat) data(example_antigenic_map) times <- example_antigenic_map$inf_times ages <- unique(example_titre_dat[,c("DOB","individual")]) ## Create age and strain mask age_mask <- create_age_mask(ages$DOB, times) strain_mask <- create_strain_mask(example_titre_dat, times)
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
## 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 ,strain_mask, proposal_inf_hist_distances, n_infs, rand_ns, 0.5)
#> Error in age_mask[indiv]:strain_mask[indiv]: NA/NaN argument