Understand the idea
A survey's margin of error says how close its estimate is likely to be to the truth: "52% ± 5 points" means the method lands within 5 points of the true percentage in about 95 of 100 surveys of this size.
The number of people you need depends on three things: the margin you want (half the margin needs four times the people), the confidence level (99% needs about 1.73 times as many as 95%), and your guess of the answer (50% is the cautious choice and needs the most). For a mean, the spread of the measurement replaces the guess of the percentage.
The size of a large population hardly matters: 385 people give ±5 points for a town or a country. Only a small population, where you would ask a sizeable share of everyone, lowers the number.
Practitioner explanation
KernelStats uses Cochran's closed forms with z = qnorm(1 − (1 − conf)/2): n0 = z² p(1 − p)/E² for a proportion and n = n0/(1 + (n0 − 1)/N) with a population of N (from the exact finite-population variance of p̂); n0 = (zσ/E)² for a mean and n = n0/(1 + n0/N). The answer is rounded up, and a table shows nearby margins at 90%, 95% and 99%.
The result assumes a simple random sample and counts completed responses: divide by the expected response rate, and multiply by the design effect for cluster samples. For detecting a difference with a given power, use Power & Sample Size instead. The worked example agrees with the closed form in R 4.5.3.
When to use it
Consider it when
Planning a survey or study whose goal is to estimate one percentage or one mean with a chosen precision: how many people should I ask?
Use caution when
When the goal is to detect a difference between groups or from a target with a given power (use Power & Sample Size), or for complex sample designs without a design effect.
Formulas and symbols
Sample size to estimate a proportion
z the standard normal value for the confidence level, p the expected share, E the margin as a proportion, N the population size (omit the correction for a large population).
Sample size to estimate a mean
σ the standard deviation (from a small trial run, an earlier study or a best guess), E the margin in the data's units.
Alternatives
- Power & Sample Size (Power & Sample Size). You want enough power to detect a difference, not a precise estimate.
Worked example
Scenario
Estimate a percentage within ±5 points at 95% confidence, no idea of the answer (50%).
Result
n0 = 1.96² × 0.25 / 0.05² = 384.15, rounded up to 385; ±3 points needs 1,068; from a population of 2,000, 323.
Interpretation
Ask about 385 people (more to allow for non-response) to estimate the percentage to within ±5 points with 95% confidence.
Dataset: none
Common misconceptions
Misconception
A bigger population needs a proportionally bigger sample.
Correction
Once the population is in the tens of thousands its size barely matters: ±5 points at 95% needs 377 people from a population of 20,000 and 385 from 2 million.
Misconception
The margin of error covers every source of error.
Correction
It covers random sampling error only, not bias from non-response, question wording or an unrepresentative sample.
References
- NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2.2 Sample sizes required, NIST/SEMATECH (2012).
