The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Introduction to cochranSize

library(cochranSize)

What is Cochran’s formula?

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:

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}}\]

Basic usage

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)

Known finite population

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):    323

Custom confidence level, margin of error, and expected proportion

cochran_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):    379

Using the underlying functions directly

n0 <- cochran_n(p = 0.5, e = 0.05, conf.level = 0.95)
n0
#> [1] 384.1459
cochran_n_adj(n0, N = 1000)
#> [1] 277.7335

Comparing confidence levels and margins of error

settings <- 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 16588

As 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.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.