A1138 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 n readings if nothing has changed (the null hypothesis, mean 0). The right curve is the same if the true mean has shifted by d. Each reading has noise σ = 1.
  • You declare "changed" when the average exceeds the threshold c. The shaded tail of the left curve is the false alarm rate; the part of the right curve below c is what you miss.
  • Raise n. 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?

Name it

The setup

  • The null hypothesis H0 is "no effect": the offset is zero, the defect rate is unchanged, there's no signal.
  • The alternative H1 is the effect you're looking for.
  • A test statistic summarizes the data, usually as a z-score: how many standard errors the estimate sits from the value H0 predicts.

For a mean with known noise σ and n readings:

z=x¯−μ0σ/n

For a proportion p^=k/n against a claimed p0, with the Gaussian approximation:

z=p^−p0p0(1−p0)/n

p-values and significance

The p-value is the chance, if H0 were true, of a result at least as extreme as the one seen. A one-sided test counts one tail, Q(z); a two-sided test counts both, 2Q(|z|). You reject H0 when the p-value is below a significance level α chosen in advance, often 5% or 1%. Equivalently, reject when z passes a threshold: 1.645 one-sided or 1.96 two-sided at 5%.

The p-value is not the chance that H0 is true. That would need a prior and Bayes' rule (lesson 5).

Two kinds of error

H0 trueH1 true
reject H0type I error (false alarm), rate αcorrect; rate is the power 1−β
keep H0correcttype 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 d at level α:

power=Q(zα−dσ/n)

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
  1. Test statistic. z=1.1−02/16=2.2
  2. p-value. Two-sided, since an offset could have either sign: p=2Q(2.2)=0.028
  3. Decide. That's below 5%, so reject "zero offset" at the 5% level, though not at 1%.

Answer yes at the 5% level (p=0.028), 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
  1. Estimate. p^=0.012
  2. Standard error under H0. 0.02×0.98/1000=0.00443
  3. Test statistic. z=0.012−0.020.00443=−1.81
  4. p-value. The question is one-sided (better means lower), so p=Q(1.81)=0.035
  5. Decide. Significant at 5% but not at 1%: promising, and worth a larger trial before retooling the line.

Answer probably: p=0.035 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
  1. Under a fair coin. The count has mean 50 and standard deviation 100×0.25=5 so 60 is z=2 standard deviations out.
  2. p-value. Two-sided: 2Q(2)=0.046 just under the conventional 5% line.
  3. Decide. It suggests a bias without proving it; a few hundred more flips would settle it.

Answer it's weak evidence of bias: p=0.046, just under the 5% line.

Check

25 readings with noise 2 mV each average 0.8 mV. What is the z-statistic for "the true mean is zero"?

Check

A two-sided test gives z = 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 z=1.645.)

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

n readings with noise s average m. Test whether the true mean is 0.

Step 1

What is the z 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?

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.