R/CI.R

Defines functions CI

Documented in CI

#' Confidence Interval
#' 
#' Calculates the confidence interval of a vector of data.
#' 
#' @keywords univar
#' 
#' @param x a vector of data
#' @param ci the confidence interval to be calculated
#' 
#' @return
#' \item{upper}{Upper bound of interval.}
#' \item{mean}{Mean of data.}
#' \item{lower}{Lower bound of interval.}
#' 
#' @export
#' 
#' @examples
#' CI(rnorm(100))
#' 
CI <-
function(x,ci=.95) {
  a<-mean(x)
  s<-sd(x)
  n<-length(x)
  error<-qt(ci+(1-ci)/2,df=n-1)*s/sqrt(n)
  return(c(upper=a+error,mean=a,lower=a-error))
}

Try the Rmisc package in your browser

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

Rmisc documentation built on May 2, 2022, 5:05 p.m.