Skip to content

Commit

Permalink
Check that booster_spacing is monotonically increasing
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannic committed Jan 9, 2024
1 parent 91247b4 commit 45486ad
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
15 changes: 15 additions & 0 deletions R/pev_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ set_pev_epi <- function(
stop("coverages and timesteps must align")
}

# Check that booster_spacing are monotonically increasing
if (length(booster_spacing) > 1) {
if (!all(diff(booster_spacing) > 0)) {
stop('booster_spacing must be monotonically increasing')
}
}

# Check that seasonal booster parameters make sense
stopifnot(min_wait >= 0)
stopifnot(age >= 0)
Expand Down Expand Up @@ -178,6 +185,14 @@ set_mass_pev <- function(
if (length(min_ages) != length(max_ages)) {
stop('min and max ages do not align')
}

# Check that booster_spacing are monotonically increasing
if (length(booster_spacing) > 1) {
if (!all(diff(booster_spacing) > 0)) {
stop('booster_spacing must be monotonically increasing')
}
}

stopifnot((length(booster_coverage)) == 0 || all(booster_coverage >= 0 & booster_coverage <= 1))
if (!all(c(ncol(booster_coverage), length(booster_profile)) == length(booster_spacing))) {
stop('booster_spacing, booster_coverage and booster_profile do not align')
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-pev-epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ test_that('set_pev_epi checks booster coverage matrix shape', {
)
})

test_that('set_pev_epi checks that booster_spacing are increasing', {
parameters <- get_parameters()
expect_error(
parameters <- set_pev_epi(
parameters,
profile = rtss_profile,
coverages = c(0.1, 0.8),
timesteps = c(10, 100),
min_wait = 0,
age = 5 * 30,
booster_spacing = c(5, 5) * 30,
booster_coverage = matrix(c(.9, .8), nrow=2, ncol=1),
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
),
'booster_spacing must be monotonically increasing',
fixed = TRUE
)
})


test_that('pev epi targets correct age and respects min_wait', {
timestep <- 5*365
parameters <- get_parameters(list(human_population = 5))
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ test_that('set_mass_pev checks booster coverage matrix shape', {
)
})

test_that('set_mass_pev checks booster_spacing is increasing', {
parameters <- get_parameters()
expect_error(
parameters <- set_mass_pev(
parameters,
profile = rtss_profile,
coverages = c(0.1),
timesteps = c(10),
min_wait = 0,
min_ages = 5 * 30,
max_ages = 17 * 30,
booster_spacing = c(5, 5) * 30,
booster_coverage = matrix(c(.9, .8), nrow=2, ncol=1),
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
),
'booster_spacing must be monotonically increasing',
fixed = TRUE
)
})

test_that('Mass vaccination fails pre-emptively for unaligned booster parameters', {
parameters <- get_parameters()
expect_error(
Expand Down

0 comments on commit 45486ad

Please sign in to comment.