R/check_PPC_binom.R

Defines functions check_PPC_binom

Documented in check_PPC_binom

#' Argument Check: Binomial Model
#'
#' Checks if the arguments of the [PPC_binom()] function are correctly specified.
#'
#' @usage check_PPC_binom(
#'   n,
#'   alpha_1,
#'   beta_1,
#'   alpha_2,
#'   beta_2,
#'   alpha_D,
#'   beta_D,
#'   xi,
#'   v,
#'   q,
#'   M,
#'   plot
#' )
#'
#' @param n The sample size.
#' @param alpha_1,beta_1 The parameters of the first beta prior.
#' @param alpha_2,beta_2 The parameters of the second beta prior.
#' @param alpha_D,beta_D The parameters of the design beta prior.
#' @param xi A constant used to compute the predictive probability.
#' @param v A constant used to determine the optimal sample size.
#' @param q The order of the Wasserstein distance.
#' @param M The number of Monte Carlo replications.
#' @param plot Logical. Should a plot be displayed?
#'
#' @return An error message.
#'
#' @note This is an internal function.
#'
#' @author Michele Cianfriglia \email{michele.cianfriglia@@uniroma1.it}
#'
#' @keywords internal
#'
#' @importFrom crayon italic

check_PPC_binom <- function(n, alpha_1, beta_1, alpha_2, beta_2, alpha_D, beta_D, xi, v, q, M, plot) {

  if (anyNA(n)) {
    stop(paste(italic("n"), "cannot contain missing values or NaNs."), call. = FALSE)
  }

  if (any(!is.vector(n), min(n) <= 0, any(n != floor(n)))) {
    stop(paste(italic("n"), "must be a vector of positive integers."), call. = FALSE)
  }

  if (is.unsorted(x = n, strictly = TRUE)) {
    stop(paste(italic("n"), "must be strictly increasing."), call. = FALSE)
  }

  if (any(!number(alpha_1), is.infinite(alpha_1), alpha_1 < 0, !number(beta_1), is.infinite(beta_1), beta_1 < 0)) {
    stop(paste(italic("alpha_1"), "and", italic("beta_1"), "must be non-negative values."), call. = FALSE)
  }

  if (any(!number(alpha_2), is.infinite(alpha_2), alpha_2 < 0, !number(beta_2), is.infinite(beta_2), beta_2 < 0)) {
    stop(paste(italic("alpha_2"), "and", italic("beta_2"), "must be non-negative values."), call. = FALSE)
  }

  if (any(!number(alpha_D), is.infinite(alpha_D), alpha_D <= 0, !number(beta_D), is.infinite(beta_D), beta_D <= 0)) {
    stop(paste(italic("alpha_D"), "and", italic("beta_D"), "must be positive values."), call. = FALSE)
  }

  if (any(!number(xi), is.infinite(xi), xi <= 0)) {
    stop(paste(italic("xi"), "must be a positive value."), call. = FALSE)
  }

  if (any(!number(v), v <= 0, v >= 1)) {
    stop(paste(italic("v"), "must be a value in (0, 1)."), call. = FALSE)
  }

  if (any(!number(q), is.infinite(q), q < 1)) {
    stop(paste(italic("q"), "must be a value in [1, Inf)."), call. = FALSE)
  }

  if (any(!number(x = M, int = TRUE), is.infinite(M), M <= 0)) {
    stop(paste(italic("M"), "must be a positive integer."), call. = FALSE)
  }

  if (!boolean(plot)) {
    stop(paste(italic("plot"), "must be TRUE or FALSE."), call. = FALSE)
  }

}
michelecianfriglia/SampleSizeWass documentation built on Feb. 28, 2023, 8:56 a.m.