-
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
Conversation
* Add rdt testing parameters * Update biting_process to consider rdt testing for mixing
- updating metapop vignette - clarifying row & col meanings
* Add rdt testing parameters * Update biting_process to consider rdt testing for mixing
* refactor transmission mixing code * fix regressions * add time caching
* Added export_mixing and import_mixing arguments to run_metapop_... * Update create_transmission_mixer to mix eir on import and foim on export * Fix regression tests
Add asymmetric transmission in mixing:
80eb376
to
dc12862
Compare
… 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.
dc12862
to
610c5cb
Compare
@@ -0,0 +1,45 @@ | |||
#' @title Parameterise age grouped output rendering |
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!
#' @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., c(0, 10, 100, 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)
#' @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 = c(0, 10, 100, 200, 250),
incidence = NULL,
clinical_incidence = c(0, 1825),
severe_incidence = NULL,
prevalence = c(730, 3650),
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)]
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)
}
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.
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))}))] | ||
|
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
this is obsolete now since we don't use formals
!
R/output_parameters.R
Outdated
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})) |
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 agree with Pete that it's a little terse. You could perhaps make it more readable with names for the functions function(x){x[-length(x)]}
and function(x){x[-1]-1}
, and/or unwrapping an unlist/lapply into a for loop.
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.
Sure thing - happy to put this into a function for readability.
… 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.
…will be rendered now). Made the code more easier to read.
Merge branch 'new_epi_outputs_function' of https://github.com/mrc-ide/malariasimulation into new_epi_outputs_function # Conflicts: # R/output_parameters.R # man/set_epi_outputs.Rd # tests/testthat/test-output.R
Was there anything extra on this branch that either of you wanted changing (@pwinskill @giovannic)? |
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.
This does reduce the functionality as you said, it doesn't support modelling discontiguous age ranges. But it is more readable. Approving since it is likely helpful for some users regardless
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))}))] | ||
|
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.
this is obsolete now since we don't use formals
!
change mixing to export_mixing and import_mixing
Co-authored-by: Paul Liétar <pl2113@ic.ac.uk>
Co-authored-by: Paul Liétar <pl2113@ic.ac.uk>
Export the run_resumable_simulation
Feat/metapopulation model
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.
👍
… 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.
…will be rendered now). Made the code more easier to read.
… 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.
…simulation into new_epi_outputs_function # Conflicts: # tests/testthat/test-output.R
Sets parameters that output age-structured incidence, prevalence and immunity levels. Discrete age groups are set using a list, where vectors within the list result in contiguous age group rendering.
(I also corrected sp. of prevelance -> prevalence :) )