Skip to content

Commit

Permalink
Big update to simulation code to use create_posterior_func directly r…
Browse files Browse the repository at this point in the history
…ather than separate functions

Also should work with simulating stratifications and multiple biomarker groups

DOES NOT yet work with measurement offsets, as this doesn't work for multiple biomarker groups (yet)
  • Loading branch information
jameshay218 committed May 12, 2024
1 parent 9ac31b7 commit 03f8e7d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 325 deletions.
11 changes: 8 additions & 3 deletions R/plots_other.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ plot_antibody_data <- function(antibody_data,
} else {
antibody_data$biomarker_group <- 1
}
p1 <- ggplot(antibody_data[antibody_data$individual %in% samps, ]) +

## For birth dates
DOBs <- unique(antibody_data[antibody_data$individual %in% samps, c("individual","birth")])

p1 <- ggplot(antibody_data[antibody_data$individual %in% samps, ]) +
geom_vline(data = DOBs, aes(xintercept = birth,linetype="Birth"),col = "purple") +
geom_rect(data=measurement_ranges,aes(ymin=max_measurement,ymax=max_measurement+1),xmin=0,xmax=max_x,fill="grey70") +
geom_rect(data=measurement_ranges,aes(ymin=min_measurement-1,ymax=min_measurement),xmin=0,xmax=max_x,fill="grey70")

Expand Down Expand Up @@ -76,7 +81,7 @@ plot_antibody_data <- function(antibody_data,

p1 <- p1 + geom_vline(data = melted_inf_hist[melted_inf_hist$individual %in% samps, ],
aes(xintercept = variable,linetype="Known infection time"),
col = "orange",linetype="dashed")
col = "orange")
}
breaks <- seq(floor(min(measurement_ranges$min_measurement)), ceiling(max(measurement_ranges$max_measurement)),by=2)
p1 <- p1 +
Expand All @@ -95,7 +100,7 @@ plot_antibody_data <- function(antibody_data,
coord_cartesian(xlim=time_range) +
scale_y_continuous(expand=c(0,0),breaks=breaks) +
scale_color_viridis_d(name="Biomarker ID") +
scale_linetype_manual(name="",values=c("Known infection time"="dashed"))
scale_linetype_manual(name="",values=c("Known infection time"="dashed","Birth"="solid"))
return(p1)
}

Expand Down
14 changes: 7 additions & 7 deletions R/posteriors.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ create_posterior_func <- function(par_tab,
antigenic_map_long <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))
antigenic_map_short <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))

cr_longs <- as.matrix(theta[,which(par_names_theta_all=="cr_long")])
cr_shorts <- as.matrix(theta[,which(par_names_theta_all=="cr_short")])
cr_longs <- matrix(theta[,which(par_names_theta_all=="cr_long")],nrow=length(unique_groups))
cr_shorts <- matrix(theta[,which(par_names_theta_all=="cr_short")],nrow=length(unique_groups))
for(group in unique_groups){
for(biomarker_group in unique_biomarker_groups){
antigenic_map_long[,biomarker_group,group] <- create_cross_reactivity_vector(antigenic_map_melted[[biomarker_group]], cr_longs[group,biomarker_group])
Expand Down Expand Up @@ -467,9 +467,9 @@ create_posterior_func <- function(par_tab,
antigenic_map_long <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))
antigenic_map_short <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))

cr_longs <- as.matrix(theta[,which(par_names_theta_all=="cr_long")])
cr_shorts <- as.matrix(theta[,which(par_names_theta_all=="cr_short")])
cr_longs <- matrix(theta[,which(par_names_theta_all=="cr_long")],nrow=length(unique_groups))
cr_shorts <- matrix(theta[,which(par_names_theta_all=="cr_short")],nrow=length(unique_groups))

for(group in unique_groups){
for(biomarker_group in unique_biomarker_groups){
antigenic_map_long[,biomarker_group,group] <- create_cross_reactivity_vector(antigenic_map_melted[[biomarker_group]], cr_longs[group,biomarker_group])
Expand Down Expand Up @@ -561,8 +561,8 @@ create_posterior_func <- function(par_tab,
antigenic_map_long <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))
antigenic_map_short <- array(dim=c(length(possible_biomarker_ids)^2,n_biomarker_groups,n_demographic_groups))

cr_longs <- as.matrix(theta[,which(par_names_theta_all=="cr_long")])
cr_shorts <- as.matrix(theta[,which(par_names_theta_all=="cr_short")])
cr_longs <- matrix(theta[,which(par_names_theta_all=="cr_long")],nrow=length(unique_groups))
cr_shorts <- matrix(theta[,which(par_names_theta_all=="cr_short")],nrow=length(unique_groups))
for(group in unique_groups){
for(biomarker_group in unique_biomarker_groups){
antigenic_map_long[,biomarker_group,group] <- create_cross_reactivity_vector(antigenic_map_melted[[biomarker_group]], cr_longs[group,biomarker_group])
Expand Down
Loading

0 comments on commit 03f8e7d

Please sign in to comment.