Skip to content

Commit

Permalink
Added PCR rendering to prevalence rendering function, adjusting tests…
Browse files Browse the repository at this point in the history
… to rendering tests to reflect additional outputs.
  • Loading branch information
RJSheppard committed May 8, 2024
1 parent b8f3c27 commit b9b923c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 14 additions & 5 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]
Expand All @@ -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
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions man/run_simulation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions tests/testthat/test-render.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@ test_that('that default rendering works', {
mockery::expect_args(
renderer$render_mock(),
2,
'n_detect_730_3650',
'n_detect_lm_730_3650',
2,
timestep
)

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', {
Expand Down

0 comments on commit b9b923c

Please sign in to comment.