Skip to content

Commit

Permalink
Merge pull request #265 from mrc-ide/bug/competing_vaccination
Browse files Browse the repository at this point in the history
Fix competing hazards for mass and EPI pev:
  • Loading branch information
giovannic authored Sep 22, 2023
2 parents 7fa7ea3 + a7c7dd1 commit efd3dfc
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 3 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# malariasimulation 1.6.1 (wip)

* Fix bug in competing hazards between mass and EPI vaccines. Where individuals
can be enrolled onto both strategies if applied on the same timestep.

# malariasimulation 1.6.0

* Fix MDA bug where undetectable asymptomatics are treated
Expand Down
21 changes: 19 additions & 2 deletions R/pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ create_epi_pev_process <- function(
to_vaccinate <- variables$birth$get_index_of(
set = timestep - parameters$pev_epi_age
)

#ignore those who are scheduled for mass vaccination
if (!is.null(events$mass_pev_doses)) {
to_vaccinate <- to_vaccinate$and(
events$mass_pev_doses[[1]]$get_scheduled()$not()
)
}

if (parameters$pev_epi_min_wait == 0) {
target <- to_vaccinate$to_vector()
} else {
Expand Down Expand Up @@ -81,13 +89,22 @@ create_mass_pev_listener <- function(
in_age_group$or(variables$birth$get_index_of(a = min_birth, b = max_birth))
}
if (parameters$mass_pev_min_wait == 0) {
target <- in_age_group$to_vector()
target <- in_age_group
} else {
not_recently_vaccinated <- variables$pev_timestep$get_index_of(
a = max(timestep - parameters$mass_pev_min_wait, 0),
b = timestep
)$not(TRUE)
target <- in_age_group$and(not_recently_vaccinated)$to_vector()
target <- in_age_group$and(not_recently_vaccinated)
}

#ignore those who are scheduled for EPI vaccination
if (!is.null(events$pev_epi_doses)) {
target <- target$and(
events$pev_epi_doses[[1]]$get_scheduled()$not()
)$to_vector()
} else {
target <- target$to_vector()
}

time_index = which(parameters$mass_pev_timesteps == timestep)
Expand Down
2 changes: 1 addition & 1 deletion src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ BEGIN_RCPP
END_RCPP
}

RcppExport SEXP run_testthat_tests(void);
RcppExport SEXP run_testthat_tests();

static const R_CallMethodDef CallEntries[] = {
{"_malariasimulation_create_adult_mosquito_model", (DL_FUNC) &_malariasimulation_create_adult_mosquito_model, 5},
Expand Down
70 changes: 70 additions & 0 deletions tests/testthat/test-pev-epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,76 @@ test_that('pev epi targets correct age and respects min_wait', {
)
})

test_that('EPI ignores individuals scheduled for mass vaccination', {
timestep <- 100
parameters <- get_parameters(list(human_population = 5))
parameters <- set_mass_pev(
parameters,
profile = rtss_profile,
timesteps = c(50, 100),
coverages = rep(0.8, 2),
min_wait = 0,
min_ages = c(1, 2, 3, 18) * 365,
max_ages = (c(1, 2, 3, 18) + 1) * 365 - 1,
booster_timestep = c(18, 36) * 30,
booster_coverage = c(.9, .8),
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
)
parameters <- set_pev_epi(
parameters,
profile = rtss_profile,
timesteps = 10,
coverages = 0.8,
min_wait = 0,
age = 18 * 365,
booster_timestep = c(18, 36) * 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, 8, 2.9, 3.2, 18) * 365 + 100
)
variables$pev_timestep <- mock_integer(
c(-1, -1, -1, 50, 50)
)

correlations <- get_correlation_parameters(parameters)

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

sample_mock <- mockery::mock(c(TRUE))

mockery::stub(
process,
'sample_intervention',
sample_mock
)

# schedule id #1 for epi vaccination
events$mass_pev_doses[[1]]$schedule(1, 0)

process(timestep)

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


test_that('pev EPI respects min_wait when scheduling seasonal boosters', {
timestep <- 5 * 365
parameters <- get_parameters(list(human_population = 5))
Expand Down
68 changes: 68 additions & 0 deletions tests/testthat/test-pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,74 @@ test_that('Mass vaccinations update vaccination time', {
)
})

test_that('Mass vaccinations ignore EPI individuals', {
timestep <- 100
parameters <- get_parameters(list(human_population = 5))
parameters <- set_mass_pev(
parameters,
profile = rtss_profile,
timesteps = c(50, 100),
coverages = rep(0.8, 2),
min_wait = 0,
min_ages = c(1, 2, 3, 18) * 365,
max_ages = (c(1, 2, 3, 18) + 1) * 365 - 1,
booster_timestep = c(18, 36) * 30,
booster_coverage = c(.9, .8),
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
)
parameters <- set_pev_epi(
parameters,
profile = rtss_profile,
timesteps = 10,
coverages = 0.8,
min_wait = 2*365,
age = 18 * 365,
booster_timestep = c(18, 36) * 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.3, 8, 2.9, 3.2, 18.4) * 365 + 100
)
variables$pev_timestep <- mock_integer(
c(-1, -1, -1, 50, 50)
)

correlations <- get_correlation_parameters(parameters)

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

sample_mock <- mockery::mock(c(TRUE, TRUE, FALSE, FALSE))

mockery::stub(
listener,
'sample_intervention',
sample_mock
)

# schedule id #1 for epi vaccination
events$pev_epi_doses[[1]]$schedule(1, 0)

listener(timestep)

mockery::expect_args(
sample_mock,
1,
c(3, 4, 5),
'pev',
.8,
correlations
)
})


test_that('Mass boosters update profile params and reschedule correctly', {
parameters <- get_parameters()
parameters <- set_mass_pev(
Expand Down

0 comments on commit efd3dfc

Please sign in to comment.