Definition
A hypothesis test is a rule that uses data to decide whether to reject a stated model of how the data arise, called the null hypothesis, in favor of an alternative hypothesis. The rule computes a test statistic, one number that summarizes the data, and rejects the null hypothesis when the statistic falls in a rejection region fixed in advance. The region is chosen so that, if the null hypothesis is true, rejection happens with probability at most (alpha), a chosen significance level such as 0.05.
The idea
A developer runs a benchmark three times on build A and three times on build B. Build B’s runs are all faster, by 0.4 milliseconds (ms) on average. Two identical builds would also differ a little from run to run, because of caches, interrupts §6.11 and timing noise. The question is whether noise alone often produces a difference this large, or rarely.
A hypothesis test answers by assuming the dull explanation, the null hypothesis that the build makes no difference, and asking how often that world would produce a result at least as striking as the observed one. If rarely, the test rejects the null hypothesis. A criminal trial is a fair picture: the defendant is presumed innocent, and conviction needs strong evidence. An acquittal does not prove innocence, just as failing to reject does not prove the null hypothesis. The picture stops at the error rate. The significance level limits wrongful rejections over many uses of the rule in cases where the null hypothesis is true; it is not the probability that one particular verdict is wrong.
How it works
A test is fixed by six decisions, made before the outcome is seen.
The null hypothesis : a precise probability model for the data when the effect of interest is absent. Example: each run would have produced the same latency whichever build it received.
The alternative hypothesis : the effect the test is meant to detect, with its direction. A one-sided alternative (build B is faster) looks in one direction; a two-sided alternative (the builds differ) looks in both.
The design: the experimental unit §11.3 (the thing that independently receives a condition, here a run), how many units there are, how conditions are assigned to them, whether measurements are paired, and when data collection stops.
The test statistic and which of its values count as more extreme, meaning further in the direction of the alternative. Example: is the mean latency of A minus the mean latency of B, and larger is more extreme.
The significance level .
The rejection region: the most extreme values of , chosen so that their total probability is at most when is true.
The distribution of when is true is called the null distribution, or reference distribution. It follows from the null hypothesis together with the design, in one of three common ways. A randomization §11.8 test, also called a permutation test, takes it from the random assignment of conditions that the experimenter carried out. A model-based test such as Student’s t-test takes it from a mathematical model: independent units whose measurements follow a normal (bell-shaped) distribution, or enough units that their averages approximately do. A rank test such as the Wilcoxon–Mann–Whitney test replaces the values by their ranks and assumes independent units drawn from continuous distributions. The three kinds rest on different assumptions and test slightly different null hypotheses.
The experiment then runs, is computed, and the test rejects if and only if lies in the rejection region. Equivalently, the test computes the p-value §11.23, the probability under of a statistic at least as extreme as the one observed, and rejects when the p-value is at most .
A test can err in two ways. A Type I error §1.22 rejects a true null hypothesis: a false positive, an effect reported that is not there. The design limits its probability to . A Type II error fails to reject when a stated alternative is true: a false negative, a missed effect. Its probability is written (beta), and is the statistical power §11.25 of the test against that alternative. This decision-rule form with two kinds of error was developed by Jerzy Neyman and Egon Pearson in papers published from 1928 to 1933 [472, 473]. Ronald Fisher’s earlier significance tests used the p-value as a graded measure of evidence against the null hypothesis.
Worked example
Six benchmark runs are available. Three are chosen by lot to run build A, and the other three run build B; this random assignment is the design. The measured latencies, in ms, are 10.2, 10.3 and 10.4 for A, and 9.8, 9.9 and 10.0 for B. The null hypothesis is Fisher’s sharp null hypothesis: every run would have produced the same latency under either build. The alternative is one-sided: B is faster. The statistic is ms. The significance level is .
If is true, the six latencies are fixed and only the labels A and B depend on the lot. The lot could have chosen any 3 of the 6 runs for A: equally likely assignments, where is the number of ways to choose items from . The six values sum to 60.6 ms, so , where is the sum of the three values labeled A. is largest when A holds the three largest values: and ms. The next largest sum, , gives only ms. So exactly 1 of the 20 assignments gives ms.
Under , the probability of ms is therefore . The rejection region “ ms” has probability exactly , the observed lies in it, and the test rejects . The justification is the lot itself: the 20 assignments were equally likely by construction, so no assumption about normal distributions or about the noise was needed.
The design also limits what the test can show. With 3 runs per build the smallest possible one-sided p-value is . A two-sided test also counts the mirror assignment, with A holding the three smallest values, as equally extreme, so its smallest p-value is : a two-sided test at can never reject with this design, whatever the data. Four runs per build give assignments and a smallest two-sided p-value of .
The procedure around the test matters too. Suppose the developer repeats the six-run experiment with fresh runs until one repetition rejects, and reports only that one. If the builds are identical, each repetition rejects with probability 0.05, independently of the others, so at least one of five repetitions rejects with probability . The reported test looks like a test at level 0.05, but the procedure that produced it has a Type I error rate of about 23% after five tries. Stopping and reporting rules are part of the design.
Stated precisely
Let be a set of probability distributions for the data: one distribution for a simple null hypothesis, several for a composite one. Let be the test statistic and the rejection region. The test has level when where is probability computed as if generated the data. The largest of these probabilities (strictly, their least upper bound §19.2.6) is the size of the test; for a discrete statistic it can be smaller than . For a distribution in the alternative, is the power of the test against , and is its Type II error probability.
The guarantee depends on three conditions.
The null model matches the design. contains the distribution that actually generates the data when the effect is absent, including how units were sampled or assigned, which measurements are independent and which are paired.
Everything fixed in advance. , , and the stopping rule were fixed without looking at the outcome. A choice made after looking is part of the procedure, and then the error rate of the whole procedure is what counts.
One test. The guarantee covers this one test. A study that runs many tests needs an error rate for the whole family, which the Multiple comparisons §11.26 entry treats.
The level is a long-run rate: if the rule were applied many times to data for which is true, at most a fraction of the applications would reject. It is not the probability that is true after a rejection, and not the probability that a particular rejection is wrong.
Limits and common mistakes
Failing to reject is not evidence of no effect; the design may simply have had little power. To claim that two systems are equivalent, fix a margin (delta), the largest difference that does not matter, and use an equivalence test. One such test is the procedure of two one-sided tests: it must reject both “the difference is at most ” and “the difference is at least ”.
Rejecting is not evidence of a large or useful effect. With many units a test rejects for a difference far too small to matter. Report the effect size §11.24 and its confidence interval §11.18.
Rejecting does not show what caused the difference. Random assignment of conditions, as in the example, supports a causal reading. In a comparison without random assignment, confounding §11.10, a third factor that affects both the condition and the outcome, can produce the difference.
The wrong unit gives the wrong null distribution. Treating 10,000 events from 3 sessions as 10,000 independent units makes rejection far too easy; this error is called pseudoreplication §11.6.
Choosing the test after seeing the data breaks the guarantee. Running a one-sided test in whichever direction the data point turns a nominal level into a real Type I error rate of . Trying several tests and keeping the smallest p-value raises it further.
Questions answered
What null hypothesis, alternative, and sampling design justify the test?
A test is justified when its null distribution, the distribution of the test statistic when there is no effect, follows from the stated null hypothesis together with the way the data were actually sampled or assigned. The justification must therefore name three things, all fixed before the data are seen. The null hypothesis is a precise model of the data without the effect, for example “each run would have the same latency under either build” or “the latencies of both builds come from one distribution”. The alternative names the effect to be detected and its direction, one-sided or two-sided, chosen from the scientific question. The sampling design names the experimental unit and how many units there are, how conditions were assigned to units (at random or not), whether measurements are paired, how measurements are grouped into sessions or devices, and when data collection stops.
The design then selects the test. Random assignment of conditions to units justifies a randomization test, whose null distribution comes from the assignment itself. Independent units whose measurements are normally distributed, or numerous enough that their averages are, justify a t-test. Independent units from continuous distributions justify a rank test such as the Wilcoxon–Mann–Whitney test. Many measurements inside a few sessions or devices justify only a test whose unit is the session or the device. The test is chosen from the question and the design, never by which test gives the smallest p-value.
Related entries: p-value (§11.23), Effect size (§11.24), Statistical power (§11.25), Multiple comparisons (§11.26), False positive and false negative (§1.22), Randomization (§11.8). Further reading: [171, 472, 473].