Skip to content

Commit

Permalink
Fix bug with pev min_wait:
Browse files Browse the repository at this point in the history
 * Update pev-epi min_wait test to directly check sample population
 * Update pe-epi  min_wait test to check that pev_timestep is being updated
   on the first dose
 * Copy pev-epi min_wait test to mass pev
 * Update pev and epi processes to calculate targets based on time of first dose
 * Update infection immunity function to calculate pev immunity only
   after 3rd dose
  • Loading branch information
giovannic committed Sep 15, 2023
1 parent 7b74c3d commit 86424e7
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: malariasimulation
Title: An individual based model for malaria
Version: 1.6.0
Version: 1.6.1
Authors@R: c(
person(
given = "Giovanni",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

# malariasimulation 1.6.1 (wip)

* Fix bug with min_wait. Min wait was working off of the final primary dose. It
now works of of the first dose.

# malariasimulation 1.6.0

* Fix MDA bug where undetectable asymptomatics are treated
Expand Down
4 changes: 3 additions & 1 deletion R/human_infection.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ calculate_infections <- function(
# calculate vaccine efficacy
vaccine_efficacy <- rep(0, length(source_vector))
vaccine_times <- variables$pev_timestep$get_values(source_vector)
vaccinated <- vaccine_times > -1
pev_profile <- variables$pev_profile$get_values(source_vector)
# get vector of individuals who have been vaccinated
# and received their 3rd dose
vaccinated <- pev_profile > -1
pev_profile <- pev_profile[vaccinated]
if (length(vaccinated) > 0) {
antibodies <- calculate_pev_antibodies(
Expand Down
12 changes: 12 additions & 0 deletions R/pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ create_epi_pev_process <- function(
)
]

# Update the latest vaccination time
variables$pev_timestep$queue_update(timestep, target)
# Reset the pev_profile so that we are not yet efficacious
variables$pev_profile$queue_update(-1, target)

schedule_vaccination(
target,
events,
Expand Down Expand Up @@ -99,6 +104,13 @@ create_mass_pev_listener <- function(
correlations
)
]

# Update the latest vaccination time
variables$pev_timestep$queue_update(timestep, target)
# Reset the pev_profile so that we are not yet efficacious
variables$pev_profile$queue_update(-1, target)

# Schedule future doses
schedule_vaccination(
target,
events,
Expand Down
6 changes: 4 additions & 2 deletions R/variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#' * zeta_group - Discretised heterogeneity of human individuals
#' * pev_timestep - The timestep of the last pev vaccination (-1 if there
#' haven't been any)
#' * pev_profile - The index of the profile of the last administered pev vaccine
#' (-1 if there haven't been any)
#' * pev_profile - The index of the profile of the last administered pev
#' vaccine.
#' This is only set on the final primary dose and subsequent booster doses
#' (-1 otherwise)
#' * tbv_vaccinated - The timstep of the last tbv vaccination (-1 if there
#' haven't been any
#' * net_time - The timestep when a net was last put up (-1 if never)
Expand Down
32 changes: 19 additions & 13 deletions tests/testthat/test-pev-epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,52 @@ test_that('pev epi targets correct age and respects min_wait', {
variables$pev_timestep <- mock_integer(
c(50, -1, -1, 4*365, -1)
)
variables$pev_profile <- mock_integer(
c(1, -1, -1, 1, -1)
)

events$pev_epi_doses <- lapply(events$pev_epi_doses, mock_event)

correlations <- get_correlation_parameters(parameters)
process <- create_epi_pev_process(
variables,
events,
parameters,
get_correlation_parameters(parameters),
correlations,
parameters$pev_epi_coverages,
parameters$pev_epi_timesteps
)

sample_mock <- mockery::mock(c(TRUE, TRUE, FALSE))
mockery::stub(
process,
'sample_intervention',
mockery::mock(c(TRUE, TRUE, FALSE))
sample_mock
)

process(timestep)

mockery::expect_args(
events$pev_epi_doses[[1]]$schedule,
sample_mock,
1,
c(1, 2),
parameters$pev_doses[[1]]
c(1, 2, 5),
'pev',
.8,
correlations
)

mockery::expect_args(
events$pev_epi_doses[[2]]$schedule,
variables$pev_timestep$queue_update_mock(),
1,
c(1, 2),
parameters$pev_doses[[2]]
timestep,
c(1, 2)
)

mockery::expect_args(
events$pev_epi_doses[[3]]$schedule,
variables$pev_profile$queue_update_mock(),
1,
c(1, 2),
parameters$pev_doses[[3]]
-1,
c(1, 2)
)

})

test_that('pev EPI respects min_wait when scheduling seasonal boosters', {
Expand Down
69 changes: 69 additions & 0 deletions tests/testthat/test-pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,75 @@ test_that('Mass booster coverages sample subpopulations correctly', {
)
})

test_that('mass pev targets correct age and respects min_wait', {
timestep <- 5*365
parameters <- get_parameters(list(human_population = 5))
parameters <- set_mass_pev(
parameters,
profile = rtss_profile,
timesteps = c(4, 5) * 365,
coverages = c(0.8, 0.8),
min_ages = 0,
max_ages = 19 * 365,
min_wait = 2*365,
booster_timestep = c(1, 6) * 30,
booster_coverage = c(.9, .8),
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
)
events <- create_events(parameters)
variables <- create_variables(parameters)
variables$birth <- individual::IntegerVariable$new(
-c(18, 18, 30, 18, 18) * 365 + timestep
)
variables$pev_timestep <- mock_integer(
c(50, -1, -1, 4*365, -1)
)

variables$pev_profile <- mock_integer(
c(1, -1, -1, 1, -1)
)

correlations <- get_correlation_parameters(parameters)
listener <- create_mass_pev_listener(
variables,
events,
parameters,
get_correlation_parameters(parameters)
)

sample_mock <- mockery::mock(c(TRUE, TRUE, FALSE))
mockery::stub(
listener,
'sample_intervention',
sample_mock
)

listener(timestep)

mockery::expect_args(
sample_mock,
1,
c(1, 2, 5),
'pev',
.8,
correlations
)

mockery::expect_args(
variables$pev_timestep$queue_update_mock(),
1,
timestep,
c(1, 2)
)

mockery::expect_args(
variables$pev_profile$queue_update_mock(),
1,
-1,
c(1, 2)
)
})

test_that('Mass efficacy listener works correctly', {
timestep <- 50
parameters <- get_parameters()
Expand Down

0 comments on commit 86424e7

Please sign in to comment.