#---------------------------------------------------------------------# #EXAMPLE 1 # Confidence interval estimate of the population mean # when the population standard deviation is known #sample size n <- 60 #sample mean xbar <- 6.5 #population standard deviation sigma <- 4 #97.5th percentile of standard normal distribution z025 <- qnorm(.975) z025 #standard error se <- sigma/sqrt(n) se #Lower confidence limit LCL <- xbar - (z025 * se) LCL #Upper confidence limit UCL <- xbar + (z025 * se) UCL #95% confidence interval estimate of mean cbind(LCL, UCL) #----------------------------------------------------------------------# #EXAMPLE 2 # Confidence interval estimate of the population mean # when the population standard deviation is unknown #sample size n <- 8 #create vector of numbers x <- c(3.5, 4.2, 5.3, 4.7, 3.4, 4.6, 4.9, 3.7) #sample mean xbar <- mean(x) #sample standard deviation s <- sd(x) #97.5th percentile of the t-distribution with 7 degrees of freedom t025_7 <- qt(.975,7) t025_7 #standard error se <- (s/sqrt(n)) se #Lower confidence limit LCL <- xbar - (t025_7 * se) LCL #Upper confidence limit UCL <- xbar + (t025_7 * se) UCL #95% confidence interval estimate of mean cbind(LCL, UCL) #-----------------------------------------------------------------------# #EXAMPLE 3 # Confidence interval estimate of the population proportion #sample size n <- 400 # number of defective component x <- 60 #sample proportion p <- x/n p #99.5th percentile of the standard normal distribution z005 <- qnorm(.995) z005 #standard error se <- sqrt(p*(1-p)/n) se #Lower confidence limit LCL <- p - (z005 *se) LCL #Upper confidence limit UCL <- p + (z005 *se) UCL #99% confidence interval estimate of proportion cbind(LCL, UCL) #-----------------------------------------------------------------------# #EXAMPLE 4 # Confidence interval estimate of the population variance #sample size n <- 10 #create vector of numbers x <- c(20.5, 19.8, 21.1, 20.2, 18.9, 19.6, 20.7, 20.1, 19.8, 19.0) #sample standard deviation s <- sd(x) s #95th percentile of the chi-square distribution with 9 degrees of freedom chi95_9 <- qchisq(.95,9) chi95_9 #5th percentile of the chi-square distribution with 9 degrees of freedom chi5_9 <- qchisq(.05,9) chi5_9 #Lower confidence limit for variance LCL <- ((n-1)*s^2)/chi95_9 LCL #Upper confidence limit for variance UCL <- ((n-1)*s^2)/chi5_9 UCL #90% confidence limit estimate of variance cbind(LCL,UCL) #90% confidence limit estimate of standard deviation cbind(sqrt(LCL), sqrt(UCL)) #-----------------------------------------------------------------------#