Beginner: data foundations · Probability and inference · topic 14 of 62 · 30 min
Samples, the central limit theorem and confidence intervals
Explanation
Why samples?
An election survey cannot ask 97 crore voters. A factory cannot open every biscuit packet to check its weight. So we take a sample, a smaller group, and use it to estimate a number about the whole population. The question is: how far off might our estimate be?
Good and bad samples
A random sample gives every member the same chance of being picked. A biased sample does not. An online poll about internet speeds only reaches people who are online. A survey done only in Mumbai cannot speak for all of Maharashtra. No formula can fix a biased sample, so how you collect data matters more than any calculation.
Standard error: how much the average wobbles
Take many samples of the same size, and each one gives a slightly different average. The standard error (SE) is the standard deviation of those averages. You can estimate it from one sample: SE = s ÷ √n, where s is the sample standard deviation and n is the sample size. Bigger samples give smaller SE, but slowly: to halve the SE you need four times the data.
import math
from statistics import mean, stdev
times = [10, 12, 14, 16, 18] # delivery times in minutes
se = stdev(times) / math.sqrt(len(times))
print(mean(times), round(se, 3))The central limit theorem (CLT)
The central limit theorem says: if you take many samples of a decent size and compute each sample's average, those averages form a roughly normal (bell-shaped) distribution around the true mean, even if the original data is not bell-shaped. Delivery times may be skewed by a few very late orders, but the average of 100 orders behaves like a bell curve. This is why the normal distribution appears everywhere in statistics.
import random
from statistics import mean
random.seed(7)
population = [random.expovariate(1 / 30) for _ in range(100000)] # skewed times
sample_means = [mean(random.sample(population, 50)) for _ in range(2000)]
print(round(mean(population), 1), round(mean(sample_means), 1))Confidence intervals
A 95% confidence interval (CI) for a mean is roughly mean ± 1.96 × SE. The 1.96 comes from the normal curve: 95% of the area lies within 1.96 standard deviations of the centre. For the delivery times: 14 ± 1.96 × 1.414, so about 11.23 to 16.77 minutes.
What a 95% CI means
It means: if we repeated the whole sampling process many times and built an interval each time, about 95% of those intervals would contain the true mean. It does NOT mean "there is a 95% chance the true mean is in this particular interval" in the strict classic sense, and it does not mean 95% of the data lies inside it. The interval is about the average, not about single values.
Common mistakes
- Thinking a huge biased sample beats a small random one. Fix: check how the data was collected first.
- Reading a CI as the range of individual values. Fix: a CI of the mean is much narrower than the spread of the data.
- Comparing two groups by checking whether their CIs overlap. Overlap does not prove "no difference". Fix: test the difference directly (next topic).
- Forgetting that SE shrinks with √n, not n. Four times the data only halves the error.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Samples, the central limit theorem and confidence intervals · 1/7
In this lesson you will learn how sure you can be about a number that comes from a sample.
Prefer a video by a teacher? Find free videos on “central limit theorem confidence interval standard error explained simply” on YouTube ↗
In real life: An opinion poll's margin of error
A news channel polls 1,000 randomly chosen voters and finds 42% support for a party. The standard error of a proportion is √(p(1 − p)/n) = √(0.42 × 0.58 / 1000) ≈ 0.0156, so the 95% margin of error is about ±3 percentage points. Honest polls report "42% ± 3%". The margin says nothing about bias: if the poll only phoned city landlines, the real error could be much bigger.
import math
p, n = 0.42, 1000
se = math.sqrt(p * (1 - p) / n)
print(round(1.96 * se * 100, 1))Practice (0/2 done)
Write standard_error(values) that returns the standard error of the mean: statistics.stdev(values) / math.sqrt(len(values)), rounded to 3 decimal places. If there are fewer than 2 values, return 0.0. Example: standard_error([10, 12, 14, 16, 18]) returns 1.414.
Write ci95(values) that returns a 95% confidence interval for the mean as a tuple (low, high): mean ± 1.96 × standard error, where SE = statistics.stdev(values) / math.sqrt(n). Round both ends to 2 decimal places. Example: ci95([10, 12, 14, 16, 18]) returns (11.23, 16.77).
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Hypothesis tests, p-values and A/B testingProbability and inference · same module
- Conditional probability and Bayes' theoremProbability and inference · same module
- Speaking with confidenceSpoken English: Zero to Fluent · Fluency and confidence
- Interval problemsData Structures and Algorithms (DSA) for interviews · Heaps and greedy algorithms
- Types of data, and the centre: mean, median, modeStatistics made simple
- NoSQL: documents, key-value, wide-column and graphSQL and Databases · Procedures, triggers, SQL engines and NoSQL
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
A survey about online shopping is done only through a shopping app. What is the main problem?
Answer: The sample is biased: it only reaches people who already shop online
Who gets asked decides what you learn. A biased sample cannot be fixed by formulas.
If you collect 4 times as much data, the standard error becomes…
Answer: Half as big
SE = s ÷ √n, and √4 = 2, so the SE halves.
What does the central limit theorem say?
Answer: Averages of reasonably large samples are roughly normally distributed
It is about sample averages, not raw data. Raw data can stay skewed.
A 95% CI for the average delivery time is 28 to 32 minutes. Which reading is best?
Answer: The method used catches the true average about 95% of the time; here it gives 28 to 32 minutes
A CI describes uncertainty about the mean, not where individual deliveries fall.
Where does the number 1.96 in "mean ± 1.96 × SE" come from?
Answer: About 95% of a normal curve lies within 1.96 standard deviations of the centre
That is the 95% point of the standard normal distribution.
Delivery times have a variance of 49 square minutes. What is the standard deviation?Related
Answer: 7 minutes
The SD is the square root of the variance: √49 = 7, back in minutes.
About an Indian accent, which is true?Related
Answer: It is fine; the goal is to be clear and understood
Every English speaker has an accent. Clear sounds and stress matter, not a foreign accent.
Which data is least likely to be close to normal?Related
Answer: Monthly incomes of people in a city
Incomes are strongly right-skewed: most are moderate and a few are very large.
In Bayes' theorem, what is the prior?Related
Answer: How common the condition is before you see the evidence
The prior is the starting belief, the base rate, before the new evidence is used.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Probability and inference” before its exam: Hypothesis tests, p-values and A/B testing.
- Module 3 exam: Probability and inference · 12 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Cleaning, exploring and visualising data. 62 topics left in the course before the final exam.