R/CI95se.R

Defines functions CI95se

Documented in CI95se

#' Calculate SEM 95% Confidence Intervals
#'
#' Uses standard error (of the mean) calculation to
#' determine the 95% CI of a vector of data.
#' Does not use a bootstrapping of empirical data,
#' but the Gaussian approximation.
#'
#' @param x Numeric. A vector of data to calculate the CI95.
#' @return A numeric vector with 3 named entries:
#' \item{lower}{the lower CI95.}
#' \item{mean}{the arithmetic mean.}
#' \item{upper}{the upper CI95.}
#' @author Stu Field
#' @seealso [bootstrap()] for CI95 via bootstrapping.
#' @examples
#' CI95se(rnorm(100))
#' @importFrom stats sd
#' @export
CI95se <- function(x) {
  sem   <- stats::sd(x) / sqrt(length(x))
	shift <- 1.96 * sem
  c(lower = mean(x) - shift, mean = mean(x), upper = mean(x) + shift)
}
stufield/stutils documentation built on March 30, 2022, 3:06 p.m.