From 94b4dcd37e662eb1e525dc241817c8dd5d4681fc Mon Sep 17 00:00:00 2001 From: Naeem Model Date: Sat, 2 Nov 2024 18:13:28 +0000 Subject: Add input validation to estimators --- R/seq_bayes.R | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'R/seq_bayes.R') diff --git a/R/seq_bayes.R b/R/seq_bayes.R index d486d2b..ccc9a41 100644 --- a/R/seq_bayes.R +++ b/R/seq_bayes.R @@ -84,10 +84,31 @@ #' # Note that the following always holds: #' estimate == sum(posterior$supp * posterior$pmf) seq_bayes <- function(cases, mu, kappa = 20, post = FALSE) { + validate_cases(cases, min_length = 2, min_count = 0) + if (!is_real(mu) || mu <= 0) { + stop("The serial interval (`mu`) must be a number greater than 0.", + call. = FALSE + ) + } + if (!is_real(kappa) || kappa < 1) { + stop( + paste("The largest value of the uniform prior (`kappa`)", + "must be a number greater than or equal to 1." + ), call. = FALSE + ) + } + if (!identical(post, TRUE) && !identical(post, FALSE)) { + stop("The posterior flag (`post`) must be set to `TRUE` or `FALSE`.", + call. = FALSE + ) + } + if (any(cases == 0)) { times <- which(cases > 0) if (length(times) < 2) { - stop("Vector of case counts must contain at least two positive integers.") + stop("Case counts must contain at least two positive integers.", + call. = FALSE + ) } cases <- cases[times] } else { -- cgit v1.2.3