Confidence Interval Lab

Confidence Interval Lab

Sketch any population, draw samples from it, and watch the sample mean, the sample variance and the 95% confidence interval settle down. Then repeat the experiment many times to see the sample means become normal and about 95% of the intervals catch the true mean.

How it works and what to try

How it works: In three steps. (1) Sketch a population density; its true mean μ and variance σ² are computed exactly. (2) Draw one run of n samples and watch X̄n, Sn² and the t-interval settle as samples arrive, with the interval narrowing like 1/√n. (3) Repeat for hundreds or thousands of runs: the sample means pile up as N(μ, σ²/n), and about 95% of the intervals contain μ.

Try this: Use a skewed population with small n (say 5) and see coverage fall short of 95%; then increase n and watch it recover. Compare a bimodal population with a uniform one: the histogram of means looks normal either way.

STEP 1The population

Drag across the plot to sketch a density on [a, b]. The page computes its true mean μ and variance σ² exactly and samples from it by inverting its CDF. Changing the shape clears all runs.

Start from
Population density (drawn) Histogram of the current run True mean μ
True mean μ–
True variance σ²–
True s.d. σ–

STEP 2One run of n samples

X̄n = (1/n) Σ Xi Sn² = (1/(n−1)) Σ (Xi − X̄n)² 95% CI: X̄n ± tn−1, 0.975 · Sn/√n
Samples drawn–
Latest sample–
Sample mean X̄ₙ–
Sample variance Sₙ²–
95% interval for μ–
Sample mean X̄ₖ as samples arrive, with its 95% interval
Sample variance Sₖ² as samples arrive

STEP 3Many runs

Each run draws n fresh samples and keeps only its mean X̄n and its 95% interval. By the central limit theorem the means pile up as N(μ, σ²/n), whatever the population looks like, and roughly 95% of the intervals contain μ. Each completed run from step 2 is added here too.

Runs0
Mean of X̄ₙ–
Variance of X̄ₙ–
Intervals covering μ–target 95%
Histogram of the sample means, with the normal curve N(μ, σ²/n)
The 40 most recent 95% intervals (newest at top), on the same axis
Sample means N(μ, σ²/n) Interval contains μ Interval misses μ

With a small n and a skewed population, coverage tends to fall a little short of 95%: the t interval is exact only for normal data, and the approximation improves as n grows.