23.6 Sample Size Determination

The appropriate sample size depends on the margin of error, confidence level, and population variability. A commonly used formula for estimating the required sample size for a proportion is:

\[ n = \frac{Z^2 p (1 - p)}{E^2} \] where:

  • \(Z\) is the Z-score corresponding to the confidence level

  • \(p\) is the estimated proportion

  • \(E\) is the margin of error

z <- qnorm(0.975)  # 95% confidence level
p <- 0.5  # Estimated proportion
E <- 0.05  # 5% margin of error
n <- (z^2 * p * (1 - p)) / (E^2)
ceiling(n)  # Round up to nearest integer
#> [1] 385