Contents/ Part XI · Estimation & Confidence Intervals/ Chapter 74

Margin of Error

The margin of error is the ± you see in every poll, the half-width of a confidence interval. We unpack what drives it, confidence, variability, and sample size, watch it shrink like 1/√n, and report a real customer survey the professional way.

⏱️ ~14 min read
🐍 Notebook included
📊 Chapter 74

"52% support, ± 3 points." That little ± is the margin of error, and it is the most widely seen, and most widely misunderstood, number in statistics. This chapter is a close look at exactly what it is and what makes it big or small.

E = z·SE
The margin of error is the half-width of a confidence interval: E = z·SE. It grows with the confidence level (bigger z) and with variability, and shrinks with sample size as 1/√n.
📐
It is just the half-width

Every interval in this Part is estimate ± margin. The margin of error is that ±. Understanding it is understanding how precise an estimate really is, and how to report it honestly.

1

What the Margin of Error Is

A confidence interval is estimate ± margin. That margin is the margin of error, E = z·SE. When a poll reports "52% ± 3%", the 3 points is E, almost always at 95% confidence.

"52% ± 3%" means estimate 52%, margin of error 3 points 52% E = 3 pts E = 3 pts

The margin of error tells you how precise the estimate is, nothing more and nothing less. It does not describe error from bad questions, biased samples, or non-response, only the random sampling uncertainty. A small margin on a biased sample is still wrong (recall Bias in Data Collection); E measures precision, not accuracy.

2

The Three Drivers

For a proportion, E = z·√(p(1−p)/n). Three things move it.

DriverEffect on EFrom the notebook (n = 1,000, p = 0.5)
Confidence level (z)higher confidence → wider E90% ±2.6 · 95% ±3.1 · 99% ±4.1 pts
Variability p(1−p)most at p = 0.5p=0.1 ±1.9 · p=0.3 ±2.8 · p=0.5 ±3.1 pts
Sample size nmore data → smaller E (1/√n)only knob that helps without costing confidence

Two of the three are trade-offs: you cannot lower the margin by lowering your confidence (that is cheating), and you do not control how variable the population is, so planners assume the worst case p = 0.5, where p(1−p) is largest. The only honest lever is sample size.

3

The 1/√n Law

Because E is proportional to 1/√n, precision is expensive: each halving of the margin costs four times the sample.

Margin of error vs sample size (95%, worst case) sample size n → E n=250: ±6.2 n=1000: ±3.1 n=4000: ±1.6 diminishing returns

Going from ±6 to ±3 points is cheap; going from ±3 to ±1.5 costs four times as much again. This is exactly why the classic national poll lands near n = 1,000 (about ±3%): it is the sweet spot where extra precision stops being worth the cost. The same curve governs how big a test set you need to certify a model's accuracy.

4

Real-World Example: Reporting a Survey

A company surveyed 900 customers and wants to announce the share who would recommend it, the kind of number that goes in a press release or board deck. Reporting it with a margin of error is what makes it credible.

📂 Dataset · margin-of-error--customer_survey.xlsx

One row per respondent with a rating_1_5 and a derived would_recommend (top-2-box).

The result, reported the right way:

📣
The honest headline

"64% of customers would recommend us, ± 3.1 points (95% confidence)." The true rate is very likely between 61.2% and 67.5%. Reporting only "64%" would imply a precision the data does not have.

LeverSettingMargin of error
Confidence90% / 95% / 99%±2.6 / ±3.1 / ±4.1 pts
Sample sizen = 300 / 900 / 2,500±5.4 / ±3.1 / ±1.9 pts

The levers are clear: demanding 99% confidence widens the margin to about ±4 points, and to roughly halve the margin the company would need to survey nearly three times as many customers. Knowing these trade-offs is the difference between quoting a number and defending it.

5

Margin of Error in Machine Learning & AI

The same ± belongs on every metric a model reports. A leaderboard number without a margin is a poll without one.

Idea (this chapter)In ML / AI it becomesExample
Margin of errorError bars on a metricaccuracy 92% ± 1.5%
1/√n lawHow big a test set you need±1% accuracy needs ~9,600 labeled items
Worst case p = 0.5Conservative eval sizingplan test-set size assuming 50% accuracy
Precision vs confidenceHow tight a claim you can maketighter bars require more eval data
🤖
Why this matters for AI research

A model's accuracy is a proportion, so it has a margin of error exactly like a poll. With a 400-item test set, the 95% margin is roughly ±5 points, so "91%" and "94%" models are indistinguishable. The 1/√n law tells you the test set must quadruple to halve those error bars, which is why certifying a 1% improvement requires on the order of 10,000 labeled examples. Reporting a metric without its margin of error is the leaderboard equivalent of a poll with no ±.

🐍

Dissect the margin of error in Python

The companion notebook computes E = z·SE, varies all three drivers (confidence, variability, n), plots the 1/√n curve, and loads margin-of-error--customer_survey.xlsx to report a real recommend rate with its margin of error and a levers table.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scipy, matplotlib, and openpyxl and launch jupyter notebook.

🎓 Key Takeaways

  • Margin of error E = z·SE is the ± half-width of a confidence interval, the precision of an estimate.
  • Three drivers: confidence (bigger z → wider), variability (worst at p=0.5), and sample size.
  • 1/√n law: quadruple the sample to halve the margin; the classic poll (n≈1,000) is ±3%.
  • Precision ≠ accuracy: a small margin on a biased sample is still wrong; E ignores question and sampling bias.
  • Real survey: 64% would recommend ±3.1 points at 95%; in ML, a 400-item test set gives ±5 points, so report metric margins.
6

Practice Challenges

Five short challenges, beginner to intermediate. Try them with NumPy and SciPy before checking the solutions.

1

Compute a margin of error

A poll of 1,200 finds 47% support. Compute the 95% margin of error.

Hint: E = 1.96·√(0.47·0.53/1200).
2

Worst-case margin

Not knowing p, compute the worst-case 95% margin for n = 1,200 (use p = 0.5).

Hint: p(1−p) is largest at 0.5.
3

Confidence widens the margin

For n = 1,000 and p = 0.5, tabulate the margin at 90%, 95%, and 99% confidence.

Hint: stats.norm.ppf(0.5 + conf/2).
4

Quadruple for half

Confirm that going from n = 1,000 to n = 4,000 halves the margin of error.

Hint: the ratio should be about 0.5.
5

Real data: survey margin

Load margin-of-error--customer_survey.xlsx and report the recommend rate with its 95% margin of error.

Hint: proportion of would_recommend, then z·SE.
Check your work

A fully-worked solutions notebook walks through all five challenges, each verified in code. Try them yourself first, then compare.

📓 View Solutions ▶ Open Solutions in Colab ⬇ View / Download on GitHub
7

Quiz: Test Yourself

Eight quick questions on the margin of error. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.

🧭
Up next

Every interval so far relied on a formula. The Resampling & Simulation chapter closes the Part with the bootstrap, which builds a confidence interval for almost any statistic, including ones with no formula at all, by letting the data resample itself.