-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function for setting age-structured outputs. #297
Changes from 10 commits
1ba67c0
08b1f62
c5a7bec
4e14e50
4b54e80
4a58966
3236f76
8e759c1
247432c
f3669f5
1d4f4a2
e568127
0057fda
a591eb0
ba4bedc
462b0fe
610c5cb
55d83ea
abdcef0
8786b81
a542d10
482fc83
c9c90f5
8f11a06
09a8c3e
5746a6b
b852847
24a0253
3989fdc
7bd8c0d
6d34636
06c1e8d
91f8270
d05b335
a4f66e2
e51c6bc
b4825c7
4701748
e004d5b
65e5899
0ff9f95
1886755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#' @title Parameterise age grouped output rendering | ||
#' | ||
#' @details this function produces contiguous age groups, inclusive of the lower | ||
#' age limit and exclusive of the upper age limit: e.g., c(0, 10, 100) will produce | ||
#' two age groups: 0-9 and 10-99 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) | ||
#' @param ica age breaks for average acquired clinical immunity; default = NULL | ||
#' @param icm age breaks for average maternal clinical immunity; default = NULL | ||
#' @param iva age breaks for average acquired severe immunity; default = NULL | ||
#' @param ivm age breaks for average maternal severe immunity; default = NULL | ||
#' @param id age breaks for average immunity to detectability; default = NULL | ||
#' @param ib age breaks for average blood immunity; default = NULL | ||
#' @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 | ||
){ | ||
|
||
input <- list( | ||
age_group = age_group, | ||
incidence = incidence, | ||
clinical_incidence = clinical_incidence, | ||
severe_incidence = severe_incidence, | ||
prevalence = prevalence, | ||
ica = ica, | ||
icm = icm, | ||
iva = iva, | ||
ivm = ivm, | ||
id = id, | ||
ib = ib | ||
) | ||
input <- input[!sapply(input, is.null)] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to validate that output_rendering... is in parameters? I feel like R lets you put any kwarg in without complaining. Something to double check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry - would you mind explaining this a bit more? Are you saying to just check that the parameters appear in the parameter list after this function is used? I have a test that should check for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is obsolete now since we don't use |
||
for(i in seq_along(input)){ | ||
name <- names(input)[i] | ||
ages <- input[[i]] | ||
min_ages <- ages[-length(ages)] | ||
max_ages <- ages[-1] - 1 | ||
parameters[[paste0(name, "_rendering_min_ages")]] <- min_ages | ||
parameters[[paste0(name, "_rendering_max_ages")]] <- max_ages | ||
} | ||
|
||
return(parameters) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 = age_limits, | ||
incidence = age_limits+1, | ||
clinical_incidence = age_limits+2, | ||
severe_incidence = age_limits+3, | ||
prevalence = age_limits+4, | ||
ica = age_limits+5, | ||
icm = age_limits+6, | ||
id = age_limits+7, | ||
ib = age_limits+8, | ||
iva = age_limits+9, | ||
ivm = 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_lm","p_detect_lm","n_detect_pcr", | ||
"ica_mean", "icm_mean","id_mean","ib_mean","iva_mean","ivm_mean"), each = 3),"_", | ||
age_limits[-4]+rep(c(0,rep(c(1:3), each = 3), rep(4, 4), 5:10), each = 3),"_",age_limits[-1]-1+rep(c(0,rep(c(1:3), each = 3), rep(4, 4), 5:10), each = 3) | ||
) %in% | ||
names(sim))) | ||
|
||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this a little tricky to parse (although I think it all works!).
I was wondering if we can avoid having to input lists, and (maybe) make the process inthe function a bit simpler. Does the following work in the correct way? I haven't tested it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to capture discrete age blocks with the lists, e.g., if you want to output 1-100 and 200-300, but not 101-199. I don't think this code would do that, but maybe that's not so important for it to do.