Skip to contents

How many items must be checked to estimate a rate (an error rate, a share of correct matches) with a given precision?

  • margin_of_error() gives the half-width of the confidence interval of a proportion estimated on n items drawn at random;

  • sample_size_for_margin() gives the number of items needed for a given margin.

Usage

margin_of_error(n, p = 0.5, conf = 0.95, population = Inf)

sample_size_for_margin(margin, p = 0.5, conf = 0.95, population = Inf)

Arguments

n

Integer. Sample size.

p

Number. Expected proportion. 0.5 gives the largest margin: use it when nothing is known.

conf

Number. Confidence level.

population

Number. Size of the population sampled (Inf when it is large); a finite population correction is applied otherwise.

margin

Number. Wanted half-width of the interval (0.05 for plus or minus 5 points).

Value

margin_of_error(): a number. sample_size_for_margin(): an integer.

Details

With \(z\) the normal quantile of the confidence level, $$m = z \sqrt{\frac{p(1-p)}{n}} \sqrt{\frac{N-n}{N-1}},$$ where the second factor is the finite population correction. The margin depends on the size of the sample, not on the share of the population it represents: checking 1,000 items gives the same precision in a corpus of 60,000 documents or of 6 million (Lemercier and Zalc, 2019, ch. 2). The margin shrinks with the square root of \(n\): going from 150 to 300 items helps much more than going from 500 to 1,000. These formulas assume a simple random sample; for a stratified sample, compute the margin within each stratum.

References

Lemercier, C., & Zalc, C. (2019). Quantitative Methods in the Humanities: An Introduction. University of Virginia Press.

Examples

margin_of_error(c(100, 200, 300, 1000), p = 0.2)
#> [1] 0.07839856 0.05543615 0.04526343 0.02479180
sample_size_for_margin(0.05)
#> [1] 385
sample_size_for_margin(0.05, p = 0.1, population = 400)
#> [1] 103