A brief note on Testing an Idea with Simulation . Read it before a test. Try each question at the end before you open its answer.
Words and rules Null idea H 0 H_0 H 0 : nothing special is going on (a fair coin, no difference). Alternative H a H_a H a : what we suspect. One-sided ( p > 0.5 p > 0.5 p > 0.5 ) or two-sided ( p ≠ 0.5 p \ne 0.5 p = 0.5 ), chosen before seeing the data. p-value: if H 0 H_0 H 0 were true, the chance of a result at least as extreme as the one seen. By simulation: the share of simulated results at least as extreme. Shuffling test: pool two groups, shuffle the labels, and count the shuffles at least as extreme. Decision: reject H 0 H_0 H 0 when the p-value is at most α \alpha α , usually 0.05 0.05 0.05 . Otherwise do not reject it. Type I error: a false alarm, with probability α \alpha α when H 0 H_0 H 0 is true. Type II error: a missed effect. A larger sample makes it rarer. Many tests: 1 − ( 1 − α ) m 1 - (1 - \alpha)^m 1 − ( 1 − α ) m is the chance of at least one false alarm. A worked example A fair coin is tossed 20 20 20 times, and 15 15 15 heads appear.
Ideas. H 0 H_0 H 0 : p = 0.5 p = 0.5 p = 0.5 . H a H_a H a : p > 0.5 p > 0.5 p > 0.5 . p-value. Count the results with 15 15 15 or more heads: 15 504 + 4845 + 1140 + 190 + 20 + 1 = 21 700 15\,504 + 4845 + 1140 + 190 + 20 + 1 = 21\,700 15 504 + 4845 + 1140 + 190 + 20 + 1 = 21 700 . Then P ( X ≥ 15 ) = 21 700 2 20 ≈ 0.0207 P(X \ge 15) = \dfrac{21\,700}{2^{20}} \approx 0.0207 P ( X ≥ 15 ) = 2 20 21 700 ≈ 0.0207 . Decision. 0.0207 ≤ 0.05 0.0207 \le 0.05 0.0207 ≤ 0.05 : reject H 0 H_0 H 0 at the 0.05 0.05 0.05 level. Practice with new numbers
A program to try The program finds the p-value of the worked example and the chance of a false alarm among 20 20 20 tests.
Run it. Does the first line match step 2?
1. Change range(15, 21) to range(14, 21). Is 14 14 14 heads still significant at the 0.05 0.05 0.05 level?
Mistakes to avoid Reading the p-value as the chance that H 0 H_0 H 0 is true. Saying "we accept H 0 H_0 H 0 ". Say "we do not reject it". Calling a significant result important. Check the size of the effect. Hiding the tests that did not work. Check yourself In 1000 1000 1000 shuffles, 8 8 8 are at least as extreme as the real difference. What is the p-value? Stuck? Show a hint Show the answerA test at α = 0.05 \alpha = 0.05 α = 0.05 gives a p-value of 0.07 0.07 0.07 . What is the decision? Stuck? Show a hint Show the answerA true null idea is rejected. Which error is this? Stuck? Show a hint Show the answerWhy must the groups of a shuffling test be formed at random to speak of cause? Stuck? Show a hint Show the answerFind the chance of at least one false alarm among 5 5 5 independent tests at α = 0.05 \alpha = 0.05 α = 0.05 . Stuck? Show a hint Show the answerSources OpenStax, Introductory Statistics , Chapter 9, hypothesis testing with one sample. OpenIntro, OpenIntro Statistics , Chapter 5, foundations for inference.