R/lqas.R

Defines functions applyLQAS

Documented in applyLQAS

################################################################################
#
#' Lot Quality Assurance Sampling (LQAS) algorithm using a two standard, three
#' class classification scheme.
#' 
#' @param x A numeric vector
#' @param upper A numeric value between 0 to 1 specifying the upper standard to
#'     use for classifying. Default is 0.8
#' @param lower A numeric value between 0 to 1 specifying the lower standard to
#'     use for classifying. Default is 0.5
#' @return A character vector providing corresponding classes. Can be either
#'     "High", "Moderate", "Low".
#' @examples
#' #
#' 
#' @export
#'
#
################################################################################

applyLQAS <- function(x,
                      upper = 0.8, 
                      lower = 0.5) {

  cases <- sum(x, na.rm = TRUE)
  total <- length(x)
  
  d1 <- floor(total * lower)
  d2 <- floor(total * upper)
  
  class <- ifelse(cases <= d1, "Low",
             ifelse(cases > d2, "High", "Moderate"))
  
  return(class)
}
validmeasures/wsup documentation built on Dec. 16, 2019, 4:50 a.m.