Sample Size Calculation Using Cochran's Formula

Provides functions to calculate the minimum required sample size for surveys and studies using Cochran's formula, including the finite population correction. Cochran's formula is a standard method in survey methodology for determining sample size based on a desired margin of error, confidence level, and (optionally) known population size. All parameters (margin of error, confidence level, and expected proportion) are fully adjustable by the user rather than fixed to any convention.


cochranSize

An R package for calculating survey/study sample sizes using Cochran's formula, with optional finite population correction.

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:

n0 = z^2 * p * (1 - p) / e^2

Where:

  • z = the z-score for the desired confidence level (e.g. 1.96 for 95%)
  • p = estimated proportion of the population with the attribute of interest (use 0.5 if unknown — this is the most conservative assumption)
  • e = 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 = n0 / (1 + (n0 - 1) / N)

All three inputs — confidence level, margin of error, and expected proportion — are fully adjustable by the user. The defaults (95% confidence, 5% margin of error, p = 0.5) are just common conventions, not fixed assumptions.

Installation

# From a local folder:
devtools::install("path/to/cochranSize")

# Or from GitHub (once pushed):
devtools::install_github("yosleycarrero2025/cochranSize")

Usage

library(cochranSize)

# Large / unknown population, 95% confidence, 5% margin of error
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 of 2,000
cochran_sample_size(N = 2000, e = 0.05, conf.level = 0.95)

# Custom expected proportion, 99% confidence
cochran_sample_size(N = 500, p = 0.3, e = 0.03, conf.level = 0.99)

You can also call the underlying functions directly:

n0 <- cochran_n(p = 0.5, e = 0.05, conf.level = 0.95)
cochran_n_adj(n0, N = 1000)

Functions

Function Purpose
cochran_n() Base (unadjusted) Cochran sample size
cochran_n_adj() Applies finite population correction to n0
cochran_sample_size() Convenience wrapper combining both, with nice printing

Testing

devtools::test()

License

MIT

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("cochranSize")

0.1.0 by Yosley Carrero, 2 months ago


https://github.com/yosleycarrero2025/cochranSize


Report a bug at https://github.com/yosleycarrero2025/cochranSize/issues


Browse source code at https://github.com/cran/cochranSize


Authors: Yosley Carrero [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests testthat, knitr, rmarkdown


See at CRAN