Package {cochranSize}


Type: Package
Title: Sample Size Calculation Using Cochran's Formula
Version: 0.1.0
Description: 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.
License: MIT + file LICENSE
URL: https://github.com/yosleycarrero2025/cochranSize
BugReports: https://github.com/yosleycarrero2025/cochranSize/issues
Encoding: UTF-8
RoxygenNote: 7.3.3
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-08-02 22:35:00 UTC; yosle
Author: Yosley Carrero [aut, cre]
Maintainer: Yosley Carrero <c3046338@newcastle.ac.uk>
Repository: CRAN
Date/Publication: 2026-08-08 12:30:07 UTC

Base Sample Size Using Cochran's Formula

Description

Calculates the minimum sample size required for a large (effectively infinite) population using Cochran's formula:

n_0 = \frac{z^2 \, p (1-p)}{e^2}

Usage

cochran_n(p = 0.5, e = 0.05, conf.level = 0.95)

Arguments

p

Estimated proportion of the population expected to have the attribute of interest. Defaults to 0.5, the most conservative choice (maximizes required sample size when unknown). Fully adjustable.

e

Desired margin of error (as a decimal, e.g. 0.05 for 5%). Fully adjustable by the user.

conf.level

Confidence level for the estimate. Defaults to 0.95 (95% confidence), but any value strictly between 0 and 1 is accepted (e.g. 0.90, 0.99).

Value

A single numeric value: the unadjusted sample size n0 (not rounded, and without any finite population correction).

Examples

cochran_n()
cochran_n(p = 0.3, e = 0.03, conf.level = 0.99)
cochran_n(e = 0.02, conf.level = 0.90)


Finite Population Correction for Cochran's Formula

Description

Adjusts an unadjusted Cochran sample size (n0) for a finite, known population size N, using:

n = \frac{n_0}{1 + \frac{n_0 - 1}{N}}

Usage

cochran_n_adj(n0, N)

Arguments

n0

The unadjusted sample size, typically the output of cochran_n.

N

The known size of the population being sampled from.

Value

A single numeric value: the finite-population-corrected sample size (not rounded). A warning is issued if n0 exceeds N, since that indicates the unadjusted sample size already exceeds the entire population.

Examples

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


Sample Size Calculation Using Cochran's Formula (Convenience Wrapper)

Description

Computes the sample size required for a survey or study using Cochran's formula, optionally applying the finite population correction when a known population size N is supplied. Wraps cochran_n and cochran_n_adj into a single call with readable output.

Usage

cochran_sample_size(N = NULL, p = 0.5, e = 0.05, conf.level = 0.95)

Arguments

N

Optional known population size. If supplied, the finite population correction is applied. If omitted, the population is treated as effectively infinite and only the unadjusted sample size is returned.

p

Estimated proportion of the population expected to have the attribute of interest. Defaults to 0.5 (most conservative). Fully adjustable.

e

Desired margin of error (as a decimal, e.g. 0.05 for 5%). Fully adjustable by the user — not fixed to any convention.

conf.level

Confidence level. Defaults to 0.95 (95%), but any value strictly between 0 and 1 is accepted (e.g. 0.90, 0.99) and is converted internally to the corresponding z-score.

Value

An object of class "cochran_size" (a list) containing:

n0

Unadjusted sample size, rounded up to the nearest integer.

n_adjusted

Finite-population-corrected sample size, rounded up to the nearest integer, or NA if N was not supplied.

p, e, conf.level, N

The input parameters used.

Examples

# Large / unknown population, 95% confidence, 5% margin of error
cochran_sample_size(e = 0.05, conf.level = 0.95)

# Known finite population of 2,000
cochran_sample_size(N = 2000, e = 0.05, conf.level = 0.95)

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


Print Method for cochran_size Objects

Description

Print Method for cochran_size Objects

Usage

## S3 method for class 'cochran_size'
print(x, ...)

Arguments

x

An object of class "cochran_size".

...

Additional arguments (unused).

Value

Invisibly returns x.