]> nmode's Git Repositories - Rnaught/blobdiff - R/idea.R
Add input validation to estimators
[Rnaught] / R / idea.R
index 14ba838bc5e363244d6b0f7793dfda3fe1cafe36..dad42207677334f59ec265b061c2c379bef5bd8e 100644 (file)
--- a/R/idea.R
+++ b/R/idea.R
 #' # Obtain R0 when the serial distribution has a mean of three days.
 #' idea(cases, mu = 3 / 7)
 idea <- function(cases, mu) {
 #' # Obtain R0 when the serial distribution has a mean of three days.
 #' idea(cases, mu = 3 / 7)
 idea <- function(cases, mu) {
+  validate_cases(cases, min_length = 2, min_count = 1)
+  if (!is_real(mu) || mu <= 0) {
+    stop("The serial interval (`mu`) must be a number greater than 0.",
+      call. = FALSE
+    )
+  }
+
   s <- seq_along(cases) / mu
 
   x1 <- sum(s)
   s <- seq_along(cases) / mu
 
   x1 <- sum(s)