@@ -58,7 +58,7 @@ get_titre_predictions <- function(chain, infection_histories, titre_dat,
5858 mu_indices = NULL ,
5959 measurement_indices_by_time = NULL ,
6060 for_res_plot = FALSE , expand_titredat = FALSE ,
61- titre_before_infection = FALSE , titres_for_regression = FALSE ){
61+ titre_before_infection = FALSE , titres_for_regression = FALSE , data_type = 1 ){
6262 # # Need to align the iterations of the two MCMC chains
6363 # # and choose some random samples
6464 samps <- intersect(unique(infection_histories $ sampno ), unique(chain $ sampno ))
@@ -124,7 +124,7 @@ get_titre_predictions <- function(chain, infection_histories, titre_dat,
124124 tmp_inf_hist <- infection_histories [infection_histories $ sampno == index , ]
125125 tmp_inf_hist <- as.matrix(Matrix :: sparseMatrix(i = tmp_inf_hist $ i , j = tmp_inf_hist $ j , x = tmp_inf_hist $ x , dims = c(n_indiv , nstrain )))
126126 predicted_titres [, i ] <- model_func(pars , tmp_inf_hist )
127- observed_predicted_titres [,i ] <- add_noise(predicted_titres [,i ], pars , NULL , NULL )
127+ observed_predicted_titres [,i ] <- add_noise(predicted_titres [,i ], pars , NULL , NULL , data_type )
128128 inf_hist_all [[i ]] <- tmp_inf_hist
129129 # # Get residuals between observations and predictions
130130 residuals [, i ] <- titre_dat1 $ titre - floor(predicted_titres [, i ])
@@ -227,15 +227,16 @@ plot_infection_histories_long <- function(chain, infection_histories, titre_dat,
227227 strain_isolation_times = NULL , par_tab ,
228228 nsamp = 100 ,
229229 mu_indices = NULL ,
230- measurement_indices_by_time = NULL ) {
230+ measurement_indices_by_time = NULL ,
231+ data_type = 1 ) {
231232 individuals <- individuals [order(individuals )]
232233 # # Generate titre predictions
233234 titre_preds <- get_titre_predictions(
234235 chain , infection_histories , titre_dat , individuals ,
235236 antigenic_map , strain_isolation_times ,
236237 par_tab , nsamp , FALSE , mu_indices ,
237238 measurement_indices_by_time ,
238- expand_titredat = TRUE
239+ expand_titredat = TRUE , data_type = data_type
239240 )
240241
241242 # # Use these titre predictions and summary statistics on infection histories
@@ -307,17 +308,18 @@ plot_infection_histories <- function(chain, infection_histories, titre_dat,
307308 nsamp = 100 ,
308309 mu_indices = NULL ,
309310 measurement_indices_by_time = NULL ,
310- p_ncol = length(individuals )/ 2 ) {
311+ p_ncol = length(individuals )/ 2 ,
312+ data_type = 1 ) {
311313 individuals <- individuals [order(individuals )]
312314 # # Generate titre predictions
313315 titre_preds <- get_titre_predictions(
314316 chain , infection_histories , titre_dat , individuals ,
315317 antigenic_map , strain_isolation_times ,
316318 par_tab , nsamp , FALSE , mu_indices ,
317319 measurement_indices_by_time ,
318- expand_titredat = TRUE
320+ expand_titredat = TRUE , data_type = data_type
319321 )
320-
322+
321323 # # Use these titre predictions and summary statistics on infection histories
322324 to_use <- titre_preds $ predicted_observations
323325 model_preds <- titre_preds $ predictions
@@ -332,7 +334,6 @@ plot_infection_histories <- function(chain, infection_histories, titre_dat,
332334
333335 max_x <- max(inf_hist_densities $ variable ) + 5
334336 time_range <- range(inf_hist_densities $ variable )
335-
336337 titre_pred_p <- ggplot(to_use ) +
337338 geom_rect(data = inf_hist_densities ,
338339 aes(xmin = xmin ,xmax = xmax ,fill = value ),ymin = min_titre - 1 ,ymax = max_titre + 2 )+
0 commit comments