R/check_PEC_norm.R

Defines functions check_PEC_norm

Documented in check_PEC_norm

#' Argument Check: Normal Model
#'
#' Checks if the arguments of the [PEC_norm()] function are correctly specified.
#'
#' @usage check_PEC_norm(
#'   n,
#'   theta_1,
#'   n_1,
#'   theta_2,
#'   n_2,
#'   theta_D,
#'   n_D,
#'   sigma,
#'   v,
#'   plot
#' )
#'
#' @param n The sample size.
#' @param theta_1,n_1 The parameters of the first normal prior.
#' @param theta_2,n_2 The parameters of the second normal prior.
#' @param theta_D,n_D The parameters of the design normal prior.
#' @param sigma A constant used to define the variance of the priors.
#' @param v A constant used to determine the optimal sample size.
#' @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_PEC_norm <- function(n, theta_1, n_1, theta_2, n_2, theta_D, n_D, sigma, v, 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(theta_1), is.infinite(theta_1))) {
    stop(paste(italic("theta_1"), "must be a finite value."), call. = FALSE)
  }

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

  if (any(!number(theta_2), is.infinite(theta_2))) {
    stop(paste(italic("theta_2"), "must be a finite value."), call. = FALSE)
  }

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

  if (any(!number(theta_D), is.infinite(theta_D))) {
    stop(paste(italic("theta_D"), "must be a finite value."), call. = FALSE)
  }

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

  if (any(!number(sigma), is.infinite(sigma), sigma <= 0)) {
    stop(paste(italic("sigma"), "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 (!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.