]> nmode's Git Repositories - Rnaught/blobdiff - R/seq_bayes.R
Update about.html
[Rnaught] / R / seq_bayes.R
index d486d2b8e439e34436fb3919345a56c79066f543..b25d273276930293c083a988901db7517054c781 100644 (file)
 #' # Note that the following always holds:
 #' estimate == sum(posterior$supp * posterior$pmf)
 seq_bayes <- function(cases, mu, kappa = 20, post = 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.")
-    }
-    cases <- cases[times]
-  } else {
-    times <- seq_along(cases)
+  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
+    )
+  }
+
+  times <- which(cases > 0)
+  if (length(times) < 2) {
+    stop("Case counts must contain at least two positive integers.",
+      call. = FALSE
+    )
   }
+  cases <- cases[times]
 
   support <- seq(0, kappa, 0.01)
   tau <- diff(times)