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/id.R | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'R/id.R') diff --git a/R/id.R b/R/id.R index 5277591..c7c28d3 100644 --- a/R/id.R +++ b/R/id.R @@ -41,5 +41,12 @@ #' # Obtain R0 when the serial distribution has a mean of three days. #' id(cases, mu = 3 / 7) id <- function(cases, mu) { + validate_cases(cases, min_length = 1, min_count = 1) + if (!is_real(mu) || mu <= 0) { + stop("The serial interval (`mu`) must be a number greater than 0.", + call. = FALSE + ) + } + exp(sum((log(cases) * mu) / seq_along(cases)) / length(cases)) } -- cgit v1.2.3