Skip to content

Commit

Permalink
Fixed incorrect time indexing for fixed_inf_hists
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshay218 committed May 17, 2024
1 parent e1d62a9 commit 7aa296a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,20 @@ serosolver <- function(par_tab,

## Mask infection times we shouldn't sample
inf_hist_masks <- matrix(1, nrow=n_indiv,ncol=length(possible_exposure_times))
fixed_inf_hists1 <- fixed_inf_hists
if(!is.null(fixed_inf_hists)){
fixed_inf_hists1$time <- match(fixed_inf_hists1$time, possible_exposure_times)
}
for(iii in 1:n_indiv){
inf_hist_masks[iii,1:age_mask[iii]] <- 0
inf_hist_masks[iii,sample_mask[iii]:ncol(inf_hist_masks)] <- 0
if(!is.null(fixed_inf_hists)){
if(iii %in% fixed_inf_hists$individual){
mask_indices <- fixed_inf_hists[fixed_inf_hists$individual == iii, "time"]
if(iii %in% fixed_inf_hists1$individual){
mask_indices <- fixed_inf_hists1[fixed_inf_hists1$individual == iii, "time"]
inf_hist_masks[iii, mask_indices] <- 0
}
}
}

## Add stratifying variables to antibody_data and demographics
## Setup data vectors and extract
tmp <- get_demographic_groups(par_tab,antibody_data,demographics, NULL)
Expand Down Expand Up @@ -402,8 +405,8 @@ serosolver <- function(par_tab,

## Fix infection states if specified
if(!is.null(fixed_inf_hists)){
for(iii in 1:nrow(fixed_inf_hists)){
infection_histories[fixed_inf_hists$individual[iii], fixed_inf_hists$time[iii]] <- fixed_inf_hists$value[iii]
for(iii in 1:nrow(fixed_inf_hists1)){
infection_histories[fixed_inf_hists1$individual[iii], fixed_inf_hists1$time[iii]] <- fixed_inf_hists1$value[iii]
}
}

Expand Down
1 change: 1 addition & 0 deletions R/posteriors.R
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ create_posterior_func <- function(par_tab,
## Mask known infection states from estimation
if(!is.null(fixed_inf_hists)) {
if(verbose) message(cat("Fixing infection states given by fixed_inf_hists\n"))
fixed_inf_hists$time <- match(fixed_inf_hists$time, possible_exposure_times)
indiv_possible_exposure_times <- indiv_possible_exposure_times %>%
left_join(fixed_inf_hists %>% rename(t_index=time) %>% mutate(t_index =t_index - 1),
by=c("individual","t_index"))
Expand Down

0 comments on commit 7aa296a

Please sign in to comment.