R/intconf.R

#' Compute the confidence interval
#'
#' Function to compute the confidence interval from a numeric vector.
#'
#' @param x A numeric vector
#'
#' @return
#' \code{intconf} returns an object of class "lifertableCI".
#' An object of class "lifertableCI" is a list containing the following components:
#'
#' \item{Lower Limit}{ Lower limit of the confidence interval.}
#' \item{Mean}{ Vector average.}
#' \item{Upper Limit}{ Upper limit of the confidence interval.}
#' \item{Var}{ Vector variance.}
#'
#' @noRd
#'
intconf <-  function (x) {
  if (length(unique(x)) == 1 ) {
    ci <- c("Lower Limit" = 0, Mean = mean(x), "Upper Limit" = 0, Var = stats::var(x) )
  } else {
    a <- stats::t.test(x)
    ic <- a$conf.int
    ci <- c("Lower Limit" = min(ic), Mean = mean(x), "Upper Limit" = max(ic), Var = stats::var(x))
  }
  class(ci) <- "lifertableCI"
  return(ci)
}

Try the Lifertable package in your browser

Any scripts or data that you put into this service are public.

Lifertable documentation built on April 12, 2025, 1:43 a.m.