Skip to content

Commit

Permalink
Merge pull request #179 from mrc-ide/feat/rtss_epi_variable_cov
Browse files Browse the repository at this point in the history
Time varying rtss epi coverage
  • Loading branch information
giovannic authored Aug 3, 2022
2 parents d3a6131 + f5472aa commit ea9e064
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 165 deletions.
2 changes: 1 addition & 1 deletion R/compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ remove_unused_equilibrium <- function(params) {
#' equilibrium parameters and set up the initial human and mosquito population
#' to acheive init_EIR
#' @param parameters model parameters to update
#' @param init_EIR the desired initial EIR (infectious bites per day over the entire human
#' @param init_EIR the desired initial EIR (infectious bites per person per day over the entire human
#' population)
#' @param eq_params parameters from the malariaEquilibrium package, if null.
#' The default malariaEquilibrium parameters will be used
Expand Down
2 changes: 1 addition & 1 deletion R/events.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create_events <- function(parameters) {
}

# EPI vaccination events
if (!is.null(parameters$rtss_epi_start)) {
if (!is.null(parameters$rtss_epi_coverage)) {
rtss_epi_doses <- lapply(
seq_along(parameters$rtss_doses),
function(.) individual::TargetedEvent$new(parameters$human_population)
Expand Down
6 changes: 4 additions & 2 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ create_processes <- function(
# =========
# RTS,S EPI
# =========
if (!is.null(parameters$rtss_epi_start)) {
if (!is.null(parameters$rtss_epi_coverages)) {
processes <- c(
processes,
create_rtss_epi_process(
variables,
events,
parameters,
correlations
correlations,
parameters$rtss_epi_coverages,
parameters$rtss_epi_timesteps
)
)
}
Expand Down
16 changes: 12 additions & 4 deletions R/rtss.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ create_rtss_epi_process <- function(
variables,
events,
parameters,
correlations
correlations,
coverages,
timesteps
) {
function(timestep) {
if (!between(timestep, parameters$rtss_epi_start, parameters$rtss_epi_end)) {
timestep_index <- match_timestep(ts = timesteps, t = timestep)
if(timestep_index == 0){
return()
}
coverage <- coverages[timestep_index]
if(coverage == 0){
return()
}

to_vaccinate <- variables$birth$get_index_of(
set = timestep - parameters$rtss_epi_age
)

if (parameters$rtss_epi_min_wait == 0) {
target <- to_vaccinate$to_vector()
} else {
Expand All @@ -36,10 +43,11 @@ create_rtss_epi_process <- function(
sample_intervention(
target,
'rtss',
parameters$rtss_epi_coverage,
coverage,
correlations
)
]

schedule_vaccination(
target,
events,
Expand Down
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ rtexp <- function(n, m, t) { itexp(runif(n), m, t) }
match_timestep <- function(ts, t) {
min(sum(ts <= t), length(ts))
}

21 changes: 9 additions & 12 deletions R/vaccine_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#' age. Efficacy will take effect after the last dose
#'
#' @param parameters a list of parameters to modify
#' @param start timestep to turn on epi vaccination
#' @param end timestep to turn off epi vaccination
#' @param coverage the coverage for the starter doses
#' @param coverages a vector of coverages for the starter doses
#' @param timesteps a vector of timesteps associated with coverages
#' @param age for the target population, (in timesteps)
#' @param min_wait the minimum acceptable time since the last vaccination (in
#' timesteps); When seasonal_boosters = TRUE, this represents the minimum time
Expand All @@ -21,19 +20,18 @@
#' @export
set_rtss_epi <- function(
parameters,
start,
end,
coverage,
coverages,
timesteps,
age,
min_wait,
boosters,
booster_coverage,
seasonal_boosters = FALSE
) {
stopifnot(length(start) == 1 && start > 1)
stopifnot(length(end) == 1 && end > start)
if(length(coverages) != length(timesteps)){
stop("coverages and timesteps must align")
}
stopifnot(min_wait >= 0)
stopifnot(coverage >= 0 & coverage <= 1)
stopifnot(age >= 0)
stopifnot(is.logical(seasonal_boosters))
if (seasonal_boosters) {
Expand All @@ -47,9 +45,8 @@ set_rtss_epi <- function(
stop('booster and booster_coverage does not align')
}
parameters$rtss <- TRUE
parameters$rtss_epi_start <- start
parameters$rtss_epi_end <- end
parameters$rtss_epi_coverage <- coverage
parameters$rtss_epi_coverages <- coverages
parameters$rtss_epi_timesteps <- timesteps
parameters$rtss_epi_age <- age
parameters$rtss_epi_boosters <- boosters
parameters$rtss_epi_min_wait <- min_wait
Expand Down
3 changes: 1 addition & 2 deletions man/set_equilibrium.Rd

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

11 changes: 4 additions & 7 deletions man/set_rtss_epi.Rd

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

34 changes: 15 additions & 19 deletions tests/testthat/test-rtss-epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ test_that('RTS,S epi strategy parameterisation works', {
parameters <- get_parameters()
parameters <- set_rtss_epi(
parameters,
start = 10,
end = 100,
coverage = 0.8,
coverages = c(0.1, 0.8),
timesteps = c(10, 100),
min_wait = 0,
age = 5 * 30,
boosters = c(18, 36) * 30,
booster_coverage = c(.9, .8)
)
expect_equal(parameters$rtss, TRUE)
expect_equal(parameters$rtss_epi_start, 10)
expect_equal(parameters$rtss_epi_end, 100)
expect_equal(parameters$rtss_epi_coverage, .8)
expect_equal(parameters$rtss_epi_coverages, c(0.1, 0.8))
expect_equal(parameters$rtss_epi_timesteps, c(10, 100))
expect_equal(parameters$rtss_epi_age, 5 * 30)
expect_equal(parameters$rtss_epi_min_wait, 0)
expect_equal(parameters$rtss_epi_boosters, c(18, 36) * 30)
Expand All @@ -24,9 +22,8 @@ test_that('RTS,S epi fails pre-emptively', {
expect_error(
set_rtss_epi(
parameters,
start = 10,
end = 100,
coverages = 0.8,
coverages = c(0.1, 0.8),
timesteps = c(10, 100),
min_wait = 0,
min_ages = 5 * 30,
max_ages = 17 * 30,
Expand All @@ -42,9 +39,8 @@ test_that('RTS,S epi targets correct age and respects min_wait', {
parameters <- get_parameters(list(human_population = 5))
parameters <- set_rtss_epi(
parameters,
start = 10,
end = timestep,
coverage = 0.8,
timesteps = 10,
coverages = 0.8,
min_wait = 2*365,
age = 18 * 365,
boosters = c(18, 36) * 30,
Expand All @@ -65,7 +61,9 @@ test_that('RTS,S epi targets correct age and respects min_wait', {
variables,
events,
parameters,
get_correlation_parameters(parameters)
get_correlation_parameters(parameters),
parameters$rtss_epi_coverages,
parameters$rtss_epi_timesteps
)

mockery::stub(
Expand Down Expand Up @@ -103,9 +101,8 @@ test_that('RTS,S EPI respects min_wait when scheduling seasonal boosters', {
parameters <- get_parameters(list(human_population = 5))
parameters <- set_rtss_epi(
parameters,
start = 10,
end = timestep,
coverage = 0.8,
timesteps = 10,
coverages = 0.8,
min_wait = 6 * 30,
age = 18 * 365,
boosters = c(3, 12) * 30,
Expand Down Expand Up @@ -138,9 +135,8 @@ test_that('RTS,S EPI schedules for the following year with seasonal boosters', {
parameters <- get_parameters(list(human_population = 5))
parameters <- set_rtss_epi(
parameters,
start = 10,
end = timestep,
coverage = 0.8,
timesteps = 10,
coverages = 0.8,
min_wait = 6 * 30,
age = 18 * 365,
boosters = c(3, 12) * 30,
Expand Down
Loading

0 comments on commit ea9e064

Please sign in to comment.