# Roger Palay copyright 2016-01-31 # Saline, MI 48176 # ci_unknown <- function( s=1, n=30, x_bar=0, cl=0.95) { # try to avoid some common errors if( cl <=0 | cl>=1) {return("Confidence interval must be strictly between 0.0 and 1") } if( s < 0 ) {return("Sample standard deviation must be positive")} if( n <= 1 ) {return("Sample size needs to be more than 1")} if( as.integer(n) != n ) {return("Sample size must be a whole number")} # to get here we have some "reasonable" values samp_sd <- s/sqrt(n) t <- abs( qt( (1-cl)/2, n-1)) moe <- t*samp_sd low_end <- x_bar - moe high_end <- x_bar + moe result <- c(low_end, high_end, moe, samp_sd) names(result)<-c("CI Low","CI High", "MOE", "Std Error") return( result ) }