Skip to content

Commit

Permalink
Minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithJF82 committed Nov 9, 2023
1 parent 34390c0 commit bea4f04
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 573 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export(Generate_Multiple_Datasets)
export(Generate_Sero_Dataset)
export(Generate_VIMC_Burden_Dataset)
export(MCMC)
export(MCMC2)
export(Model_Run)
export(Model_Run_Many_Reps)
export(Model_Run_Multi_Input)
Expand All @@ -23,7 +22,6 @@ export(input_data_truncate)
export(mcmc_FOI_R0_setup)
export(mcmc_checks)
export(mcmc_prelim_fit)
export(mcmc_prelim_fit2)
export(param_calc_enviro)
export(param_prop_setup)
export(parameter_setup)
Expand All @@ -32,7 +30,6 @@ export(sero_calculate)
export(sero_calculate2)
export(sero_data_compare)
export(single_posterior_calc)
export(single_posterior_calc2)
export(template_region_xref)
import(dde)
import(odin.dust)
Expand Down
15 changes: 11 additions & 4 deletions R/data_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,19 @@ regions_breakdown <- function(region_labels=c()){
#-------------------------------------------------------------------------------
#' @title template_region_xref
#'
#' @description [TBA]
#' @description Cross-reference template data with individual regions
#'
#' @details [TBA]
#' @details Examines template data (serological, case or burden) and compares with vector of region names in order
#' to check which lines in each set of template data require model data from which region(s). For example, if a
#' line in a set of serological data has its region given as "AGO.1_1,AGO.2_1,AGO.3_1" and the compared vector of
#' regions is c("AGO.1_1","AGO.2_1","AGO.3_1",...), then that line requires data from regions 1, 2 and 3.
#'
#' @param template [TBA]
#' @param regions [TBA]
#' This function is used when generating a dataset from one or more templates; it is normally used by the functions
#' Generate_Dataset, Generate_Sero_Dataset, Generate_Case_Dataset, Generate_VIMC_Burden_Dataset and
#' Generate_Multiple_Datasets. It returns a list containing [TBA].
#'
#' @param template List containing one or more sets of template data (serological data, case data or burden data)
#' @param regions Vector of individual regions
#'
#' @export
#'
Expand Down
25 changes: 18 additions & 7 deletions R/mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ single_posterior_calc <- function(log_params_prop=c(),input_data=list(),obs_sero
consts=list()){

#Get additional values and calculate associated priors
vaccine_efficacy=p_rep_severe=p_rep_death=m_FOI_Brazil=1.0
vaccine_efficacy=p_rep_severe=p_rep_death=p_rep_severe_af=p_rep_death_af=p_rep_severe_sa=p_rep_death_sa=m_FOI_Brazil=1.0
prior_add=0
for(var_name in names(consts$add_values)){
if(is.numeric(consts$add_values[[var_name]])==FALSE){
Expand Down Expand Up @@ -255,10 +255,19 @@ single_posterior_calc <- function(log_params_prop=c(),input_data=list(),obs_sero
if (is.finite(prior_prop)) {

#Generate modelled data over all regions
dataset <- Generate_Dataset(input_data,FOI_values,R0_values,obs_sero_data,obs_case_data,vaccine_efficacy,
consts$p_severe_inf,consts$p_death_severe_inf,p_rep_severe,p_rep_death,
consts$mode_start,start_SEIRV=NULL,consts$dt,consts$n_reps,consts$deterministic,
consts$mode_parallel,consts$cluster)
if(p_rep_severe %in% names(consts$add_values)){
dataset <- Generate_Dataset(input_data,FOI_values,R0_values,obs_sero_data,obs_case_data,vaccine_efficacy,
consts$p_severe_inf,consts$p_death_severe_inf,p_rep_severe,p_rep_death,
consts$mode_start,start_SEIRV=NULL,consts$dt,consts$n_reps,consts$deterministic,
consts$mode_parallel,consts$cluster)
} else {
dataset <- Generate_Dataset2(input_data,FOI_values,R0_values,obs_sero_data,obs_case_data,vaccine_efficacy,
consts$p_severe_inf,consts$p_death_severe_inf,
p_rep_severe_af,p_rep_death_af,p_rep_severe_sa,p_rep_death_sa,
consts$mode_start,start_SEIRV=NULL,consts$dt,consts$n_reps,consts$deterministic,
consts$mode_parallel,consts$cluster)

}

#Likelihood of observing serological data
if(is.null(obs_sero_data)==FALSE){
Expand Down Expand Up @@ -325,7 +334,9 @@ mcmc_checks <- function(log_params_ini=c(),n_regions=1,type=NULL,prior_settings=

# Check additional values
add_value_names=names(add_values) #TODO: formalize flexibility
#assert_that(all(add_value_names==c("vaccine_efficacy","p_rep_severe","p_rep_death","m_FOI_Brazil")))
# assert_that(all(add_value_names==c("vaccine_efficacy","p_rep_severe","p_rep_death","m_FOI_Brazil")) ||
# all(add_value_names==c("vaccine_efficacy","p_rep_severe_af","p_rep_death_af",
# "p_rep_severe_sa","p_rep_death_sa","m_FOI_Brazil")))
assert_that(all(extra_estimated_params %in% add_value_names))
for(var_name in add_value_names){
if(var_name %in% extra_estimated_params){
Expand Down Expand Up @@ -532,7 +543,7 @@ mcmc_prelim_fit <- function(n_iterations=1,n_param_sets=1,n_bounds=1,type=NULL,l
#Get additional values
extra_estimated_params=c()
add_value_names=names(add_values)
assert_that(all(add_value_names==c("vaccine_efficacy","p_rep_severe","p_rep_death","m_FOI_Brazil"))) #TBV in alt version
#assert_that(all(add_value_names==c("vaccine_efficacy","p_rep_severe","p_rep_death","m_FOI_Brazil"))) #TBV in alt version
for(var_name in add_value_names){
if(is.null(add_values[[var_name]])==TRUE){extra_estimated_params=append(extra_estimated_params,var_name)}
}
Expand Down
Loading

0 comments on commit bea4f04

Please sign in to comment.