⚡0 XP🔥0

Sampling and the Central Limit Theorem

Lesson 3 of 5 ⏱ 4 min read ✎ 2 exercises ❓ 5-question quiz ▶ Runs Python

Population vs sample, sampling methods and bias, sample statistics with ddof=1, the sampling distribution, standard error, and the Central Limit Theorem demonstrated with simulations.

Population and sample#

  • A population is everyone (or everything) you want to know about - all voters in Madhya Pradesh, all orders ever placed on an app.
  • A sample is the part you actually measure - 2,000 voters, last week's 500 orders.

We compute statistics from the sample (x̄, s) to estimate parameters of the population (μ, σ).

Population (parameter) Sample (statistic)
size N n
mean μ x̄
standard deviation σ s
proportion p p̂

Sampling methods and bias#

Method How Good for
simple random everyone has an equal chance the default
stratified split into groups (e.g. city, gender), sample from each making sure small groups are represented
cluster pick whole groups (e.g. 20 random schools) when a full list of people isn't available
systematic every k-th item (every 10th invoice) quality checks on a production line
convenience whoever is easy to reach quick pilots - often biased
Common Mistake

A huge biased sample is worse than a small random one. An online poll on a cricket website will never represent the views of all citizens, however many people vote.

हिंदी में समझें

Population पूरा समूह है (जैसे शहर के सारे लोग), sample उसका छोटा हिस्सा जिसे हम सच में नापते हैं। Sample random होना चाहिए - वरना नतीजा biased होगा। जैसे दाल पकी या नहीं, यह देखने के लिए पूरी हांडी नहीं खाते, पर चम्मच अच्छी तरह हिलाकर लेते हैं - वही random sample है।

Sample statistics in Python#

For a sample, NumPy's std needs ddof=1 (divide by n − 1); pandas uses n − 1 by default.

▶ Try it YourselfPython
Ctrl + Enter to run

Sampling distributions#

Take many samples of the same size and compute the mean of each. Those means vary - their distribution is the sampling distribution of the mean. Its standard deviation is called the standard error (SE):

SE = σ ÷ √n (estimate it with s ÷ √n)

Bigger samples → smaller SE → more precise estimates. Because of the square root, 4× the data only halves the error.

The Central Limit Theorem (CLT)#

The CLT: if you take samples of size n from any population with mean μ and SD σ, then for large n (often n ≥ 30 is enough) the sample mean is approximately normal with mean μ and SD σ/√n - even if the population itself is skewed.

Delivery times are right-skewed (most are quick, a few are very late). Watch what happens to the averages:

▶ Try it YourselfPython
Ctrl + Enter to run

With n = 5 the means are still a bit skewed; with n = 50 they form a clear bell curve centred on 30, with SD close to σ/√n.

Did you know?

The CLT is why we can build confidence intervals and run hypothesis tests on averages without knowing the population's exact shape - the next lesson.

Summary#

  • Statistics (x̄, s, p̂) from samples estimate parameters (μ, σ, p) of populations.
  • Random sampling avoids bias; convenience samples are often biased.
  • Use ddof=1 for the sample SD in NumPy.
  • Standard error = σ/√n; bigger samples give more precise means.
  • CLT: sample means are approximately normal for large n, whatever the population shape.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Sample summary

Delivery times (minutes) for a random sample of 10 orders are given. Using NumPy, compute and print: the sample mean (mean), the sample standard deviation with ddof=1 (sd) and the standard error se = sd / √n, each with 2 decimals:

Mean: 31.40
SD: 6.19
SE: 1.96
Expected output:
Mean: 31.40
SD: 6.19
SE: 1.96
2

How big a sample?

The population standard deviation of monthly mobile data use is sigma = 12 GB. For each sample size in sizes, print the standard error as n=36: SE=2.00. Then store in needed the smallest sample size (a whole number) that gives a standard error of at most 1 GB, and print Needed: 144.

Expected output:
n=36: SE=2.00
n=64: SE=1.50
n=100: SE=1.20
Needed: 144

Quick Quiz

Q1.

A survey of only people who visit a gym is used to estimate how often all Indians exercise. The main problem is...

Q2.

Why do we divide by n − 1 (ddof=1) for the sample standard deviation?

Q3.

Population SD is 20. The standard error of the mean for samples of size 100 is...

Q4.

The Central Limit Theorem says that for a large enough sample size, the distribution of the sample mean is approximately...

Q5.

To make the standard error half as big, you need a sample that is...