-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function for setting age-structured outputs for incidence, prevalence…
… and immunity. Discrete age groups are set using a list, where vectors within the list result in contiguous age group rendering. Also correcting spelling of prevalence in create_prevalence_renderer function. This is a correction attempting to remove issues around line endings.
- Loading branch information
1 parent
7e62cc9
commit 610c5cb
Showing
7 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' @title Parameterise age grouped output rendering | ||
#' | ||
#' @details this function produces discrete and contiguous age groups, inclusive of the lower | ||
#' age limit and exclusive of the upper age limit: e.g., list(c(0, 10, 100), c(200, 250) will produce | ||
#' three age groups: 0-9, 10-99 and 200-249 in days. | ||
#' @param parameters the model parameters | ||
#' @param age_group age breaks for population size outputs; default = NULL | ||
#' @param incidence age breaks for incidence outputs (D+Tr+A); default = NULL | ||
#' @param clinical_incidence age breaks for clinical incidence outputs (symptomatic); default = c(0, 1825) | ||
#' @param severe_incidence age breaks for severe incidence outputs; default = NULL | ||
#' @param prevalence age breaks for clinical prevalence outputs (pcr and lm detectable infections); default = c(730, 3650) | ||
#' @export | ||
#' | ||
set_epi_outputs <- function(parameters, | ||
age_group = NULL, | ||
incidence = NULL, | ||
clinical_incidence = NULL, | ||
severe_incidence = NULL, | ||
prevalence = NULL, | ||
ica = NULL, | ||
icm = NULL, | ||
iva = NULL, | ||
ivm = NULL, | ||
id = NULL, | ||
ib = NULL | ||
){ | ||
|
||
parent_formals <- names(formals()) | ||
parent_formals <- parent_formals[which(parent_formals != "parameters")] | ||
outputs <- parent_formals[!unlist(lapply(parent_formals, function(x){is.null(get(x))}))] | ||
|
||
for (output in outputs) { | ||
if(!is.list(get(output))){stop("Each age input must be a list of vectors")} | ||
parameters[[paste0(output, "_rendering_min_ages")]] <- unlist(lapply(get(output), function(x){x[-length(x)]})) | ||
parameters[[paste0(output, "_rendering_max_ages")]] <- unlist(lapply(get(output), function(x){x[-1]-1})) | ||
} | ||
|
||
parameters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
test_that('Test age parameter function works', { | ||
parameters <- get_parameters() | ||
age_limits <- c(0,1,2,3)*365 | ||
parameters <- set_epi_outputs(parameters, | ||
age_group = list(age_limits), | ||
incidence = list(age_limits+1), | ||
clinical_incidence = list(age_limits+2), | ||
severe_incidence = list(age_limits+3), | ||
prevalence = list(age_limits+4), | ||
ica = list(age_limits+5), | ||
icm = list(age_limits+6), | ||
id = list(age_limits+7), | ||
ib = list(age_limits+8), | ||
iva = list(age_limits+9), | ||
ivm = list(age_limits+10) | ||
) | ||
|
||
sim <- run_simulation(timesteps = 1, parameters) | ||
|
||
expect_true( | ||
all( | ||
paste0(rep(c("n_age", | ||
"n", "n_inc", "p_inc", | ||
"n","n_inc_clinical","p_inc_clinical", | ||
"n","n_inc_severe","p_inc_severe", | ||
"n","n_detect","p_detect", | ||
"ica_mean", "icm_mean","id_mean","ib_mean","iva_mean","ivm_mean"), each = 3),"_", | ||
age_limits[-4]+rep(c(0,rep(c(1:4), each = 3),5:10), each = 3),"_",age_limits[-1]-1+rep(c(0,rep(c(1:4), each = 3),5:10), each = 3) | ||
) %in% | ||
names(sim))) | ||
|
||
}) | ||
|
||
test_that('Test age parameter multiple sequences function works', { | ||
parameters <- get_parameters() | ||
age_limits <- c(0,1,2,3)*365 | ||
parameters <- set_epi_outputs(parameters, | ||
age_group = list(age_limits, age_limits+100)) | ||
|
||
sim <- run_simulation(timesteps = 1, parameters) | ||
|
||
expect_true( | ||
all( | ||
paste0(rep(c("n_age"), each = 3),"_", | ||
c(age_limits[-4], age_limits[-4]+100), "_", c(age_limits[-1], age_limits[-1]+100)-1 | ||
) %in% | ||
names(sim))) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters