R/utils.R

Defines functions errors_x_p

errors_x_p <- function(x, p)  {

  if(length(x) != length(p)) {
    stop("The vectors x and p must be the same length.")
  }

  if(sum(x < 0) >= 1) {
    stop("The vector x cannot contain negative counts.")
  }

  if(sum(x%%1 == 0) < length(x)) {
    stop("The vector x cannot contain fractions. Counts must be expressed as whole numbers.")
  }

  if(sum(p < 0) >= 1) {
    stop("The vector p cannot contain negative probabilities.")
  }

  if(abs(sum(p) - 1) > sqrt(.Machine$double.eps)) {
    stop("The probabilities in vector p must sum to one.")
  }
}
josh-mc/discretefit documentation built on Jan. 28, 2022, 5:39 p.m.