Module 7 · Statistics: Describing and Deciding · Lesson 24 of 51
Samples, standard error and confidence intervals
Populations and samples, sampling bias, the standard error, the central limit theorem, and how to compute and explain a 95% confidence interval.
In this lesson · about 40 minutes
- Explain why a sample can describe a population, and how bias breaks it
- Compute a standard error and a 95% confidence interval
- Explain a confidence interval correctly in plain words
Sampling and bias
A random sample gives every member of the population the same chance of being picked. Bias creeps in when it doesn't: surveying only app users (who are younger), only weekday mornings, or only people who chose to reply (self-selection). Survivorship bias: studying only the cafés that are still open hides why others closed. A bigger biased sample is still biased.
Standard error and the central limit theorem
Every sample gives a slightly different mean. The standard error (SE) is how much sample means typically vary: SE = SD ÷ √n. Quadruple the sample, halve the SE. The central limit theorem says that for reasonably large samples (often n ≥ 30), sample means follow a bell curve around the true mean, even when the data itself is skewed. That's why the 1.96 below works.
The 95% confidence interval
mean ± 1.96 × SE (for small samples, use the t-distribution: scipy.stats.t.ppf(0.975, n - 1) instead of 1.96). For a proportion p: p ± 1.96 × √(p(1 − p) ÷ n).
How to say it: "We estimate average spend at $7.45, and we're 95% confident the true average is between $7.21 and $7.69." Strictly, the 95% is about the method: if we repeated the sampling many times, about 95% of the intervals built this way would contain the true value. It's not "a 95% chance the true value is in this particular interval", and it says nothing about where 95% of individual customers fall.
Try it · data lab
Samples, the central limit theorem and confidence intervals
Draw random samples from a population you normally never see. Watch the sample means form a bell curve, and count how often a 95% confidence interval catches the truth.
The population: what all 5,000 app users spent last week. It is skewed (most spend a little, a few spend a lot). Its true mean is $6.84, but in real life you never get to see the whole population: you only get a sample.
A confidence interval for average member spend
Exercise
Confidence interval for churn
Using all members, set p to the churn rate (mean of churned), se to its standard error √(p(1 − p) / n), and ci to the tuple (low, high) of the 95% interval, p ± 1.96 × se, each rounded to 4 decimals.
Code that runs before yours
import pandas as pd
import numpy as np
members = pd.read_csv("kc_members.csv")Check your understanding0 of 3 correct
Quiz score: 0 of 3
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.