Estimation
Estimation uses a sample to make an educated guess about an unknown population parameter. There are two kinds of estimates:
- A point estimate is a single number: "the mean delivery time is 34.2 minutes".
- An interval estimate, usually a confidence interval, is a range with a stated confidence level: "the mean delivery time is between 32.5 and 35.9 minutes, with 95% confidence".
A point estimate is almost certainly a little wrong. An interval estimate admits that and tells you how wrong it is likely to be.
Point estimates
| Parameter | Point estimate |
|---|---|
population mean μ |
sample mean x̄ |
population proportion p |
sample proportion p̂ = x / n |
population standard deviation σ |
sample standard deviation s |
The anatomy of a confidence interval
Most confidence intervals have the same structure:
point estimate ± margin of error
margin of error = critical value × standard error- The standard error (SE) is the standard deviation of the point estimate across repeated samples: how much the estimate typically wobbles. For a mean it is
s / √n; for a proportion√(p̂(1 − p̂) / n). - The critical value (
z*ort*) depends on the confidence level: 1.96 for 95% with the normal distribution.
import math
from scipy import stats
# 40 deliveries: mean 34.2 minutes, standard deviation 5.3 minutes
n, xbar, s = 40, 34.2, 5.3
se = s / math.sqrt(n)
t_star = stats.t.ppf(0.975, df=n - 1)
margin = t_star * se
print(f"standard error = {se:.3f}")
print(f"critical value = {t_star:.3f}")
print(f"margin of error = {margin:.3f}")
print(f"95% CI: ({xbar - margin:.2f}, {xbar + margin:.2f})")standard error = 0.838
critical value = 2.023
margin of error = 1.695
95% CI: (32.50, 35.90)
What "95% confidence" really means
The confidence is a property of the method, not of one particular interval. If we repeated the whole study many times, each time computing a 95% interval, about 95% of those intervals would contain the true parameter. Any single interval either contains it or doesn't; we just don't know which.
A simulation makes this concrete. We know the true mean (μ = 50) because we invented the population, then compute 100 intervals from 100 independent samples:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
rng = np.random.default_rng(95)
mu, sigma, n = 50, 12, 25
t_star = stats.t.ppf(0.975, n - 1)
fig, ax = plt.subplots(figsize=(6.5, 4))
misses = 0
for i in range(100):
sample = rng.normal(mu, sigma, n)
m = sample.mean()
half = t_star * sample.std(ddof=1) / np.sqrt(n)
hit = m - half <= mu <= m + half
misses += not hit
ax.plot([m - half, m + half], [i, i], color="#2a78d6" if hit else "#e34948", linewidth=1.5)
ax.axvline(mu, color="#0b0b0b", linewidth=1)
ax.set_xlabel("95% confidence intervals for the mean (true μ = 50)")
ax.set_yticks([])
plt.tight_layout()
plt.show()
print(f"{100 - misses} of 100 intervals contain the true mean; {misses} miss it (red)")96 of 100 intervals contain the true mean; 4 miss it (red)
Note: It is not correct to say "there is a 95% probability that μ is in (32.5, 35.9)". μ is fixed; the randomness is in the sample. The careful phrasing is "we are 95% confident", meaning: the procedure captures μ 95% of the time.
Confidence level, sample size and width
Two levers control how wide an interval is:
- Higher confidence → wider interval. To be more certain of catching μ, you need a bigger net.
- Larger sample → narrower interval. The standard error shrinks like
1 / √n, so quadrupling the sample halves the width.
import math
from scipy import stats
s = 5.3
print(" n 90% 95% 99% (margin of error, minutes)")
for n in [10, 40, 160, 640]:
se = s / math.sqrt(n)
margins = [stats.t.ppf(1 - (1 - c) / 2, n - 1) * se for c in (0.90, 0.95, 0.99)]
print(f"{n:4d} " + " ".join(f"{m:6.3f}" for m in margins)) n 90% 95% 99% (margin of error, minutes)
10 3.072 3.791 5.447
40 1.412 1.695 2.269
160 0.693 0.828 1.092
640 0.345 0.411 0.541
Going from 40 to 160 deliveries roughly halves the margin of error. Going from 95% to 99% confidence makes it about a third wider.
Planning a sample size
You can turn the margin-of-error formula around to find the n needed for a desired precision. For a mean with an estimated standard deviation σ:
n = (z* × σ / E)² (E = desired margin of error, round up)import math
from scipy import stats
sigma_guess = 5.3 # from a pilot study
E = 1.0 # we want ±1 minute
z_star = stats.norm.ppf(0.975)
n = math.ceil((z_star * sigma_guess / E) ** 2)
print("deliveries needed:", n)deliveries needed: 108
The following two lessons apply this recipe to proportions and means.
Test yourself
A 95% confidence interval for a mean is (12.1, 15.9). What is the point estimate?
- 12.1
- 14.0
- 15.9
- 3.8
Which is the correct interpretation of a 95% confidence interval?
- 95% of the data lies inside it
- There is a 95% chance the sample mean is inside it
- The method produces intervals that contain the true parameter in 95% of repeated samples
- The parameter changes 5% of the time
How does the margin of error change if the sample size is multiplied by 4?
- It is divided by 4
- It is halved
- It doubles
- It does not change