Margin of Error — Precision and Sample Size
Foundations of Statistics
The Price of Precision
The margin of error quantifies the width of confidence intervals and depends on sample size, variability, and confidence level. Understanding this relationship is essential for designing efficient studies and interpreting reported results.
- Survey Research — Determining how many respondents are needed for reliable estimates
- Quality Control — Balancing precision requirements against inspection costs
- Business Intelligence — Setting appropriate precision targets for data collection
The margin of error tells you exactly how much precision your budget can buy.
What Is Margin of Error?
Core Formula
Critical Values for Common Confidence Levels
Derivation: Why ?
Worked Example: Polling
A pollster surveys 1,200 voters and finds 58% support Candidate A. The 95% margin of error is:
So the 95% CI is — Candidate A leads by 3 to 9 percentage points.
The Three Factors Affecting Margin of Error
Python Implementation
import numpy as np
from scipy import stats
def margin_of_error_mean(sigma, n, confidence=0.95):
"""Compute margin of error for population mean (σ known)."""
z_crit = stats.norm.ppf(1 - (1 - confidence) / 2)
return z_crit * sigma / np.sqrt(n)
def margin_of_error_proportion(p_hat, n, confidence=0.95):
"""Compute margin of error for population proportion."""
z_crit = stats.norm.ppf(1 - (1 - confidence) / 2)
return z_crit * np.sqrt(p_hat * (1 - p_hat) / n)
# Example 1: Mean with known σ
print(f"E (95%, σ=10, n=100): {margin_of_error_mean(10, 100, 0.95):.3f}")
print(f"E (99%, σ=10, n=100): {margin_of_error_mean(10, 100, 0.99):.3f}")
# Example 2: Proportion
print(f"E (95%, p̂=0.58, n=1200): {margin_of_error_proportion(0.58, 1200, 0.95):.4f}")
# Show 1/√n scaling
for n in [100, 400, 1600, 6400]:
E = margin_of_error_mean(10, n, 0.95)
print(f"n={n:5d}: E = {E:.3f}")