Hypothesis testing, the p-value and the two kinds of error
A new page variant converts at 4.8 per cent instead of 4.0 — a real improvement or chance? A statistical test turns that question into arithmetic: a null hypothesis, a test statistic, a rejection region and a p-value. Together with what a p-value does NOT say, because it is the most abused number in science.
Before you start
This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:
- Estimation and confidence intervalsA thousand people were surveyed and the conclusion is meant to be about thirty million. An estimator turns a sample into a number, the standard error says how much that number wobbles, and a confidence interval turns one value into an honest range — together with the arithmetic for how many observations a given range costs.
- The normal distributionThe bell curve describes heights, measurement errors, exam scores and packet weights — and that is no coincidence but the content of the central limit theorem. Two numbers, μ and σ, say everything there is to say about such a distribution, and the 68–95–99.7 rule lets you read it without tables.
Where this is used
Real situations where you count exactly the way this lesson teaches:
- An A/B testVariant A converts at 4.0 per cent. Variant B gets 2500 views and converts 120 times, that is 4.8 per cent. Under the hypothesis that nothing changed, the standard error is √(0.04 · 0.96 / 2500) ≈ 0.0039, so z = (0.048 − 0.040)/0.0039 ≈ 2.04. That clears 1.96, so at α = 0.05 the null hypothesis is rejected — but only just, and the rollout decision should say so.
- A clinical trialA drug is supposed to lower systolic pressure. Across 64 patients the mean drop was 5 mmHg with a deviation of 12 mmHg. The standard error is 12/√64 = 1.5, so z = 5/1.5 ≈ 3.33 — above 2.58, so the result is significant even at the 1 per cent level. Whether 5 mmHg is clinically important is a wholly separate question from whether it is statistically significant.
- Monitoring a production lineA filling machine is set for 500 g. An inspector weighs 100 packs: mean 499.4 g, deviation 2 g. The standard error is 0.2 g, so z = (499.4 − 500)/0.2 = −3. An absolute value of 3 clears 1.96, so the 0.6 g shortfall is not chance — across 20 000 packs a day that is 12 kg less product than the label promises.
- Is the die fairIn 600 throws a six came up 120 times instead of the expected 100. Under the fair-die hypothesis the standard deviation of the count of sixes is √(600 · 1/6 · 5/6) ≈ 9.13, so z = 20/9.13 ≈ 2.19. That clears 1.96, so at α = 0.05 the die is judged unfair — although at α = 0.01, where the boundary is 2.58, this data would not have been enough.
All formulas
Null and alternative hypothesis
H₀ always carries the equality — that is the computable one
Test statistic for a mean
how many standard errors the sample sits from the hypothesis
Decision rule (two-sided test)
z_{α/2} = 1.96 for α = 0.05
The p-value
the probability of SUCH DATA given H₀ — not of H₀ given the data
Type I error
a false alarm; fixed in advance
Type II error
missing an effect that is really there
Power of a test
the chance of detecting an effect that exists
The previous lesson answered the question how much — what the mean is and how precisely we know it. This one answers the question whether: whether an observed difference is real, or within the reach of chance.
A new page variant converts at instead of . A filling machine dispenses g instead of . A drug lowered blood pressure by mmHg. Every time the question is the same: is this an effect, or is it noise.
Two hypotheses
A test begins with a pair of claims about the population:
The null hypothesis says nothing is happening: the mean equals the nominal value, the variants convert alike, the drug does not work. The alternative hypothesis says something is.
The pair is asymmetric, and that is the first thing to understand:
- always carries the equality, because only then can the distribution of the test statistic be computed. Writing fixes one particular distribution; writing fixes infinitely many.
- stands until the data overturns it. A test never "proves" ; at best it rejects it or fails to. This is the same asymmetry as in a courtroom: innocence is assumed until guilt is shown, and an acquittal does not mean innocence was proved.
The alternative can also be one-sided (), when only one direction is of interest in advance — whether a drug lowers pressure, rather than whether it changes it. The direction must then be fixed before the data is seen; we come back to that in the section on abuses.
The test statistic
Since fixes a distribution, we can ask how unusual our sample is relative to that distribution. The measure of unusualness is the test statistic:
The numerator is the sample's departure from the hypothesis; the denominator is the standard error of the previous lesson. The quotient therefore says how many standard errors the sample mean sits from what claims.
Dividing by is the heart of it: the same g shortfall is nothing at and an alarm at . That step is exactly what separates a test statistic from the plain standardisation of a single observation in the normal-distribution lesson.
The rejection region and the significance level
It remains to settle how unusual a sample has to be to overturn . The boundary is set by the significance level — the acceptable probability of a false alarm.
The decision rule is a single comparison:
| two-sided test | one-sided test | |
|---|---|---|
These are the same values the estimation lesson matched to confidence levels — and that is no coincidence. We come to the link between the two calculations in a moment.
For the machine in the example , so we reject the hypothesis that it dispenses g.
The p-value
Comparing against a boundary gives a yes/no answer but loses the information about how extreme the result was. That is what the p-value carries:
In words: the probability of observing data at least as extreme as ours, assuming is true. The smaller it is, the worse the data fits the null hypothesis.
The decision rule can therefore be written a second, equivalent way: reject when . Three numbers from the three-sigma rule are enough to read p-values without tables:
| two-sided | one-sided | |
|---|---|---|
The direction of the conditioning in the definition is everything, and we return to it in the section on abuses: , not . That is the same difference as between and in the conditional probability lesson.
The two kinds of error
A decision made from a sample can be wrong in two ways — and they are entirely different errors:
| true | false | |
|---|---|---|
| reject | Type I error () | correct (power) |
| fail to reject | correct | Type II error () |
- Type I error — a false alarm: announcing an effect that is not there. Its probability is and we set it ourselves, in advance.
- Type II error — a miss: the effect exists and we do not detect it. Its probability depends on how large the effect is and how large the sample is.
- Power is — the chance of detecting an effect that really exists. The conventional floor of respectability is .
The picture shows what the table cannot: both errors are fighting over the same boundary. Moving the mark to the right (tightening ) shrinks the shaded tail and at the same time enlarges the part of the right curve to the left of the mark. The only way to shrink both at once is to pull the curves apart or narrow them — a bigger effect or a bigger sample.
A test and a confidence interval
The two calculations of this lesson and the previous one are the same calculation written from two sides:
A two-sided test at level rejects exactly when lies outside the confidence interval at level .
That is why more and more journals require an interval alongside the p-value: the interval says how large the effect is and how precisely it was measured, the p-value only whether it cleared a threshold.
Where this mathematics gets abused
This is the most abused calculation in science, so there are five abuses.
1. The p-value read as the probability of the hypothesis
", so there is only a 3 per cent chance the null hypothesis is true." False, and it swaps the conditioning: is , while that sentence is about .
The correction: the right wording is "if were true, data as extreme as ours would turn up in 3 per cent of studies". To say anything about the probability of the hypothesis itself you need a prior and Bayes' formula — and the test does not take that road. For hypotheses that are rarely true a priori, can sit in the tens of per cent even at .
2. "Absence of evidence" read as "evidence of absence"
", so the drug does not work." No: means this data was not enough to reject . Perhaps there is no effect — or perhaps the sample was too small to detect it, i.e. the test had low power.
The correction: the conclusion is "we do not reject ", never "we confirm ". To actually demonstrate the absence of an effect there is the equivalence test, or a confidence interval that excludes every practically important effect.
3. Statistical significance mistaken for importance
With a large enough sample every difference becomes statistically significant, because the standard error shrinks like . At a million observations a conversion difference of percentage points gives — and means nothing whatsoever to the business.
The correction: significance says "this is not noise", not "this matters". The effect size and its confidence interval are a separate and equally necessary piece of information; the threshold of practical importance is set by the field, not by statistics.
4. p-hacking and multiple testing
Run twenty independent tests at with every null hypothesis true, and on average one comes out significant. Not because something was discovered, but because that is how was defined. The same arithmetic sits behind adding observations "until it works", dropping outliers after the fact, testing many variables and hunting for the subgroup where it came out.
The correction: hypothesis and analysis plan fixed before the data is collected, and with many tests a correction for multiplicity — the simplest is the Bonferroni rule, dividing by the number of tests. Preregistering a study is the practical version of the same principle.
5. Choosing the hypothesis after seeing the data
Switching from a two-sided to a one-sided test after seeing which way the data leaned doubles the stated : a result with two-sided becomes "significant" at . The same trick, under the name HARKing, consists of phrasing a hypothesis to fit a pattern that was found and presenting it as though it had been stated in advance.
The correction: the direction of the test, and the hypothesis itself, are part of the plan, not of the result. An analysis that found a pattern cannot confirm it with the same data — that takes a fresh sample.
Exercises
The first set walks the three steps of one test. The z prompt gives , , and and asks for the test statistic — remember to divide by , because without that step you are standardising a single observation rather than a mean.
The "p-value" prompt gives and asks for the area of the tail, as a percentage, one-sided in some draws and two-sided in others; both read off the three-sigma rule. The third prompt adds a critical value and asks for the verdict: the answer is the symbol of the hypothesis that stands, H₀ or H₁. You may type H0 and H1.
Practice
Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.
The second set is authored and asks about what the generator does not compute: the link between and the Type I error, between power and the Type II error, the verdict read straight off a p-value and off a confidence interval, and the arithmetic of multiple testing. Where the answer is a hypothesis, write H₀ or H₁.
Practice
Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.
Naming which kind of error a particular situation risks has no number for an answer and stays content — the table above settles all four cases.
Common mistakes
- Reading p as the probability of the null hypothesis — , not the other way round; swapping the conditioning is the same slip as confusing with .
- Concluding "we proved there is no effect" — a test can only reject or fail to; absence of evidence is not evidence of absence.
- Confusing significance with importance — on a large sample every difference becomes significant, including differences of no practical consequence.
- Setting , or the direction of the test, after seeing the data — either one invalidates the stated significance level; switching to a one-sided test after the fact doubles it.
- Dropping the from the denominator — without it you are standardising a single observation, and the test is about a sample mean.
- Repeating a test until it succeeds — twenty tests at produce one significant result on average even when there is nothing to find.
- Tightening without looking at power — a smaller always raises ; both fall together only on a larger sample.
Formula card
Topic: Hypothesis testing
Null and alternative hypothesis
H₀ always carries the equality — that is the computable one
Test statistic for a mean
how many standard errors the sample sits from the hypothesis
Decision rule (two-sided test)
z_{α/2} = 1.96 for α = 0.05
The p-value
the probability of SUCH DATA given H₀ — not of H₀ given the data
Type I error
a false alarm; fixed in advance
Type II error
missing an effect that is really there
Power of a test
the chance of detecting an effect that exists
