R/sdConfInt.R In userfriendlyscience: Quantitative Analysis Made Accessible

Documented in print.sdConfIntsdConfInt

```### This function generates a confidence level for a standard deviation
### https://www.wolframalpha.com/input/?i=confidence+interval+for+a+standard+deviation&lk=3
sdConfInt <- function(vector=NULL, sd=NULL, n=NULL, conf.level=.95) {
if (is.null(sd) & is.null(n)) {
if (is.null(vector)) {
stop("Please specify either vector, or sd and n!");
}
sd <- sd(vector);
n <- length(vector);
}
res <- list();
res\$input <- list(vector=vector, sd=sd, n=n, conf.level=conf.level);
res\$intermediate <- list(alpha = 1-conf.level);
res\$intermediate\$chisq.bound.lo <- qchisq(((1-res\$intermediate\$alpha)/2), n-1);
res\$intermediate\$chisq.bound.hi <- qchisq(res\$intermediate\$alpha/2, n-1);
ci.lo <- sqrt(((n-1)*sd^2)/res\$intermediate\$chisq.bound.lo);
ci.hi <- sqrt(((n-1)*sd^2)/res\$intermediate\$chisq.bound.hi);
res\$output <- list(ci = c(ci.lo, ci.hi));
class(res) <- 'sdConfInt';
return(res);
}

print.sdConfInt <- function(x, digits=2, ...) {
print(x\$output\$ci, digits=digits, ...);
}
```

Try the userfriendlyscience package in your browser

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

userfriendlyscience documentation built on May 2, 2019, 1:09 p.m.