Hypothesis testing: p-values, power, t-tests and multiple testing
Before this lesson: lesson 01 (Bayes' rule and base rates), lesson 02 (the probability integral transform), lesson 06 (the CLT, the t-distribution and confidence intervals). Lesson 10 helps for the contrast with credible intervals. Time: about 80 minutes, plus the notebook.
Why this matters #
- Comparing models. "Model B beats model A on the test set" is a claim about noise. Seeds, test examples and data splits all add randomness. A paired test or an interval tells you whether the gain is larger than this noise.
- A/B tests. Every change to a product with many users (a new ranking model, a new layout, a new LLM prompt) is launched or rejected after a two-proportion z-test or a t-test. Lesson 12 turns this into an engineering process.
- Monitoring. Drift detection tests hundreds of input features every day. Without a multiple-testing correction, most alarms are false.
- Science. Genomics tests thousands of genes, climate science tests a trend in every grid cell, and particle physics uses the "5σ" rule. All of them are multiple-testing problems.
- Reading papers. Many results in ML papers are a mean over 3–5 seeds. To read them well, you need to know what a p-value and a confidence interval say, and what they do not say.
1. Predict first #
2. The picture #
A test in four steps. You flip a coin times and see heads. Is the coin fair?
- Null hypothesis : the default model, which you try to reject. Here , where is the probability of heads. The alternative hypothesis is .
- Test statistic: a number that measures how far the data are from . Under , and . So use the standardised count .
- Null distribution: the distribution of the statistic when is true. Here , and by the CLT (lesson 06) is approximately .
- p-value: the probability, under , of a statistic at least as extreme as the observed one. "Extreme" means far from 50 in either direction (two-sided): with the exact binomial distribution. The CLT gives , and with the continuity correction ().
Fix the level before you see the data. Since , you reject : the result is "statistically significant at the 5% level".
Press "Repeat 1,000 times" to flip a fair coin 100 times, again and again. This is the world where is true. The violet bars show how often each number of heads appears; the orange marks are the exact binomial probabilities. The magenta bars are the runs at least as far from 50 as the observed count (yellow line). Their share is the p-value: it approaches the exact 0.0352. Move the observed count to 55 or 70 and predict the p-value first. The second view, Many p-values, runs many tests and shows the histogram of their p-values.
Two kinds of errors. The truth is unknown, and the test decides. There are four cases:
| true | false | |
|---|---|---|
| reject | type I error (false positive), probability | correct, probability = power |
| do not reject | correct | type II error (false negative), probability |
The power is : the probability that the test finds an effect that is really there. We write (not ) because has other meanings in this track.
Power as two bell curves. Draw the distribution of under : a bell centred at 0. The test rejects when ; the two tails beyond have area . Now suppose the coin really has . Then is centred at , with standard deviation , about 1. Only about half of this second bell lies beyond 1.96. So the power is about one half (0.52 with the normal approximation): half of the time, 100 flips miss a coin that lands heads 60% of the time. With flips the centre moves to , and the power is about 0.98. The effect is the same; more data make it visible.
Move the sliders for the effect and the sample size . The violet curve is the null distribution of , the orange curve the distribution when the effect is real. The magenta area is , the aqua area is the power, and the light orange area is . The lower chart shows the power as a function of . The start values are the coin: , . Notice that only moves the orange curve: to double you need four times as much data.
A test has power 0.5 at for some effect. About how many observations give power 0.98 for the same effect, with the same (two-sided)?
Power 0.5 means that the alternative is centred near the critical value, . Power 0.98 needs , so must double. Since , must grow by . Power is not proportional to : it is of something proportional to .
3. Definitions and main results #
Tests, errors and power #
Data come from a model with an unknown parameter . The two hypotheses split the set of parameters: against . A test is a rule , where 1 means "reject ". Usually for a test statistic and a critical value .
- Type I error rate: for . The test has level if this is at most for every . Its size is the largest type I error rate, .
- Type II error rate: for .
- Power function: . On it equals . Power is a function of the true , not one number.
Power of the z-test. Take i.i.d. observations with unknown mean and known standard deviation . Test with . Let be the -quantile of , so and .
- One-sided (, reject when ). If the true mean is , then with , so
- Two-sided (reject when ): . The second term (rejecting in the wrong direction) is tiny unless is close to 0.
Power grows with the effect , with and with , and falls with the noise . Only the combination matters. Lesson 12 solves this formula for to plan an experiment.
The p-value #
Definition. Let large values of count as evidence against , and let be the observed value. The p-value is
the probability, computed under , of a statistic at least as extreme as the observed one. For a two-sided test with a statistic that is symmetric under , use : . Equivalently, the p-value is the smallest level at which the test rejects. So exactly when the level- test rejects.
Theorem (p-values are uniform under ). If fixes the distribution of , and its CDF is continuous, then under . Hence for every .
Proof.
- For a continuous , , so the p-value is the random variable .
- By the probability integral transform (lesson 02), when is continuous.
- If , then .
For a discrete statistic (counts, permutations), : the test is conservative. The exact coin test above rejects only if or . This region has probability under , not , because no region of exact size exists.
is true and the test statistic is continuous. You repeat the experiment many times and collect the p-values. What share of them is below 0.5?
Under a continuous null, , so for every . A true null does not give "large" p-values; it gives p-values spread evenly over . Try it in the Many p-values view of the simulator above with .
What a p-value is not.
- Not . That probability needs a prior, by Bayes' rule (lesson 01). Suppose 10% of the ideas that a team tests are real effects, its tests have power 0.8, and . Out of 1,000 ideas, 900 are null and give false positives; 100 are real and give true positives. So of the significant results are false. This is the same base-rate effect as the medical test of lesson 01.
- Not an effect size. A test statistic is roughly (effect / noise). An effect of with gives and . Report the estimate and a confidence interval, not only .
- Not evidence for when it is large. can mean "no effect" or "too little data". Only the power, or the width of the confidence interval, tells you which.
The t-tests #
Two distributions appear here. Both were introduced in lesson 06.
- The χ² distribution with degrees of freedom, , is the distribution of for i.i.d. . It is in the rate parametrisation, with mean .
- The Student t distribution with degrees of freedom, , is the distribution of for independent and . It has heavier tails than , and it tends to as . Its quantiles are larger: , , while .
Slide the degrees of freedom and compare the t density (orange) with the normal density (violet, dashed). The solid orange lines are , the dashed violet lines . Press Simulate to draw 2,000 samples of size from a normal distribution and compute for each: the blue histogram follows , not . With , about 8.2% of the values fall beyond (magenta tails), not 5%. This is why small samples need quantiles.
One-sample t-test. Data i.i.d. , with unknown. Let be the sample mean and the sample variance. To test use
Why . For Gaussian data, and are independent, and (Cochran's theorem). So is the standard normal divided by , which is the definition of . For non-Gaussian data with finite variance, by the CLT and Slutsky's lemma, so the test is still approximately valid for large . For small, skewed samples it is not.
Paired data. If and belong together (the same student before and after a course, the same test example scored by two models), compute the differences and run the one-sample t-test on them. Pairing removes the variation between the pairs, which is often most of the variation.
Two independent samples. Samples (size ) and (size ), with sample means and sample variances . Test .
- Student's t-test (pooled). Assume equal variances. Pool them, , and use .
- Welch's t-test. Do not assume equal variances. Use
which is approximately with the Welch–Satterthwaite degrees of freedom
Where the Welch–Satterthwaite comes from
Let , the estimated variance of . The idea: find the distribution that has the same mean and variance as .
- For Gaussian data, . So and .
- In the one-sample case, is exactly . So approximate by . This has mean and variance .
- Set the two variances equal and solve for : . Replace each by its estimate . This gives the formula above.
always lies between and . It is close to the lower end when one group has most of the uncertainty.
Which one to use. When , the two statistics are identical (only the degrees of freedom differ), so the pooled test is robust. When the sizes differ, the pooled variance weights each by its sample size. If the small group has the large variance, is too small, is too large, and the pooled test rejects far too often: in the setting of section 4, 22% of the time instead of 5%. Welch loses almost nothing when the variances are equal. Use Welch by default.
40 students take an exam before and after a course. You want to know if the course raised the scores. Which test fits?
The two scores of one student belong together. The differences remove the large variation between students (strong and weak students), so the paired test has much more power. The unpaired tests treat the two lists as independent samples, which they are not; they are valid only for independent groups.
Two proportions and the χ² tests #
Two-proportion z-test. Group 1 has successes in trials, group 2 has in . Let . Under , the difference has variance . Estimate the common by the pooled rate :
The two-sided p-value is .
Pearson's χ² test. Counts in categories, with expected counts under . The statistic is
- Goodness of fit. fixes the cell probabilities (for a fair die, ), so . Under , as . Why : the counts are approximately Gaussian (CLT), is a squared standardised distance, and the constraint removes one dimension. Each parameter that you estimate from the same data removes one more.
- Independence in an table. , and .
- Rule of thumb: all . Otherwise use an exact test (Fisher's exact test for a table) or a simulated null distribution.
For a table, Pearson's equals of the pooled two-proportion test, and is the
distribution of . So the two tests give the same two-sided p-value. Yates' continuity correction subtracts
from each in a table; it makes the test more conservative, and SciPy's
chi2_contingency applies it by default.
Confidence intervals and duality #
Definition. A confidence interval is a random interval with for every . This probability is the coverage (lesson 06 checks it by simulation).
95% coverage is a property of the procedure, before you see the data: if you repeat the study many times, about 95% of the intervals contain the fixed true . After you compute one interval, is either in it or not. The sentence " lies in this interval with probability 0.95" needs a prior; it describes a credible interval (lesson 10).
Theorem (duality of tests and intervals). For each value , let be a level- test of . Then the set of values that the test does not reject, , is a confidence set.
Proof.
- Fix the true . By the definition of , exactly when .
- So .
- tests a true null hypothesis, so .
The converse also holds: "reject when " is a level- test. So a level-0.05 test of "no difference" rejects exactly when the matching 95% interval excludes 0. The matching intervals are:
| Test | interval |
|---|---|
| one-sample or paired t | |
| Student (pooled) | |
| Welch | |
| two proportions |
The proportion interval uses the unpooled standard error, because no null hypothesis says there. So it is not the exact dual of the pooled z-test: when is close to , the test and the interval can disagree.
Multiple testing #
You test hypotheses, and of the null hypotheses are true. A procedure makes rejections ("discoveries"), and of them are false (true nulls that were rejected).
- Family-wise error rate: , the probability of at least one false discovery.
- False discovery proportion: ; the sets when .
- False discovery rate: , the average FDP over repeated studies.
Since , always . Without any correction, independent true nulls tested at level give : 0.40 for and 0.64 for .
Theorem (Bonferroni). Reject if . Then , under any dependence between the tests.
Proof. By the union bound over the true nulls, .
Holm's method is a step-down version that is never less powerful and also controls the FWER: sort the p-values, compare with for , and stop at the first failure.
The Benjamini–Hochberg (BH) procedure at level .
- Sort the p-values: .
- Find the largest with .
- Reject the hypotheses with the smallest p-values (none if no such exists).
BH is a step-up rule: a p-value above its own line is still rejected if a larger p-value lies below its line. The BH-adjusted p-values give the same decision: reject when .
Switch between the three rules and watch which p-values are rejected. Each dot is one test, sorted by its p-value (log scale). Aqua dots are real effects, violet dots are true nulls, and magenta dots are false discoveries. The orange line is the threshold of the rule: , , or the BH line ; everything left of the grey line is rejected. Press Run 500 studies: without a correction the FWER is close to 1; Bonferroni keeps it below 0.05 but finds few real effects; BH keeps the average FDP near and finds many more.
Theorem (BH controls the FDR). If the null p-values are independent of each other and of the non-null p-values, and each null p-value is , then .
Proof that BH controls the FDR (independent p-values)
Write , so . Let be the number of BH rejections when is replaced by 0. It depends only on the other p-values, and .
- Split by the value of : for a true null , .
- On the event , exactly when . If , then is among the smallest; moving it to 0 keeps the same smallest values and changes no larger order statistic. Conversely, if , putting back a keeps values below and can only raise the larger order statistics.
- By independence and uniformity, .
- So .
- Summing over the true nulls gives .
When BH controls the FDR under dependence
- Independent p-values: yes, at exactly .
- A specific kind of positive dependence (PRDS, positive regression dependence on the subset of nulls; Benjamini and Yekutieli, 2001): yes, . One-sided tests from jointly Gaussian statistics with nonnegative correlations are PRDS. Two-sided p-values of such statistics are in general not PRDS; BH usually works well there in practice, but the theorem does not guarantee it.
- Arbitrary dependence: not guaranteed. The Benjamini–Yekutieli procedure runs BH at level and controls the FDR in every case.
- FDR control is a statement about the average FDP over repeated studies. In one study the FDP can be well above .
FWER or FDR? Control the FWER when one false claim is costly: a confirmatory trial, a safety claim, a few planned comparisons. Control the FDR when you screen many hypotheses and follow up the hits: genes, features, grid cells, many metrics. Then a known small share of false leads is acceptable, and the FDR keeps much more power.
p-hacking and the garden of forking paths. A p-value is valid only for a test that was fixed before you saw the data. If you try several metrics, subgroups, outlier rules or tests and report the one with , you have run many tests but corrected for none. This is p-hacking. Even without bad intent, an analysis that would have been different for different data has the same problem (the "garden of forking paths"). The fix: write down the hypothesis, the metric, the test and before you look, and treat everything else as exploration.
A genomics study tests 10,000 genes and plans to check the hits in a second experiment. Which correction fits best?
Without a correction, about 500 null genes pass by chance. Bonferroni controls the chance of even one false hit, which is too strict for screening: almost no real effect survives . BH bounds the expected share of false leads among the hits, which is what matters when hits are checked again.
Answers to section 1. (1) Only (b). (a) is wrong because needs a prior: with 10% real effects and power 0.8, about 36% of the results with are true nulls. (c) is wrong because mixes the effect size with . (2) . Bonferroni at brings this back below 0.05. (3) About half the time: the power is about 0.5 (section 2).
4. Worked example #
A. Welch vs Student: a new course. A school tests a new online course. The score gain (after minus before, in points) of each student:
| course | mean gain | ||
|---|---|---|---|
| new | 8 | 6.2 | 5.0 |
| old | 30 | 3.0 | 2.0 |
Do the two courses give the same mean gain?
- Welch. Step 1, the two variance terms: and . Step 2, the standard error: . Step 3, the statistic: . Step 4, the degrees of freedom: . Step 5, the p-value: two-sided . Not significant at 5%. Step 6, the interval: with , it is . It contains 0, as duality requires.
- Student (pooled). , and . So with 36 degrees of freedom, and .
The two tests disagree: "not significant" against "significant at 1%". The pooled SE is too small. It is dominated by the 30 old-course students with a small spread, but the uncertainty of the difference comes mostly from the 8 noisy new-course students. Trust Welch. A simulation with these sizes and spreads, and equal true means, shows the pooled test rejecting 22% of the time at (section 5).
B. Two proportions: two sign-up pages. Page A is shown to 400 visitors and 18 sign up (). Page B is shown to 400 other visitors and 33 sign up ().
- Pooled rate: .
- Standard error under : .
- Statistic: , so . Significant at 5%.
- 95% interval with the unpooled SE : , that is 0.4 to 7.1 percentage points.
- The χ² test of the table (rows: page; columns: signed up or not) gives and the same . With Yates' correction, and .
C. χ² goodness of fit: is a weather ensemble calibrated? An ensemble forecast runs a weather model 9 times with slightly different starting states. For each of 200 forecast cases, rank the observation among the 9 members; there are 10 possible ranks. If the ensemble is calibrated, the observation behaves like one more member, so each rank has probability 1/10 and expected count 20. The observed rank histogram:
| rank | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| count | 31 | 22 | 17 | 15 | 14 | 13 | 16 | 18 | 21 | 33 |
. With degrees of freedom, ; the 5% critical value is 16.9. The U shape (too many observations outside the ensemble's range) says that the ensemble is underdispersed: its spread is too small. One caveat: the test assumes independent cases. Forecasts on consecutive days are correlated, which makes too large.
D. Multiple testing: drift in 8 features. A team checks whether each of 8 input features of a model has drifted between the training data and this month's data. Sorted p-values, and the BH lines at :
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|
| 0.0004 | 0.0021 | 0.0075 | 0.026 | 0.031 | 0.18 | 0.44 | 0.87 | |
| 0.00625 | 0.0125 | 0.01875 | 0.025 | 0.03125 | 0.0375 | 0.04375 | 0.05 | |
| below the line? | yes | yes | yes | no | yes | no | no | no |
- Bonferroni: the threshold is . It rejects 2.
- Holm: , , , then : stop. It rejects 3.
- BH: the largest below its line is . It rejects 5, including , which lies above its own line. This is the step-up rule. The adjusted p-values are . For example, .
5. In code #
SciPy checks the numbers of sections 2 and 4, and a simulation checks the type I error of the two t-tests.
import numpy as np
from scipy import stats
# coin: 61 heads in 100 flips
print(round(stats.binomtest(61, 100, 0.5).pvalue, 4)) # 0.0352 exact two-sided
print(round(2 * stats.norm.sf((61 - 50) / 5), 4)) # 0.0278 CLT approximation
# A. Welch vs Student from summary statistics (mean, sd, n)
new, old = (6.2, 5.0, 8), (3.0, 2.0, 30)
for equal_var in (False, True):
r = stats.ttest_ind_from_stats(*new, *old, equal_var=equal_var)
print(equal_var, round(r.statistic, 3), round(r.pvalue, 4))
# False 1.773 0.1161 (Welch)
# True 2.829 0.0076 (Student)
# B. two proportions = chi-squared test of the 2x2 table, without Yates' correction
table = np.array([[18, 382], [33, 367]]) # rows: page A, page B
chi2, p, dof, _ = stats.chi2_contingency(table, correction=False)
print(round(chi2, 3), round(np.sqrt(chi2), 3), round(p, 4)) # 4.712 2.171 0.0299
# C. goodness of fit of the rank histogram
print(stats.chisquare([31, 22, 17, 15, 14, 13, 16, 18, 21, 33])) # statistic 21.7, pvalue 0.0099
# D. Benjamini-Hochberg adjusted p-values
pv = np.array([0.0004, 0.0021, 0.0075, 0.026, 0.031, 0.18, 0.44, 0.87])
print(stats.false_discovery_control(pv, method="bh").round(4))
# [0.0032 0.0084 0.02 0.0496 0.0496 0.24 0.5029 0.87 ]
# type I error when H0 is true (equal means) with the sizes and spreads of example A
rng = np.random.default_rng(0)
x = rng.normal(0, 5.0, size=(20_000, 8)) # 20,000 simulated studies
y = rng.normal(0, 2.0, size=(20_000, 30))
for equal_var in (False, True):
pval = stats.ttest_ind(x, y, axis=1, equal_var=equal_var).pvalue
print(equal_var, np.mean(pval < 0.05))
# False 0.05 (Welch keeps the level)
# True 0.21825 (Student rejects 4 times too often)
chi2_contingency applies Yates' continuity correction to tables by default. Pass correction=False
when you compare with the z-test.
6. Where it shows up #
- Comparing ML models. Score both models on the same test examples or seeds and use a paired test: a paired t-test on per-seed scores, or McNemar's test for the errors of two classifiers on the same examples. With 3–5 seeds the interval for the gain is often wider than the gain. A leaderboard of many models on one test set is a multiple-testing problem.
- A/B tests. The two-proportion z-test (conversion rates) and Welch's t-test (revenue, time spent) are the standard analyses. A χ² test of the assignment counts detects a broken randomisation (sample-ratio mismatch, lesson 12).
- Drift monitoring. Tests on hundreds of input features every day need BH, or most alarms are false.
- Ensemble forecasts. The rank histogram of section 4C is a standard calibration check for weather and climate ensembles. Correlated cases (consecutive days, nearby stations) must be thinned or handled with an effective sample size.
- Maps of significance. A trend test in each of thousands of grid cells is tests at once; BH is the usual remedy. Neighbouring cells are positively correlated, so check the PRDS condition or use Benjamini–Yekutieli.
- Physics. The 5σ discovery rule is a one-sided p-value of . The "look-elsewhere effect" is a multiple-testing correction over the many places where a signal could have appeared.
7. Common mistakes #
- Reading as , or as "the probability that the result is due to chance". The p-value is computed assuming ; it cannot also give the probability of .
- "Not significant, so there is no effect." The interval of example 4A allows no effect and also a large one. To show that an effect is small, use an equivalence test (two one-sided tests, TOST) or a narrow interval.
- Statistical vs practical significance. With a huge every tiny effect is "significant". Report the effect size and its interval.
- The pooled t-test with unequal sizes and unequal variances. Use Welch.
- An unpaired test on paired data (it wastes power), or a test for independent data on dependent data (time steps, pixels, sessions of one user): the SE and are then too small.
- Choosing the test after seeing the data: one-sided after seeing the sign, or trying tests until . Fix the test, the metric and first.
- χ² with expected counts below 5, and forgetting that
chi2_contingencyapplies Yates' correction by default. - Ignoring multiplicity, or using Bonferroni to screen thousands of hypotheses (no power left).
- Reading FDR control as "each rejection is false with probability ". It bounds the average FDP over repeated studies, not the FDP of this study.
8. Check yourself #
- paired differences have mean 0.4 and . Test (two-sided) and give the 95% interval
().
Answer
, so with 24 degrees of freedom, and : not significant at 5%. The interval is . It contains 0 (duality), but it also contains effects as large as 0.8: the data cannot tell "no effect" from "a large effect". - Under , with a continuous test statistic, what is ? Why can be smaller than 0.05
for the exact binomial test?
Answer
0.2, because (probability integral transform). A discrete statistic takes only some values, so only some p-values are possible. The rejection region then has probability at most 0.05; for 100 coin flips it is 0.035. - A one-sided z-test at has effect and . What is its power? Which
gives power 0.8?
Answer
, so the power is . Power 0.8 needs , so and , that is . - When do the pooled and Welch t-statistics coincide? When does the pooled test reject far too often?
Answer
They coincide when : then and . Only the degrees of freedom differ. The pooled test rejects too often when the sizes differ and the smaller group has the larger variance, because the pooled variance then underestimates . - Ten independent tests, all nulls true, each at level 0.05. Give the FWER without correction and with Bonferroni.
Answer
Without correction: . Bonferroni tests each at : . The union bound gives for any dependence. - BH at rejects 40 hypotheses. A colleague says: "so exactly 4 of them are false discoveries." What is
right and what is wrong?
Answer
Wrong: BH bounds the *expected* false discovery proportion over repeated studies, (under independence or PRDS). It says nothing exact about these 40: can be 0 or well above 4, and you do not know which rejections are false. "About 4 or fewer" is a reasonable rough guess, not a guarantee.
Define the p-value.
The probability, computed under , of a test statistic at least as extreme as the observed one.
What are the type I and type II errors of a test?
Type I: rejecting when it is true (probability at most ). Type II: not rejecting when it is false (probability ).
What is the power of a one-sided z-test with effect , noise and observations?
.
What is the distribution of a p-value under when the test statistic is continuous, and why?
Uniform(0, 1), because and is uniform by the probability integral transform.
Write Welch's t statistic.
, compared with (Welch–Satterthwaite degrees of freedom).
Write the pooled two-proportion z statistic.
with the pooled rate .
What does the duality of tests and confidence intervals say?
The confidence set is the set of values that the level- test of does not reject.
State the Bonferroni rule and what it controls.
Reject if ; it keeps the FWER under any dependence (union bound).
State the Benjamini–Hochberg procedure.
Sort the p-values, find the largest with , and reject the smallest.
What is the difference between the FWER and the FDR?
FWER , the chance of any false discovery; FDR , the expected share of false discoveries among the rejections.
9. Interview angle #
- "Explain a p-value to a product manager." — If the change did nothing, a difference at least this large would show up in of repeated experiments. It is not the probability that the change does nothing.
- "Your test gives . What do you do?" — Report the estimate and the interval. Check the planned power. Do not extend the test until it becomes significant, and do not call it a "trend".
- "Student or Welch? And when not a t-test at all?" — Welch by default. For heavy tails or small skewed samples, use a permutation test, a bootstrap interval (lesson 12) or a rank test (Mann–Whitney). Mann–Whitney tests whether one group tends to give larger values (), not whether the means differ.
- "You test 100 features and 7 are significant at 5%. What do you conclude?" — Under the global null you expect 5 false positives. Use BH (screening) or Holm (confirmation), and validate on new data.
- "How are confidence intervals and tests related?" — Duality: the 95% interval is the set of null values that the 5% test does not reject.
- "What is the power of a test, and what increases it?" — The probability of rejecting when a given effect is real. It grows with the effect, with , with , and with less noise (pairing, a better metric).
10. Practice #
The notebook for this lesson has five exercises, each with a check cell and a folded solution:
- Write
welch_t_test(statistic, Welch–Satterthwaite , p-value) and compare it withscipy.stats.ttest_ind(equal_var=False). - Write
two_proportion_z_testwith its 95% interval, and check that equals the χ² statistic of the table. - Measure the type I error of Student's and Welch's tests by simulation, with unequal variances and sizes.
- Write
benjamini_hochberg(adjusted p-values) and compare it withscipy.stats.false_discovery_control. - Estimate the power of a z-test by simulation and compare it with the formula .
11. Watch and read #
- Philippe Rigollet, MIT 18.650 Statistics for Applications (2016), lecture slides, "Parametric hypothesis testing": errors, level, power and p-values; the χ² and t distributions; Student's and Welch's tests.
- Larry Wasserman, 36-705 lecture notes on multiple testing: the BH procedure, FDR vs FWER, and the proof that BH controls the FDR under independence.
- Kevin Murphy, Probabilistic Machine Learning: An Introduction, free PDF: §4.7.4–4.7.5 (confidence intervals are not credible intervals) and §5.5 (type I and II errors, p-values, "p-values considered harmful").
- SciPy
scipy.statsreference:ttest_ind(equal_var=Falseis Welch),chi2_contingency(correction),chisquare,false_discovery_control.
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.
No Google account needed: Python runs inside your browser. The first start downloads about 40 MB; your changes are saved in this browser only.