R/lower.R

Defines functions lower

Documented in lower

#' Lower Credible Limit
#'
#' Calculates the quantile-based lower credible limit.
#'
#' By default it returns the 95% credible limit which
#' corresponds to the 2.5% quantile.
#'
#' @inheritParams params
#' @param x A numeric vector of MCMC values.
#' @return A number.
#' @family summary
#' @export
#' @examples
#' lower(as.numeric(0:100))
lower <- function(x, conf_level = 0.95, na_rm = FALSE) {
  chk_numeric(x)
  chk_number(conf_level)
  chk_range(conf_level)

  if(anyNA(x)) {
    if(vld_false(na_rm)) return(NA_real_)
    x <- as.vector(x)
    x <- x[!is.na(x)]
  }
  if (!length(x)) {
    return(NA_real_)
  }

  lower <- (1 - conf_level) / 2
  x <- stats::quantile(x, lower)
  x <- unname(x)
  x
}
poissonconsulting/extras documentation built on Jan. 18, 2024, 1:18 a.m.