From b9b923c466998a1e81427a8597515ea6d90b965e Mon Sep 17 00:00:00 2001 From: RJSheppard Date: Wed, 8 May 2024 15:32:08 +0100 Subject: [PATCH] Added PCR rendering to prevalence rendering function, adjusting tests to rendering tests to reflect additional outputs. --- R/model.R | 4 ++-- R/render.R | 19 ++++++++++++++----- man/run_simulation.Rd | 4 ++-- tests/testthat/test-render.R | 12 ++++++++++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/R/model.R b/R/model.R index 67f79758..ebb25bd7 100644 --- a/R/model.R +++ b/R/model.R @@ -29,10 +29,10 @@ #' * n: number of humans between an inclusive age range at this timestep. This #' defaults to n_730_3650. Other age ranges can be set with #' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. -#' * n_detect: number of humans with an infection detectable by microscopy between an inclusive age range at this timestep. This +#' * n_detect_lm (or pcr): number of humans with an infection detectable by microscopy (or pcr) between an inclusive age range at this timestep. This #' defaults to n_detect_730_3650. Other age ranges can be set with #' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. -#' * p_detect: the sum of probabilities of detection by microscopy between an +#' * p_detect_lm (or pcr): the sum of probabilities of detection by microscopy (or pcr) between an #' inclusive age range at this timestep. This #' defaults to p_detect_730_3650. Other age ranges can be set with #' prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. diff --git a/R/render.R b/R/render.R index 60cb5b73..4f5816f3 100644 --- a/R/render.R +++ b/R/render.R @@ -4,8 +4,11 @@ in_age_range <- function(birth, timestep, lower, upper) { #' @title Render prevalence statistics #' -#' @description renders prevalence numerators and denominators for indivduals -#' detected by microscopy and with severe malaria +#' @description renders prevalence numerators and denominators for individuals +#' detected by light microscopy and pcr, where those infected asymptomatically by +#' P. falciparum have reduced probability of infection due to detectability +#' immunity (reported as an integer sample: n_detect_lm, and summing over +#' detection probabilities: p_detect_lm) #' #' @param state human infection state #' @param birth variable for birth of the individual @@ -32,7 +35,8 @@ create_prevelance_renderer <- function( clinically_detected <- state$get_index_of(c('Tr', 'D')) detected <- clinically_detected$copy()$or(asymptomatic_detected) - + pcr_detected <- state$get_index_of(c('Tr', 'D', 'A', 'U')) + for (i in seq_along(parameters$prevalence_rendering_min_ages)) { lower <- parameters$prevalence_rendering_min_ages[[i]] upper <- parameters$prevalence_rendering_max_ages[[i]] @@ -43,17 +47,22 @@ create_prevelance_renderer <- function( timestep ) renderer$render( - paste0('n_detect_', lower, '_', upper), + paste0('n_detect_lm_', lower, '_', upper), in_age$copy()$and(detected)$size(), timestep ) renderer$render( - paste0('p_detect_', lower, '_', upper), + paste0('p_detect_lm_', lower, '_', upper), in_age$copy()$and(clinically_detected)$size() + sum( prob[bitset_index(asymptomatic, in_age)] ), timestep ) + renderer$render( + paste0('n_detect_pcr_', lower, '_', upper), + pcr_detected$copy()$and(in_age)$size(), + timestep + ) } } } diff --git a/man/run_simulation.Rd b/man/run_simulation.Rd index 383b38f6..5861517d 100644 --- a/man/run_simulation.Rd +++ b/man/run_simulation.Rd @@ -45,10 +45,10 @@ the whole population) \item n: number of humans between an inclusive age range at this timestep. This defaults to n_730_3650. Other age ranges can be set with prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. -\item n_detect: number of humans with an infection detectable by microscopy between an inclusive age range at this timestep. This +\item n_detect_lm (or pcr): number of humans with an infection detectable by microscopy (or pcr) between an inclusive age range at this timestep. This defaults to n_detect_730_3650. Other age ranges can be set with prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. -\item p_detect: the sum of probabilities of detection by microscopy between an +\item p_detect_lm (or pcr): the sum of probabilities of detection by microscopy (or pcr) between an inclusive age range at this timestep. This defaults to p_detect_730_3650. Other age ranges can be set with prevalence_rendering_min_ages and prevalence_rendering_max_ages parameters. diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 920f09bb..cc4e9f87 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -34,7 +34,7 @@ test_that('that default rendering works', { mockery::expect_args( renderer$render_mock(), 2, - 'n_detect_730_3650', + 'n_detect_lm_730_3650', 2, timestep ) @@ -42,11 +42,19 @@ test_that('that default rendering works', { mockery::expect_args( renderer$render_mock(), 3, - 'p_detect_730_3650', + 'p_detect_lm_730_3650', 1.5, timestep ) + mockery::expect_args( + renderer$render_mock(), + 4, + 'n_detect_pcr_730_3650', + 3, + timestep + ) + }) test_that('that default rendering works when no one is in the age range', {