Skip to content

Commit 68c8291

Browse files
apulsiphergvegayon
andauthored
Create input param type checks for models (#80)
* Add input param checks and corresponding tests for ModelSIRCONN * Add input param checks and corresponding tests for ModelSIRD * Move arg check functions to separate file * Add arg checks for ModelDiffNet * Add input param checks for ModelSEIR and ModelSEIRD * Add input param checks for ModelSEIRCONN * Fix test in test-seirconn.R * Add input param checks for ModelSEIRCONN * Add input param checks to ModelSEIRMixing * Add input param checks to ModelSIR * Add input param checks ModelSIRDCONN * Add input param checks to ModelSIRLogit * Add input param checks to ModelSIRMixing * Add input param checks for ModelSIS * Add input param checks to ModelSISD * Add input param checks to ModelSURV * Clean up arg-checks.R * Bump R patch version number * Remove stopif_na from R/arg-checks.R Co-authored-by: George G. Vega Yon <[email protected]> --------- Co-authored-by: George G. Vega Yon <[email protected]>
1 parent 53a6a8b commit 68c8291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1997
-202
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: epiworldR
22
Type: Package
33
Title: Fast Agent-Based Epi Models
4-
Version: 0.6.1.0
4+
Version: 0.6.1.1
55
Depends: R (>= 4.1.0)
66
Authors@R: c(
77
person(given="George", family="Vega Yon", role=c("aut"),

R/LFMCMC.R

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
stopifnot_lfmcmc <- function(x) {
2-
# Catching the value of x
3-
nam <- match.call()$x
4-
5-
if (!inherits(x, "epiworld_lfmcmc"))
6-
stop(nam, " must be an object of class epiworld_lfmcmc")
7-
8-
}
9-
10-
111
#' Likelihood-Free Markhov Chain Monte Carlo (LFMCMC)
122
#'
133
#' @aliases epiworld_lfmcmc

R/ModelDiffNet.R

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ ModelDiffNet <- function(
6464
data_cols = 1L:ncol(data),
6565
params = vector("double")
6666
) {
67+
# Check input params
68+
stopifnot_string(name)
69+
stopifnot_double(prevalence)
70+
stopifnot_double(prob_adopt)
71+
stopifnot_bool(normalize_exposure)
72+
stopifany_na(data)
73+
stopifnot_numvector(data_cols)
74+
stopifnot_numvector(params)
6775

6876
if (length(data) == 0L)
6977
data_cols <- vector("integer")

R/ModelSEIR.R

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ ModelSEIR <- function(
4545
incubation_days,
4646
recovery_rate
4747
) {
48+
# Check input parameters
49+
stopifnot_string(name)
50+
stopifnot_double(prevalence)
51+
stopifnot_double(transmission_rate)
52+
stopifnot_double(incubation_days)
53+
stopifnot_double(recovery_rate)
4854

4955
structure(
5056
ModelSEIR_cpp(name, prevalence, transmission_rate, incubation_days, recovery_rate),

R/ModelSEIRCONN.R

+15-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,22 @@
4949
#' plot(model_seirconn)
5050
#' @seealso epiworld-methods
5151
ModelSEIRCONN <- function(
52-
name, n, prevalence, contact_rate, transmission_rate,
53-
incubation_days, recovery_rate
52+
name,
53+
n,
54+
prevalence,
55+
contact_rate,
56+
transmission_rate,
57+
incubation_days,
58+
recovery_rate
5459
) {
60+
# Check input parameters
61+
stopifnot_string(name)
62+
stopifnot_int(n)
63+
stopifnot_double(prevalence)
64+
stopifnot_double(contact_rate)
65+
stopifnot_double(transmission_rate)
66+
stopifnot_double(incubation_days)
67+
stopifnot_double(recovery_rate)
5568

5669
structure(
5770
ModelSEIRCONN_cpp(name, n, prevalence, contact_rate,

R/ModelSEIRD.R

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ ModelSEIRD <- function(
4949
recovery_rate,
5050
death_rate
5151
) {
52+
# Check input parameters
53+
stopifnot_string(name)
54+
stopifnot_double(prevalence)
55+
stopifnot_double(transmission_rate)
56+
stopifnot_double(incubation_days)
57+
stopifnot_double(recovery_rate)
58+
stopifnot_double(death_rate)
5259

5360
structure(
5461
ModelSEIRD_cpp(

R/ModelSEIRDCONN.R

+17-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,24 @@
6161
#' plot(model_seirdconn)
6262
#' @seealso epiworld-methods
6363
ModelSEIRDCONN <- function(
64-
name, n, prevalence, contact_rate, transmission_rate,
65-
incubation_days, recovery_rate, death_rate
64+
name,
65+
n,
66+
prevalence,
67+
contact_rate,
68+
transmission_rate,
69+
incubation_days,
70+
recovery_rate,
71+
death_rate
6672
) {
73+
# Check input parameters
74+
stopifnot_string(name)
75+
stopifnot_int(n)
76+
stopifnot_double(prevalence)
77+
stopifnot_double(contact_rate)
78+
stopifnot_double(transmission_rate)
79+
stopifnot_double(incubation_days)
80+
stopifnot_double(recovery_rate)
81+
stopifnot_double(death_rate)
6782

6883
structure(
6984
ModelSEIRDCONN_cpp(name, n, prevalence, contact_rate,

R/ModelSEIRMixing.R

+17-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,24 @@
6666
#'
6767
#' @seealso epiworld-methods
6868
ModelSEIRMixing <- function(
69-
name, n, prevalence, contact_rate, transmission_rate,
70-
incubation_days, recovery_rate, contact_matrix
69+
name,
70+
n,
71+
prevalence,
72+
contact_rate,
73+
transmission_rate,
74+
incubation_days,
75+
recovery_rate,
76+
contact_matrix
7177
) {
78+
# Check input parameters
79+
stopifnot_string(name)
80+
stopifnot_int(n)
81+
stopifnot_double(prevalence)
82+
stopifnot_double(contact_rate)
83+
stopifnot_double(transmission_rate)
84+
stopifnot_double(incubation_days)
85+
stopifnot_double(recovery_rate)
86+
stopifany_na(contact_matrix)
7287

7388
structure(
7489
ModelSEIRMixing_cpp(

R/ModelSIR.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@
4141
#' plot(model_sir)
4242
#' @seealso epiworld-methods
4343
ModelSIR <- function(
44-
name, prevalence, transmission_rate, recovery_rate
44+
name,
45+
prevalence,
46+
transmission_rate,
47+
recovery_rate
4548
) {
49+
# Check input parameters
50+
stopifnot_string(name)
51+
stopifnot_double(prevalence)
52+
stopifnot_double(transmission_rate)
53+
stopifnot_double(recovery_rate)
4654

4755
structure(
4856
ModelSIR_cpp(name, prevalence, transmission_rate, recovery_rate),

R/ModelSIRCONN.R

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
ModelSIRCONN <- function(
3838
name, n, prevalence, contact_rate, transmission_rate, recovery_rate
3939
) {
40+
# Check inputs
41+
stopifnot_string(name)
42+
stopifnot_int(n)
43+
stopifnot_double(prevalence)
44+
stopifnot_double(contact_rate)
45+
stopifnot_double(transmission_rate)
46+
stopifnot_double(recovery_rate)
4047

4148
structure(
4249
ModelSIRCONN_cpp(name, n, prevalence, contact_rate,

R/ModelSIRD.R

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
ModelSIRD <- function(
5151
name, prevalence, transmission_rate, recovery_rate, death_rate
5252
) {
53+
# Check inputs
54+
stopifnot_string(name)
55+
stopifnot_double(prevalence)
56+
stopifnot_double(transmission_rate)
57+
stopifnot_double(recovery_rate)
58+
stopifnot_double(death_rate)
5359

5460
structure(
5561
ModelSIRD_cpp(name, prevalence, transmission_rate, recovery_rate, death_rate),

R/ModelSIRDCONN.R

+14-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@
3838
#' plot(model_sirdconn, main = "SIRDCONN Model")
3939
#' @seealso epiworld-methods
4040
ModelSIRDCONN <- function(
41-
name, n, prevalence, contact_rate, transmission_rate, recovery_rate,
41+
name,
42+
n,
43+
prevalence,
44+
contact_rate,
45+
transmission_rate,
46+
recovery_rate,
4247
death_rate
4348
) {
49+
# Check input parameters
50+
stopifnot_string(name)
51+
stopifnot_int(n)
52+
stopifnot_double(prevalence)
53+
stopifnot_double(contact_rate)
54+
stopifnot_double(transmission_rate)
55+
stopifnot_double(recovery_rate)
56+
stopifnot_double(death_rate)
4457

4558
structure(
4659
ModelSIRDCONN_cpp(name, n, prevalence, contact_rate,

R/ModelSIRLogit.R

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ ModelSIRLogit <- function(
7272
recovery_rate,
7373
prevalence
7474
) {
75+
# Check input parameters
76+
stopifnot_string(vname)
77+
stopifany_na(data)
78+
stopifnot_numvector(coefs_infect)
79+
stopifnot_numvector(coefs_recover)
80+
stopifnot_numvector(coef_infect_cols)
81+
stopifnot_numvector(coef_recover_cols)
82+
stopifnot_double(prob_infection)
83+
stopifnot_double(recovery_rate)
84+
stopifnot_double(prevalence)
7585

7686
structure(
7787
ModelSIRLogit_cpp(

R/ModelSIRMixing.R

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@
6464
#'
6565
#' @seealso epiworld-methods
6666
ModelSIRMixing <- function(
67-
name, n, prevalence, contact_rate, transmission_rate, recovery_rate,
67+
name,
68+
n,
69+
prevalence,
70+
contact_rate,
71+
transmission_rate,
72+
recovery_rate,
6873
contact_matrix
6974
) {
75+
# Check input parameters
76+
stopifnot_string(name)
77+
stopifnot_int(n)
78+
stopifnot_double(prevalence)
79+
stopifnot_double(contact_rate)
80+
stopifnot_double(transmission_rate)
81+
stopifnot_double(recovery_rate)
82+
stopifany_na(contact_matrix)
7083

7184
structure(
7285
ModelSIRMixing_cpp(

R/ModelSIS.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@
3636
#'
3737
#' @seealso epiworld-methods
3838
ModelSIS <- function(
39-
name, prevalence, transmission_rate, recovery_rate) {
39+
name,
40+
prevalence,
41+
transmission_rate,
42+
recovery_rate) {
43+
# Check input parameters
44+
stopifnot_string(name)
45+
stopifnot_double(prevalence)
46+
stopifnot_double(transmission_rate)
47+
stopifnot_double(recovery_rate)
4048

4149
structure(
4250
ModelSIS_cpp(name, prevalence, transmission_rate, recovery_rate),

R/ModelSISD.R

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@
4242
#'
4343
#' @seealso epiworld-methods
4444
ModelSISD <- function(
45-
name, prevalence, transmission_rate, recovery_rate, death_rate) {
45+
name,
46+
prevalence,
47+
transmission_rate,
48+
recovery_rate,
49+
death_rate) {
50+
# Check input parameters
51+
stopifnot_string(name)
52+
stopifnot_double(prevalence)
53+
stopifnot_double(transmission_rate)
54+
stopifnot_double(recovery_rate)
55+
stopifnot_double(death_rate)
4656

4757
structure(
4858
ModelSISD_cpp(name, prevalence, transmission_rate, recovery_rate, death_rate),

R/ModelSURV.R

+27-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,34 @@
6363
#'
6464
#' @seealso epiworld-methods
6565
ModelSURV <- function(
66-
name, prevalence, efficacy_vax, latent_period, infect_period, prob_symptoms,
67-
prop_vaccinated, prop_vax_redux_transm, prop_vax_redux_infect,
68-
surveillance_prob, transmission_rate, prob_death, prob_noreinfect
66+
name,
67+
prevalence,
68+
efficacy_vax,
69+
latent_period,
70+
infect_period,
71+
prob_symptoms,
72+
prop_vaccinated,
73+
prop_vax_redux_transm,
74+
prop_vax_redux_infect,
75+
surveillance_prob,
76+
transmission_rate,
77+
prob_death,
78+
prob_noreinfect
6979
) {
80+
# Check input parameters
81+
stopifnot_string(name)
82+
stopifnot_double(prevalence)
83+
stopifnot_double(efficacy_vax)
84+
stopifnot_double(latent_period)
85+
stopifnot_double(infect_period)
86+
stopifnot_double(prob_symptoms)
87+
stopifnot_double(prop_vaccinated)
88+
stopifnot_double(prop_vax_redux_transm)
89+
stopifnot_double(prop_vax_redux_infect)
90+
stopifnot_double(surveillance_prob)
91+
stopifnot_double(transmission_rate)
92+
stopifnot_double(prob_death)
93+
stopifnot_double(prob_noreinfect)
7094

7195
structure(
7296
ModelSURV_cpp(name, prevalence, efficacy_vax, latent_period, infect_period,

R/agents.R

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
stopifnot_agent <- function(x) {
2-
if (!inherits(x, "epiworld_agent"))
3-
stop("x must be an object of class epiworld_agent")
4-
}
5-
61
#' Load agents to a model
72
#'
83
#' These functions provide access to the network of the model. The network is

0 commit comments

Comments
 (0)