Cochran’s formula estimates the minimum sample size needed for a survey to achieve a given margin of error at a given confidence level:
\[n_0 = \frac{z^2 \, p (1-p)}{e^2}\]
Where:
z is the z-score for the desired confidence level
(e.g. 1.96 for 95%)p is the estimated proportion of the population with
the attribute of interest (use 0.5 if unknown — the most conservative
assumption)e is the desired margin of error (e.g. 0.05 for
+/-5%)If the population size N is known and relatively small,
a finite population correction is applied:
\[n = \frac{n_0}{1 + \frac{n_0 - 1}{N}}\]
By default, cochran_sample_size() uses a 95% confidence
level and a 5% margin of error — but these are only defaults, not fixed
assumptions. Every parameter can be set explicitly:
cochran_sample_size(e = 0.05, conf.level = 0.95)
#> Cochran's Formula - Sample Size Calculation
#> --------------------------------------------
#> Confidence level: 95%
#> Margin of error (e): 0.050
#> Expected proportion (p): 0.500
#>
#> Unadjusted sample size (n0): 385
#> Population size (N): not supplied (treated as infinite)cochran_sample_size(N = 2000, e = 0.05, conf.level = 0.95)
#> Cochran's Formula - Sample Size Calculation
#> --------------------------------------------
#> Confidence level: 95%
#> Margin of error (e): 0.050
#> Expected proportion (p): 0.500
#>
#> Unadjusted sample size (n0): 385
#> Population size (N): 2000
#> Adjusted sample size (n): 323cochran_sample_size(N = 500, p = 0.3, e = 0.03, conf.level = 0.99)
#> Warning in cochran_n_adj(n0, N): `n0` exceeds `N`; the corrected sample size
#> will approach the full population size.
#> Cochran's Formula - Sample Size Calculation
#> --------------------------------------------
#> Confidence level: 99%
#> Margin of error (e): 0.030
#> Expected proportion (p): 0.300
#>
#> Unadjusted sample size (n0): 1549
#> Population size (N): 500
#> Adjusted sample size (n): 379settings <- expand.grid(
conf.level = c(0.90, 0.95, 0.99),
e = c(0.05, 0.03, 0.01)
)
settings$n0 <- mapply(cochran_n, e = settings$e, conf.level = settings$conf.level)
settings$n0 <- ceiling(settings$n0)
settings[order(settings$conf.level, -settings$e), ]
#> conf.level e n0
#> 1 0.90 0.05 271
#> 4 0.90 0.03 752
#> 7 0.90 0.01 6764
#> 2 0.95 0.05 385
#> 5 0.95 0.03 1068
#> 8 0.95 0.01 9604
#> 3 0.99 0.05 664
#> 6 0.99 0.03 1844
#> 9 0.99 0.01 16588As the table shows, tightening the margin of error or raising the confidence level both increase the required sample size — margin of error has the larger effect, since it is squared in the denominator.