R/sigmaCI.R

Defines functions sigmaCI

Documented in sigmaCI

#' Confidence interval for the population standard deviation
#'
#' @description
#' A function 'sigmaCI()' is used to compute a confidence interval of the population standard deviation
#' when given a numeric vector
#'
#' @param x    a numeric vector
#' @param conf.level   a confidence level, default is \code{0.95}; the user can change to \code{0.90} or otherwise
#'
#' @importFrom stats qchisq sd
#'
#' @returns  a confidence interval of the population standard deviation
#' @export
#'
#' @references
#' Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press.
#' <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
#'
#' @examples
#' heigth <- c(155.5, 165.5, 170, 164.5, 180, 162, 173, 158.5, 168.5, 175, 164.5, 167)
#' sigmaCI(x=heigth,conf.level = 0.90)
#'
sigmaCI <- function(x,conf.level=0.95){
  n <- length(x)
  s <- sd(x)
  ci <- conf.level
  alpdiv2 <- (1-ci)/2
  v <- n-1
  q <- qchisq(c(alpdiv2,1-alpdiv2),df=v)
  vCI <- c( (n-1)*(s^2)/q[2], (n-1)*(s^2)/q[1] )
  sCI <- sqrt(vCI)
  return(sCI)
}

Try the Mychisq package in your browser

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

Mychisq documentation built on June 22, 2026, 9:08 a.m.