Statistics for analysis · lesson 4 of 13
Parts in this lesson
As.std() / np.sqrt(len(s))the standard error of the mean
Bstats.sem(s)the same, from SciPy

The central limit theorem

Last updated

Lesson 8.3 found that sample means pile up in a neat, narrow hump around the truth. That isn't luck: it's the central limit theorem, one of the most useful results in statistics. It says that means of samples are close to normal, whatever shape the data has, and it tells you exactly how wide the hump is. In this lesson you'll watch it happen, compute a standard error from one sample, and see the kind of data where the theorem fails.

By the end of this lesson you can

  • Say what the central limit theorem says, and when it applies
  • Compute the standard error of a mean from one sample
  • Explain how sample size changes the standard error
  • Recognise heavy-tailed data, where means don't settle

Means of many draws

Receipts are skewed: lots of small ones, a long tail of big ones. What do means of receipts look like? The cell takes 5,000 samples of 1, 2, 5 and 30 receipts (with replacement) and draws a histogram of the means in each case. Run it.

clt.ipynb
  • Means of 1 are just receipts: skewed, skew 1.29.
  • Means of 2 are already less skewed (0.87): a big receipt is often paired with a small one.
  • Means of 5: skew 0.54.
  • Means of 30: skew 0.16, and the bars follow the pink normal curve closely.

That's the central limit theorem (CLT). If you take samples of size n from almost any population with mean μ and standard deviation σ, the sample mean X¯ is approximately normal, and more so as n grows:

X¯≈𝒩(μ,σ2n)

𝒩(μ,σ2/n) is the normal distribution with mean μ and variance σ2/n, so standard deviation σ/n. It doesn't matter much what shape the data has. Try other shapes:

CLT machine3,000 samples of n, and their means
the starting shape₱0₱520means of 1 (zoomed in)₱0₱260₱520
1

Means of 1: skew 1.32, standard deviation ₱72.37. The pink curve is the normal the theorem predicts, with standard deviation σ/√n = ₱71.78. With n = 1 a “mean” is just one value, so the bars are the starting shape.

With two humps or a flat uniform shape, means of 5 already look normal; the skewed receipts need more, about 30. The heavy tail is different, and step 4 is about it.

The standard error

The standard deviation of the sample mean has its own name: the standard error (SE). It says how far a sample mean typically is from the true mean. The CLT says it's σ/n. You don't know σ, the population's standard deviation, but your sample's standard deviation s is an estimate of it, so from one sample:

SE=sn

Run the cells: one sample of 40 receipts.

clt.ipynb

The sample's mean is ₱102.68 and its standard deviation ₱74.49, so its standard error is 74.49/40≈ ₱11.78. stats.sem (standard error of the mean) gives the same. The second cell checks it the long way, with 2,000 samples of 40: their means have a standard deviation of ₱11.06. One sample predicted, from its own spread, how much samples like it wobble.

Don't mix the two up: the standard deviation describes the data (how much receipts vary); the standard error describes an estimate (how much a mean of 40 receipts would vary from sample to sample).

Sample size

Because n is under a square root, the standard error shrinks slowly. The table in the last cell shows it: ₱22.71 for 10 receipts, ₱11.35 for 40, ₱5.68 for 160, ₱2.84 for 640. Every time you want to halve the error, you need four times the data. Step through it:

The standard error shrinks with the square root of n. Samples of 4. The theorem says their means are close to normal, centred on ₱109.22, with standard error σ/√n = 71.78/√4 = ₱35.9.n = 4₱60₱80₱100₱120₱140₱160sample mean
1 of 4 Samples of 4. The theorem says their means are close to normal, centred on ₱109.22, with standard error σ/√n = 71.78/√4 = ₱35.9.

This is why surveys of a few hundred people are common and surveys of a few hundred thousand are rare: going from 1,000 to 100,000 people only makes the error ten times smaller, for a hundred times the cost. And it's why a survey of 1,000 can describe 100 million people: the error depends on the size of the sample, not of the population (as long as the sample is random, as 8.3 warned).

When it fails: heavy tails

The CLT needs σ to be a finite number. Some data has tails so heavy that it isn't: a few values are so enormous that the variance never settles. Likes on social media posts, the sizes of cities, people's wealth and the damage done by storms are like that. Run the cells: 100,000 made-up posts, where the true mean is 30 likes.

likes.ipynb

After 100 posts the mean is 35.1; after 1,000 it's 21.9; after 10,000, 22.8; after 100,000, 29.7. The chart shows the "mean so far" crawling along, then jumping up whenever a viral post arrives (the biggest has 280,879 likes). It's nowhere near settled even after 100,000 posts. The median, meanwhile, is 8.8 to 9.0 likes from the first hundred posts on.

For data like this, the mean of a sample tells you little and its standard error is meaningless. Describe it with the median and percentiles (8.1), look at the biggest values on their own, or analyse the logarithm. The check is the same as always: look at the histogram first, and at the largest values. If one value is thousands of times the median, be suspicious of any mean.

Wrong way: ten receipts

The owners want to know what the week's takings will be, but only typed in ten receipts so far. Someone multiplies their mean by the week's 1,203 receipts. Run the cells.

takings.ipynb

The ten receipts average ₱125.00, so the projection is ₱150,375. The real week took in ₱131,396: the projection is ₱18,979 too high, about 14%. Another ten receipts would have said ₱117.80.

Nothing was miscalculated. The problem is treating ₱125.00 as if it were exact. Its standard error is ₱26.05, so the true mean could easily be anywhere from about ₱73 to ₱177 (two standard errors either side), which makes the projection anything from about ₱88,000 to ₱213,000. Reported as "₱150,375", it sounded certain to the peso.

The check: whenever you report a mean from a sample, work out its standard error, and say how uncertain the number is ("about ₱125, give or take ₱50"). If the uncertainty is too big for the decision, get a bigger sample. Lesson 8.5 turns this into a confidence interval.

Check what you learned

A sample of 100 has a standard deviation of 20. What is the standard error of its mean?
You want the standard error to be a third of what it is now. How much more data do you need?
Which of these is the CLT least able to help with?

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Data Analysis