3333# ' @param output_proposals Logical indicating whether proposed parameter jumps should be output along with results
3434# ' @param n_chains number of MCMC chains to run
3535# ' @inheritParams calibrate
36+ # ' @param date_vaccine_change Date that vaccine doses per day change.
37+ # ' Default = NULL.
38+ # ' @param baseline_max_vaccine Baseline vaccine doses per day. Default = NULL
39+ # ' @param max_vaccine Time varying maximum vaccine doeses per day. Default = NULL.
3640# ' @param Rt_args List of arguments to be passed to \code{evaluate_Rt_pmcmc} for calculating Rt.
3741# ' Current arguments are available in \code{Rt_args_list}
3842# ' @param burnin number of iterations to discard from the start of MCMC run when sampling from the posterior for trajectories
@@ -161,6 +165,9 @@ pmcmc <- function(data,
161165 ICU_bed_capacity = NULL ,
162166 baseline_ICU_bed_capacity = NULL ,
163167 date_ICU_bed_capacity_change = NULL ,
168+ date_vaccine_change = NULL ,
169+ baseline_max_vaccine = NULL ,
170+ max_vaccine = NULL ,
164171 Rt_args = NULL ,
165172 burnin = 0 ,
166173 replicates = 100 ,
@@ -180,6 +187,11 @@ pmcmc <- function(data,
180187 # assertions & checks
181188 # --------------------
182189
190+ # if nimue keep to 1 step per day
191+ if (inherits(squire_model , " nimue_model" )) {
192+ steps_per_day <- 1
193+ }
194+
183195 # we work with pars_init being a list of inital conditions for starting
184196 if (any(c(" start_date" , " R0" ) %in% names(pars_init ))) {
185197 pars_init <- list (pars_init )
@@ -312,9 +324,6 @@ pmcmc <- function(data,
312324 if (as.Date(tail(date_contact_matrix_set_change ,1 )) > as.Date(tail(data $ date , 1 ))) {
313325 stop(" Last date in date_contact_matrix_set_change is greater than the last date in data" )
314326 }
315- if (as.Date(pars_max $ start_date ) > = as.Date(head(date_contact_matrix_set_change , 1 ))) {
316- stop(" First date in date_contact_matrix_set_change is earlier than maximum start date allowed in pars search" )
317- }
318327
319328 # Get in correct format
320329 if (is.matrix(baseline_contact_matrix )) {
@@ -343,9 +352,6 @@ pmcmc <- function(data,
343352 if (as.Date(tail(date_ICU_bed_capacity_change ,1 )) > as.Date(tail(data $ date , 1 ))) {
344353 stop(" Last date in date_ICU_bed_capacity_change is greater than the last date in data" )
345354 }
346- if (as.Date(pars_max $ start_date ) > = as.Date(head(date_ICU_bed_capacity_change , 1 ))) {
347- stop(" First date in date_ICU_bed_capacity_change is earlier than maximum start date of epidemic" )
348- }
349355
350356 tt_ICU_beds <- c(0 , seq_len(length(date_ICU_bed_capacity_change )))
351357 ICU_bed_capacity <- c(baseline_ICU_bed_capacity , ICU_bed_capacity )
@@ -355,6 +361,33 @@ pmcmc <- function(data,
355361 ICU_bed_capacity <- baseline_ICU_bed_capacity
356362 }
357363
364+ # handle vaccine changes
365+ if (! is.null(date_vaccine_change )) {
366+
367+ assert_date(date_vaccine_change )
368+ assert_vector(max_vaccine )
369+ assert_numeric(max_vaccine )
370+ assert_numeric(baseline_max_vaccine )
371+
372+ if (is.null(baseline_max_vaccine )) {
373+ stop(" baseline_max_vaccine can't be NULL if date_vaccine_change is provided" )
374+ }
375+ if (as.Date(tail(date_vaccine_change ,1 )) > as.Date(tail(data $ date , 1 ))) {
376+ stop(" Last date in date_vaccine_change is greater than the last date in data" )
377+ }
378+
379+ tt_vaccine <- c(0 , seq_len(length(date_vaccine_change )))
380+ max_vaccine <- c(baseline_max_vaccine , max_vaccine )
381+
382+ } else {
383+ tt_vaccine <- 0
384+ if (! is.null(baseline_max_vaccine )) {
385+ max_vaccine <- baseline_max_vaccine
386+ } else {
387+ max_vaccine <- 0
388+ }
389+ }
390+
358391 # handle hosp bed changed
359392 if (! is.null(date_hosp_bed_capacity_change )) {
360393
@@ -369,9 +402,6 @@ pmcmc <- function(data,
369402 if (as.Date(tail(date_hosp_bed_capacity_change ,1 )) > as.Date(tail(data $ date , 1 ))) {
370403 stop(" Last date in date_hosp_bed_capacity_change is greater than the last date in data" )
371404 }
372- if (as.Date(pars_max $ start_date ) > = as.Date(head(date_hosp_bed_capacity_change , 1 ))) {
373- stop(" First date in date_hosp_bed_capacity_change is earlier than maximum start date of epidemic" )
374- }
375405
376406 tt_hosp_beds <- c(0 , seq_len(length(date_hosp_bed_capacity_change )))
377407 hosp_bed_capacity <- c(baseline_hosp_bed_capacity , hosp_bed_capacity )
@@ -403,6 +433,8 @@ pmcmc <- function(data,
403433 tt_hosp_beds = tt_hosp_beds ,
404434 ICU_bed_capacity = ICU_bed_capacity ,
405435 tt_ICU_beds = tt_ICU_beds ,
436+ max_vaccine = max_vaccine ,
437+ tt_vaccine = tt_vaccine ,
406438 ... )
407439
408440 # collect interventions for odin model likelihood
@@ -413,7 +445,9 @@ pmcmc <- function(data,
413445 date_ICU_bed_capacity_change = date_ICU_bed_capacity_change ,
414446 ICU_bed_capacity = ICU_bed_capacity ,
415447 date_hosp_bed_capacity_change = date_hosp_bed_capacity_change ,
416- hosp_bed_capacity = hosp_bed_capacity )
448+ hosp_bed_capacity = hosp_bed_capacity ,
449+ date_vaccine_change = date_vaccine_change ,
450+ max_vaccine = max_vaccine )
417451
418452 # ----------------..
419453 # Collect Odin and MCMC Inputs
@@ -609,10 +643,13 @@ pmcmc <- function(data,
609643 tt_hosp_beds = tt_hosp_beds ,
610644 ICU_bed_capacity = ICU_bed_capacity ,
611645 tt_ICU_beds = tt_ICU_beds ,
646+ max_vaccine = max_vaccine ,
647+ tt_vaccine = tt_vaccine ,
612648 population = population ,
613649 replicates = 1 ,
614650 day_return = TRUE ,
615- time_period = nrow(pmcmc_samples $ trajectories ))
651+ time_period = nrow(pmcmc_samples $ trajectories ),
652+ ... )
616653
617654 # and add the parameters that changed between each simulation, i.e. posterior draws
618655 r $ replicate_parameters <- pmcmc_samples $ sampled_PMCMC_Results
@@ -1195,6 +1232,7 @@ calc_loglikelihood <- function(pars, data, squire_model, model_params,
11951232 date_contact_matrix_set_change <- interventions $ date_contact_matrix_set_change
11961233 date_ICU_bed_capacity_change <- interventions $ date_ICU_bed_capacity_change
11971234 date_hosp_bed_capacity_change <- interventions $ date_hosp_bed_capacity_change
1235+ date_vaccine_change <- interventions $ date_vaccine_change
11981236
11991237 # change betas
12001238 if (is.null(date_R0_change )) {
@@ -1245,6 +1283,19 @@ calc_loglikelihood <- function(pars, data, squire_model, model_params,
12451283 model_params $ hosp_beds <- tt_list $ change
12461284 }
12471285
1286+ # and vaccine coverage
1287+ if (is.null(date_vaccine_change )) {
1288+ tt_vaccine <- 0
1289+ max_vaccine <- 0
1290+ } else {
1291+ tt_list <- intervention_dates_for_odin(dates = sort(unique(c(start_date ,date_vaccine_change ))),
1292+ change = interventions $ max_vaccine ,
1293+ start_date = start_date ,
1294+ steps_per_day = round(1 / model_params $ dt ))
1295+ model_params $ tt_vaccine <- tt_list $ tt
1296+ model_params $ max_vaccine <- tt_list $ change
1297+ }
1298+
12481299 # --------------------..
12491300 # update new R0s based on R0_change and R0_date_change, and Meff_date_change
12501301 # --------------------..
0 commit comments