#------------------------------------------------------------------# #EXAMPLE 1 #Sample size determination for estimating the population mean # Population size not known #sampling error E <- 5 #prelimary estimate of sigma sigma_est <- 25 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size n <- ((z025*sigma_est)/E)^2 n # Population size known #sampling error E <- 5 #prelimary estimate of sigma sigma_est <- 25 #population size N <- 500 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size num <- N*(z025*sigma_est)^2 dem <- ((N-1)*(E^2))+(z025*sigma_est)^2 n <- num/dem n #-------------------------------------------------------------------# #EXAMPLE 2 #Sample size determination for estimating the population proportion # Population size not known #sampling error E <- 0.01 #prelimary estimate of pi pi_est <- 0.5 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size n <- (z025*(sqrt(pi_est*(1-pi_est)))/E)^2 n # Population size known #sampling error E <- 0.01 #prelimary estimate of pi pi_est <- 0.5 #population size N <- 12350 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size n0 <- (z025*(sqrt(pi_est*(1-pi_est)))/E)^2 n0 n <- n0/(1+(n0-1)/N) n #-------------------------------------------------------------------# #EXAMPLE 3 #Sample size determination for estimating the population variance #sampling error E <- 0.1 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size n <- (0.5*(z025/E)^2) +1 n #--------------------------------------------------------------------# #EXAMPLE 4 #Sample size determination for estimating the population proportion #sampling error E <- 0.04 #prelimary estimate of pi pi_est <- 0.5 #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sample size n <- (z025*(sqrt(pi_est*(1-pi_est)))/E)^2 n #Given the sample size obtain the sampling error #budget budget <- 2400 #cost cost <- 10 #sample size n <- budget/cost n #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #sampling error E <- z025 * sqrt((pi_est*(1-pi_est))/n) E #--------------------------------------------------------------------#