Hypothesis testing and effect sizes
Quick answer
Hypothesis testing compares an observed statistic with its distribution under a specified null model. A p-value is the probability, under that null model and its assumptions, of a test statistic at least as extreme as the observed statistic according to the chosen test. It is not the probability that the null hypothesis is true. Report the magnitude of the effect and its uncertainty, not just a threshold decision.
A tiny randomized comparison
Four independent fictional jobs have fixed outcomes [1, 2, 5, 6] seconds under a sharp no-treatment-effect null. Exactly two jobs were randomly assigned to each configuration, with all six assignments equally probable. Observed group A contains the first two jobs (mean 1.5), group B the last two (mean 5.5). The observed A−B difference is −4 seconds. For a two-sided randomization test use absolute differences and enumerate all six assignments, including ties and the observed assignment. Two assignments give an absolute difference ≥4; the exact p-value is 2/6. A small number of assignments limits resolution.
from itertools import combinationsx=[1,2,5,6]observed=abs((1+2)/2-(5+6)/2)diffs=[]for a in combinations(range(4),2): sa=sum(x[i] for i in a) diffs.append(abs(sa/2-(sum(x)-sa)/2))print(diffs)print(round(sum(d>=observed for d in diffs)/len(diffs), 4))Expected output (local Python 3.13.5):
[4.0, 1.0, 0.0, 0.0, 1.0, 4.0]0.3333A sizable observed difference is not strong evidence against this null in the tiny randomized design. In observational comparisons exchangeability must be justified, not assumed.
Error rates, effects and multiple tests
Choose the null, alternative, test statistic, tail and significance level α before examining results. Type I error is rejecting a true null; Type II error is failing to reject under a specified alternative, and power is one minus that probability. Failing to reject does not establish equivalence. Effect size may be a raw mean difference in seconds, a difference in accuracy in percentage points, or an appropriate standardized effect. Define a practically meaningful threshold before testing. With m prespecified valid tests, Bonferroni uses α/m for each rejection to control the probability of one or more false rejections at at most α, without requiring independent tests. This may reduce power. Report all tested comparisons; repeated model selection on the same holdout invalidates naive inference.
alpha=0.05p_values=[0.003,0.012,0.04,0.5]cutoff=alpha/len(p_values)print(cutoff)print([p <= cutoff for p in p_values])Expected output (local Python 3.13.5):
0.0125[True, True, False, False]Only the first two pass the adjusted threshold. This does not establish that the corresponding effects are practically useful.
Common mistakes
Do not interpret p=0.03 as a 3% chance the null is true. Permutation redistributes labels according to a valid null design; it differs from bootstrap draws with replacement. Do not report only the smallest p-value across model variants. A high p-value may reflect low power. A statistical comparison on a fixed held-out dataset does not automatically establish production benefit or causality.
Practice and next steps
Suppose 20 comparisons are planned at familywise α=0.05. Compute the Bonferroni threshold; interpret a p-value of 0.004 and describe what else you need to judge the effect. Next, study optimization objectives and numerical stability.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Hypothesis testing and effect sizes — knowledge check
Apply statistical reasoning to original synthetic examples.
A p-value is computed assuming what?
What is a Type I error?
With 5 equally likely assignments and 2 at least as extreme as observed, what is the exact p-value?
For 10 valid planned tests and familywise α=0.05, what is the Bonferroni threshold?
Which is best when reporting a model comparison?