Skip to content

Beginner: data foundations · Probability and inference · topic 14 of 62 · 30 min

Samples, the central limit theorem and confidence intervals

Explanation

We usually study a sample, not everyone, so our numbers have some error. The standard error says how much a sample average would wobble from sample to sample. The central limit theorem says sample averages follow a bell curve, which lets us build a 95% confidence interval: a range that very likely contains the true value.

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.

python
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))
Shows 14 1.414. The average is 14 minutes, give or take about 1.4 minutes.

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.

python
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))
The averages of samples centre on the population mean (both about 30). A histogram of sample_means would look like a bell even though the times are skewed.

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.

Careful: For small samples (say under 30) analysts use a slightly wider multiplier from the t-distribution instead of 1.96. For n = 5 it is about 2.78. Libraries like scipy.stats handle this for you.

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.

Think of it like this: A CI is like a fishing net, not a fish. You throw the net (build an interval) the same way every time. 95 throws out of 100 catch the fish (the true value). Any single throw either caught it or did not; you just know your method works 95% of the time.

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

Samples and confidence

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.

python
import math

p, n = 0.42, 1000
se = math.sqrt(p * (1 - p) / n)
print(round(1.96 * se * 100, 1))
Shows 3.1, the margin of error in percentage points.

Practice (0/2 done)

Task 1 · Code · Python

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.

Task 2 · Code · Python

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

Question 1

1.A survey about online shopping is done only through a shopping app. What is the main problem?

Question 2

2.If you collect 4 times as much data, the standard error becomes…

Question 3

3.What does the central limit theorem say?

Question 4

4.A 95% CI for the average delivery time is 28 to 32 minutes. Which reading is best?

Question 5

5.Where does the number 1.96 in "mean ± 1.96 × SE" come from?

Read more (free)

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.

From Spread: range, variance and standard deviation

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.

From Speaking with confidence

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.

From The normal distribution and z-scores

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.

From Conditional probability and Bayes' theorem

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. 1 more topic in “Probability and inference” before its exam: Hypothesis tests, p-values and A/B testing.
  2. Module 3 exam: Probability and inference · 12 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Cleaning, exploring and visualising data. 62 topics left in the course before the final exam.

← Previous: Random variables and distributions