Skip to content

Commit

Permalink
Remove make PEVProfile for list based alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannic committed Mar 7, 2023
1 parent 50f5c92 commit 00d5383
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 150 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

export(AL_params)
export(DHA_PQP_params)
export(PEVProfile)
export(SP_AQ_params)
export(arab_params)
export(create_pev_profile)
export(fun_params)
export(gamb_params)
export(get_correlation_parameters)
Expand Down Expand Up @@ -32,7 +32,6 @@ export(set_species)
export(set_spraying)
export(set_tbv)
importFrom(MASS,mvrnorm)
importFrom(R6,R6Class)
importFrom(Rcpp,sourceCpp)
importFrom(stats,qnorm)
importFrom(stats,rbinom)
Expand Down
90 changes: 29 additions & 61 deletions R/pev_parameters.R
Original file line number Diff line number Diff line change
@@ -1,58 +1,38 @@
#' @title PEV profile
#' @description A data structure for holding pre-erythrocytic vaccine profile parameters.
#' Parameters are validated on creation.
#' @importFrom R6 R6Class
#' @title create a PEV profile
#' @description creates a data structure for holding pre-erythrocytic vaccine
#' profile parameters. Parameters are validated on creation.
#' @param vmax maximum efficacy of the vaccine
#' @param alpha shape parameter for the vaccine efficacy model
#' @param beta scale parameter for the vaccine efficacy model
#' @param cs peak parameters for the antibody model (vector of mean and std. dev)
#' @param rho delay parameters for the antibody model (vector of mean and std. dev)
#' @param ds delay parameters for the antibody model, short-term waning (vector of mean and std. dev)
#' @param dl delay parameters for the antibody model, long-term waning (vector of mean and std. dev)
#' @export
PEVProfile <- R6::R6Class(
'PEVProfile',
public = list(
#' @field vmax maximum efficacy of the vaccine
vmax = 0,
#' @field alpha shape parameter for the vaccine efficacy model
alpha = 0,
#' @field beta scale parameter for the vaccine efficacy model
beta = 0,
#' @field cs peak parameters for the antibody model (vector of mean and std. dev)
cs = 0,
#' @field rho delay parameters for the antibody model (vector of mean and std. dev)
rho = 0,
#' @field ds delay parameters for the antibody model, short-term waning (vector of mean and std. dev)
ds = 0,
#' @field dl delay parameters for the antibody model, long-term waning (vector of mean and std. dev)
dl = 0,

#' @description create a vaccine profile
#' @param vmax immutable value for vmax
#' @param alpha immutable value for alpha
#' @param beta immutable value for beta
#' @param cs immutable value for cs
#' @param rho immutable value for rho
#' @param ds immutable value for ds
#' @param dl immutable value for dl
initialize = function(vmax, alpha, beta, cs, rho, ds, dl) {
allargs <- c(vmax, alpha, beta, cs, rho, ds, dl)
stopifnot(all(is.numeric(allargs)))
stopifnot(all(allargs > 0))
stopifnot(length(cs) == 2)
stopifnot(length(rho) == 2)
stopifnot(length(ds) == 2)
stopifnot(length(dl) == 2)
self$vmax <- vmax
self$alpha <- alpha
self$beta <- beta
self$cs <- cs
self$rho <- rho
self$ds <- ds
self$dl <- dl
}
create_pev_profile <- function(vmax, alpha, beta, cs, rho, ds, dl) {
allargs <- c(vmax, alpha, beta, cs, rho, ds, dl)
stopifnot(all(is.numeric(allargs)))
stopifnot(all(allargs > 0))
stopifnot(length(cs) == 2)
stopifnot(length(rho) == 2)
stopifnot(length(ds) == 2)
stopifnot(length(dl) == 2)
list(
vmax = vmax,
alpha = alpha,
beta = beta,
cs = cs,
rho = rho,
ds = ds,
dl = dl
)
)
}

#' @title RTS,S vaccine profile
#' @description Parameters for a primary dose of RTS,S for use with the
#' set_mass_pev and set_pev_epi functions
#' @export
rtss_profile <- PEVProfile$new(
rtss_profile <- create_pev_profile(
vmax = 0.93,
alpha = 0.74,
beta = 99.4,
Expand All @@ -66,7 +46,7 @@ rtss_profile <- PEVProfile$new(
#' @description Parameters for a booster dose of RTS,S for use with the
#' set_mass_pev and set_pev_epi functions
#' @export
rtss_booster_profile <- PEVProfile$new(
rtss_booster_profile <- create_pev_profile(
vmax = 0.93,
alpha = 0.74,
beta = 99.4,
Expand Down Expand Up @@ -135,12 +115,6 @@ set_pev_epi <- function(
stop('booster_timestep and booster_coverage and booster_profile does not align')
}

# Check that vaccine profiles are well formed
stopifnot(inherits(profile, 'PEVProfile'))
for (p in booster_profile) {
stopifnot(inherits(p, 'PEVProfile'))
}

# Index the new vaccine profiles
profile_list <- c(list(profile), booster_profile)
profile_indices <- seq_along(profile_list) + length(parameters$pev_profiles)
Expand Down Expand Up @@ -204,12 +178,6 @@ set_mass_pev <- function(
stop('booster_timestep, booster_coverage and booster_profile does not align')
}

# Check that vaccine profiles are well formed
stopifnot(inherits(profile, 'PEVProfile'))
for (p in booster_profile) {
stopifnot(inherits(p, 'PEVProfile'))
}

# Index the new vaccine profiles
profile_list <- c(list(profile), booster_profile)
profile_indices <- seq_along(profile_list) + length(parameters$pev_profiles)
Expand Down
82 changes: 0 additions & 82 deletions man/PEVProfile.Rd

This file was deleted.

27 changes: 27 additions & 0 deletions man/create_pev_profile.Rd

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

2 changes: 1 addition & 1 deletion man/get_correlation_parameters.Rd

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

2 changes: 1 addition & 1 deletion man/rtss_booster_profile.Rd

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

2 changes: 1 addition & 1 deletion man/rtss_profile.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ test_that('Mass efficacy listener works correctly', {
min_wait = 0,
booster_timestep = c(1, 6) * 30,
booster_coverage = c(.9, .8),
booster_profile = c(rtss_booster_profile, rtss_booster_profile)
booster_profile = list(rtss_booster_profile, rtss_booster_profile)
)

variables <- create_variables(parameters)
Expand Down Expand Up @@ -396,7 +396,7 @@ test_that('Mass dose events are not ruined by lazy evaluation', {
min_wait = 0,
booster_timestep = c(1, 6, 12) * 30,
booster_coverage = c(.9, .8, .7),
booster_profile = c(rtss_booster_profile, rtss_booster_profile, rtss_booster_profile)
booster_profile = list(rtss_booster_profile, rtss_booster_profile, rtss_booster_profile)
)

events <- create_events(parameters)
Expand Down

0 comments on commit 00d5383

Please sign in to comment.