Confidence intervals & hypothesis tests
Step 18 of 18 in Foundations · Concept · Medium
A confidence interval gives a range of plausible values; a p-value is how surprising the data would be if nothing were going on. Neither is the probability your hypothesis is true.
The lesson
An estimate from a sample wobbles from sample to sample. A 95% confidence interval is a recipe that, repeated on fresh samples, would cover the true value 95% of the time. For a mean, the recipe is x̄ ± 1.96·s/√n.
- Standard error = 10 / √100 = 1
- Half-width = 1.96 × 1 = 1.96
- 95% interval: 48.04 to 51.96
When there is no formula, as for a median, bootstrap. Resample your own data with replacement, recompute the statistic, repeat a few thousand times, and read off the 2.5th and 97.5th percentiles.
A p-value answers one narrow question: if nothing were going on, how often would data at least this extreme turn up? Small means the data would be surprising under that assumption.
Common mistake. p = 0.03 does not mean a 3% chance that nothing is going on. That would be P(hypothesis | data), which needs Bayes' theorem and a prior. And if you run 20 tests at the 0.05 level, expect one false alarm even when every effect is zero.
Check yourself
n = 400 and s = 20. What is the half-width of the 95% confidence interval for the mean?
Show the answer
1.96. Standard error = 20 / √400 = 1. Half-width = 1.96 × 1.
A test gives p = 0.03. That means:
- there is a 3% chance the effect is not real
- there is a 97% chance the effect is real
- if there were no effect, data this extreme would turn up 3% of the time
Show the answer
if there were no effect, data this extreme would turn up 3% of the time. A p-value is P(data | no effect). It says nothing direct about P(no effect | data).
You run 20 independent tests at the 0.05 level and no effect is real. How many false positives do you expect?
Show the answer
1. 20 × 0.05 = 1.
Build it
Bootstrap a CI
Bootstrap a 95% confidence interval for a median, then check coverage by repeating the whole experiment 1,000 times on simulated data.
Done when: About 95% of intervals contain the true median.
Runs in your browser: write the code on the map and the tests mark it.
Case study: The replication crisis
- Many published findings with p < 0.05 failed to replicate.
- Testing many hypotheses and reporting the significant one (p-hacking) inflates false positives.
- Pre-registration and effect sizes are the practical fixes; same rules apply to ML experiments.
Resources
Earn this star
On the map, your answers are marked and you log what you built. Finish the step and its star lights.
Open this step on the map