A11 · Lesson 38 · Hypothesis tests
Deciding whether a difference is real or just noise
A new soldering process gives 12 defects in 1000 boards, against the old rate of 2%. Did the process improve, or did this batch just get lucky? An amplifier's offset reads 1.1 mV averaged over 16 readings with 2 mV of noise each. Is the offset really nonzero? A hypothesis test turns these into a calculation: how often would noise alone produce a result this far from "no change"? It's the same reasoning a radar or a receiver uses to decide whether a signal is there, with the same two ways to be wrong.
- The left curve is the distribution of the average of readings if nothing has changed (the null hypothesis, mean 0). The right curve is the same if the true mean has shifted by . Each reading has noise σ = 1.
- You declare "changed" when the average exceeds the threshold . The shaded tail of the left curve is the false alarm rate; the part of the right curve below is what you miss.
- Raise . Both curves narrow, so you can lower the false alarms and the misses at the same time.
Predict
Sixteen readings with 2 mV of noise each average 1.1 mV. If the true offset were zero, how often would the average land at least this far from zero, either way?
About 3%. The average has standard error mV, so 1.1 mV is standard errors out, and . Noise alone would rarely do this, so the offset is probably real. That 2.8% is the p-value of the test.
Name it
The setup
- The null hypothesis is "no effect": the offset is zero, the defect rate is unchanged, there's no signal.
- The alternative is the effect you're looking for.
- A test statistic summarizes the data, usually as a -score: how many standard errors the estimate sits from the value predicts.
For a mean with known noise σ and readings:
For a proportion against a claimed , with the Gaussian approximation:
p-values and significance
The p-value is the chance, if were true, of a result at least as extreme as the one seen. A one-sided test counts one tail, ; a two-sided test counts both, . You reject when the p-value is below a significance level chosen in advance, often 5% or 1%. Equivalently, reject when passes a threshold: 1.645 one-sided or 1.96 two-sided at 5%.
The p-value is not the chance that is true. That would need a prior and Bayes' rule (lesson 5).
Two kinds of error
| true | true | |
|---|---|---|
| reject | type I error (false alarm), rate | correct; rate is the power |
| keep | correct | type II error (miss), rate |
For a fixed amount of data, moving the threshold trades one error for the other. Only more data, or a bigger effect, reduces both. For a one-sided test of a mean shift at level :
Lesson 42 uses exactly this tradeoff to set a receiver's decision threshold.
Worked example
Is the amplifier's offset nonzero? Sixteen readings average 1.1 mV, with 2 mV of noise each.
Show the solution
- Test statistic.
- p-value. Two-sided, since an offset could have either sign:
- Decide. That's below 5%, so reject "zero offset" at the 5% level, though not at 1%.
Answer yes at the 5% level (), though not at the 1% level.
Worked example
The old process had a 2% defect rate. A new one gives 12 defects in 1000 boards. Is it better?
Show the solution
- Estimate.
- Standard error under .
- Test statistic.
- p-value. The question is one-sided (better means lower), so
- Decide. Significant at 5% but not at 1%: promising, and worth a larger trial before retooling the line.
Answer probably: is significant at 5% but not at 1%, so it's worth a larger trial.
Worked example
A coin gives 60 heads in 100 flips. Is that evidence it's biased?
Show the solution
- Under a fair coin. The count has mean 50 and standard deviation so 60 is standard deviations out.
- p-value. Two-sided: just under the conventional 5% line.
- Decide. It suggests a bias without proving it; a few hundred more flips would settle it.
Answer it's weak evidence of bias: , just under the 5% line.
Check
25 readings with noise 2 mV each average 0.8 mV. What is the -statistic for "the true mean is zero"?
Check
A two-sided test gives = 2.4. What is the p-value?
Check
A defect rate was 0.02. A new process shows a rate of 0.7 times that in 1000 boards. What is the one-sided p-value for "no improvement"?
Check
Each reading has 2 mV of noise. Above what average of 4 readings should you declare "positive offset", for a 5% one-sided false alarm rate? (The 5% point of the Gaussian is .)
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
Same kind of test: noise 2 mV per reading, 16 readings, one-sided at 5%. The true offset is 1.5 mV. What is the chance the test detects it?
Check
A test gives a p-value of 0.03. What does that mean?
Check
A coin gives 60 heads in 100 flips.
(a)
How many standard deviations is that from 50?
(b)
What is the two-sided p-value?
Check
readings with noise average . Test whether the true mean is 0.
Step 1
What is the statistic?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Check
Write p_value(mean, sigma, n) returning the two-sided p-value for testing a zero true mean from n readings with noise sigma and average mean. Set p1 = p_value(1.1, 2, 16).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why can't you reduce both false alarms and misses just by choosing a better threshold?
The threshold divides the possible results into "declare a change" and "don't". Raising it pushes more of the no-change distribution below it, cutting false alarms, but also pushes more of the changed distribution below it, adding misses. Lowering it does the opposite. With fixed data the two distributions overlap by a fixed amount, and the threshold only decides where the overlap's errors go. To cut both you must shrink the overlap: average more readings so each distribution narrows, or look for a bigger effect.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.