HomeAll tracks · pricing · account
Python11 apps · Python, SQL & data
Start free Log in

🪤 The Trap Gallery82 trapsFree for everyone

The classic misuses, simulated

Each card runs thousands of experiments in your browser. Unless it says otherwise, none of them has a real effect, so an honest test raises a false alarm 5 % of the time. Watch the misuse break that promise, then open the lesson for the honest version.

Lesson 01 · How every test works

Trying tests until one says yes

The same data can be tested many ways: means, logs, ranks, without the outlier, just one subgroup… Try several, report the best-looking one, and you are no longer running a 5 % test.

The honest version

Choose the test (and what you’ll do about outliers) **before** you look at the results, and write it down. If you did try several, say so and report them all.

Lesson 1: Signal or noise? The test behind every test →

Lesson 02 · How every test works

“p = 0.04 means a 4 % chance it’s a fluke”

The p-value is calculated assuming there is no effect. It cannot tell you the chance that there is no effect: that also depends on how many of the ideas you test are true to begin with.

The honest version

Read p as “how surprising, if nothing were going on”. When few of your ideas are likely to be true, expect many significant results to be false alarms, and look for replication.

Lesson 2: The p-value is an area →

Lesson 03 · How every test works

Picking the tail after looking

The data come in, the new page looks better, and the analyst decides “we only cared about improvement anyway” and runs a one-sided test. It feels harmless.

The honest version

Fix the direction (and α) before the data arrive. If you didn’t, report the two-sided p. The checkout team must report 0.076.

Lesson 3: α and the critical region: one tail or two →

Lesson 04 · How every test works

“Not significant, so there is no effect”

A real effect, a small study, and p = 0.4. The report says the new page “has no effect”. But a study this small would miss a real effect most of the time.

The honest version

Say “we couldn’t tell” and give the interval for the effect. To show an effect is negligible, test for equivalence (station 74) or run a study powered to find what matters.

Lesson 4: Two ways to be wrong: errors and power →

Lesson 05 · How every test works

Significant vs not significant is not a difference

Study A (small) finds p = 0.2; study B (large) finds p = 0.01. The headline says the effect “works in B but not in A”. But what if both studies measured the very same effect?

The honest version

To claim two effects differ, compare the effects directly (their difference and its interval), not their p-values.

Lesson 5: Surprise vs size: effect sizes and intervals →

Lesson 06 · How every test works

The many-tests tax

A dashboard tracks 20 independent metrics. After a change that did nothing, one of them shows p = 0.03 and gets a celebratory email. How often would that happen by luck alone?

The honest version

With 20 independent tests of nothing, 1 − 0.95²⁰ ≈ 64 % of dashboards show at least one p < 0.05. Decide in advance which metric is primary. For the rest, adjust: Holm controls the chance of any false alarm; Benjamini–Hochberg controls the share of false alarms among your discoveries.

Lesson 6: Reading the Atlas: five engines and the many-tests tax →

Lesson 07 · One sample vs a value

A z cut-off with an estimated σ

Every sample here is on target. The analyst estimates σ from the sample but still uses the z cut-off of 1.96. With 6 bottles per sample, how often does that cry wolf? Run it, then drag the sample size up.

The honest version

With 6 bottles the z cut-off raises false alarms about 11 % of the time, not 5 %; the t cut-off for 5 df is 2.571. If σ comes from the data, use the t curve. Only a σ known from outside the sample earns the z-test.

Lesson 7: z-test for a mean, when σ is known →

Lesson 08 · One sample vs a value

One-sided t on a few skewed values

Waiting times are skewed (exponential), and the true mean really is the target. A one-sided t-test on 10 values should say “lower” 5 % of the time and “higher” 5 % of the time. Run it and see.

The honest version

On 10 exponential values, “lower” fires about 13 % of the time and “higher” about 1 %: the t curve is lopsided for skewed data, and the errors shrink only slowly with n. For the mean, a bootstrap-t or a model of the skew beats the t curve, though nothing is exact at n = 10. The sign test answers a median question.

Lesson 8: The one-sample t-test →

Lesson 09 · One sample vs a value

The bell-curve shortcut for a rare event

The true rate is the target. For every n from 10 to 200, the picture shows the exact chance (no simulation) that each test raises a false alarm at α = 0.05: red for the z shortcut, green for the exact test. Try each target rate.

The honest version

At a 5 % target the z shortcut’s false-alarm rate saw-tooths between about 2 % and 10 % (worst at n = 11), so its “5 %” is not a promise. The exact test never goes above 5 % (it is often below: 1.6 % at n = 30). With few yeses expected, use `binomtest`.

Lesson 9: One proportion: exact binomial vs z →

Lesson 10 · One sample vs a value

Clumpy counts treated as Poisson

Calls arrive in bursts: some hours busy, some quiet, so the hourly counts vary three times more than a Poisson count would. The average rate (6 an hour over 24 hours) really is the target. Run 2,000 days and test each with the Poisson test.

The honest version

With variance three times the mean, the Poisson test raises false alarms about 24 % of the time instead of 5 %. Check the hourly variance ÷ mean first (week 1’s is 0.82: fine). If it is well above 1, fit a negative-binomial (or quasi-Poisson) model, or t-test the hourly counts if the hours are independent.

Lesson 10: Counts per unit time: Poisson rate tests →

Lesson 11 · One sample vs a value

“It tests the spread, whatever the shape”

Both kinds of data here have exactly the target variance. One is normal; the other has heavier tails (t with 5 df), as a bad batch now and then produces. A fair test should cry wolf 5 % of the time on both. Run 2,000 samples of 30.

The honest version

On normal data the test keeps its 5 %; on heavy tails it raises false alarms about three times as often, and with 200 values it gets worse, not better. A test of a mean is rescued by large n; this one is not. Bootstrap the SD, or use a robust test of spread.

Lesson 11: A variance vs a target: the χ² variance test →

Lesson 12 · One sample vs a value

“Wilcoxon is a test of the median”

Skewed data whose **median really is the target**, so a median test should cry wolf 5 % of the time. A report uses Wilcoxon’s signed-rank test as its median test, beside the sign test. Run 1,500 skewed samples, then drag the sample size.

The honest version

The sign test stays at or below 5 %. Wilcoxon rejects more often, and far more often with 100 values: on skewed data it tests the pseudo-median (the median of all pairwise averages), not the median. For a median, use the sign test; keep Wilcoxon for near-symmetric data.

Lesson 12: A median vs a value: sign and Wilcoxon tests →

Lesson 13 · One sample vs a value

“The test flagged it, so delete it”

No sample here contains a mistake. Half are 20 normal readings; half are 20 readings that are naturally skewed, like reaction times or incomes. Grubbs is run on each. How often does it declare an outlier?

The honest version

Normal data: about 5 % flagged, as promised. Skewed data: about half, and more with bigger samples, because under a normal model a long tail looks like errors. Plot first, find a cause before removing anything, and report results with and without the point.

Lesson 13: Is that point an outlier? Grubbs and Dixon →

Lesson 14 · Two groups

“σ = 4 is on the spec sheet, so σ is known”

Two machines that fill identically, 30 bottles each. The analyst runs a two-sample z-test with σ = 4 from last year’s spec sheet, but the machines have worn and σ is now 6. Run 2,000 comparisons, then drag the true σ.

The honest version

With σ really 6, the z-test using 4 cries wolf about 19 % of the time; Welch stays near 5 %. Set the true σ to 4 and z behaves. A “known” σ is only as good as its date: check it against the data, and use Welch when in doubt.

Lesson 14: Two means, σ known: the two-sample z →

Lesson 15 · Two groups

Pooling a small, noisy group with a big, calm one

No real difference between the groups. The **small** group (10) has the **bigger** spread (3×), as a pilot group often does; the other group has 40. Student pools the two spreads into one. Count its false alarms.

The honest version

Use Welch: it keeps its 5 % promise whatever the spreads. Student is only safe with equal group sizes or truly equal spreads. Flip the ratio below 1 and Student turns too timid instead, missing real effects.

Lesson 15: Student's pooled t-test →

Lesson 16 · Two groups

Pre-testing the spreads to pick Student or Welch

A popular recipe: run Levene’s test; if p > 0.05, assume equal spreads and use Student, else Welch. Here there is no real difference, the spreads really differ (2×) and the groups are 10 and 40. Count the false alarms.

The honest version

Skip the pre-test and use Welch every time. Levene with 10 values often misses a real spread difference, and “p > 0.05” is not proof of equal spreads, so Student gets used exactly where it fails.

Lesson 16: Welch's t-test: the default →

Lesson 17 · Two groups

Ignoring the pairing

12 runners, timed before and after a training plan that **really works**. One analyst pairs each runner with themselves; the other compares the before and after groups with a two-sample t. Run 2,000 studies.

The honest version

Keep the pairs: test the differences with `ttest_rel` (or Wilcoxon on them if they are skewed and few). A two-sample test on paired data adds the runner-to-runner spread to the noise; when units differ a lot, as runners do, it misses most real effects.

Lesson 17: Paired t: a one-sample t on the differences →

Lesson 18 · Two groups

The F-test on heavy-tailed data

Two machines with **exactly the same spread**, but heavy-tailed fills (an occasional big over- or under-fill), 20 bottles each. Which test of “same spread” keeps its 5 % promise: the F-test or Levene?

The honest version

For spreads of real-world data use Levene’s test (SciPy’s default centres on the median: the Brown–Forsythe version) or Fligner–Killeen (`stats.fligner`), not Bartlett, which leans on normality as hard as F. More bottles don’t rescue the F-test; keep it for data you have good reason to believe are normal.

Lesson 18: Two variances: the F-test and Pitman–Morgan →

Lesson 19 · Two groups

Calling Mann–Whitney “the test of medians”

Two groups with **the same median** (0) but different shapes: one symmetric, one skewed. A report runs Mann–Whitney as “the test of medians”, 50 values a group. Run 1,500 comparisons, then raise the group size.

The honest version

Mann–Whitney rejects far more than 5 % here, and more often as the groups grow, because it tests whether one group tends to be larger (P(B > A) ≠ ½), and with different shapes that is false even at equal medians. Mood’s test keeps its 5 %. Report Mann–Whitney as “tends to be larger”.

Lesson 19: Mann–Whitney: comparing by ranks →

Lesson 20 · Two groups

Choosing Mood “to be safe” when Mann–Whitney fits

A real shift of 0.6 SD, 30 values a group, and the same shape in both. Both tests are robust, so which one finds the shift more often? Run 2,000 studies, then slide the size of the shift.

The honest version

Mann–Whitney found the 0.6 SD shift in about 60 % of studies, Mood in about 32 %: nearly half the power gone. Keeping only above / below the median throws the distances away. Use Mood when you need medians specifically, and plan a bigger sample to pay for it.

Lesson 20: Mood's median test →

Lesson 21 · Two groups

Counting sessions instead of users

The pages are identical. 100 users a page each visit 10 times, and some users are much keener than others. The dashboard runs a 2×2 test on 1,000 sessions a page as if they were independent. Run 1,500 A/B tests, then change the sessions per user.

The honest version

Counting sessions raised false alarms about four times as often as the promised 5 %; one sign-up rate per user (compared with Welch’s t) stayed near 5 %. A keen user’s sessions rise and fall together. Analyse the unit that was randomised: with 1 session per user, the two agree.

Lesson 21: Two proportions: z, χ² and Fisher →

Lesson 22 · Two groups

Shuffling pupils when classes were randomised

Six classes of 10: three get the new method, three the old, and the method does nothing. Pupils in a class share a teacher, so they resemble each other. One analysis treats the 60 pupils as independent; the other uses the 6 class means. Run 2,000 school trials.

The honest version

Pupils as independent gave about 25 % false alarms; a t-test on the 6 class means kept about 5 %. Classes were randomised, so the class is the unit. But 3 + 3 classes split only 20 ways, so a class-label shuffle can’t give p below 0.10 (two-sided): use the t on class means, or plan more classes.

Lesson 22: Permutation and bootstrap tests →

Lesson 23 · Many groups

A t-test for every pair of groups

No group really differs: four groups of 12. One analyst runs a t-test for each of the 6 pairs and reports any p < 0.05; the other runs a single one-way ANOVA. Count the false alarms, then add groups.

The honest version

Ask the overall question with one ANOVA. To ask which pairs differ, use a method that protects all pairs together (Tukey HSD), not one unadjusted t-test per pair: with 4 groups those find a “difference” about 1 time in 5, with 8 groups about half the time.

Lesson 23: One-way ANOVA: why not many t-tests →

Lesson 24 · Many groups

Classic ANOVA with a small, noisy group

Three clinics with the same mean wait: two big calm ones (30 patients each) and one small one (10) whose SD is 3× theirs. Classic ANOVA pools the spreads; Welch’s ANOVA doesn’t. Count the false alarms.

The honest version

Use Welch’s ANOVA whenever spreads may differ, and don’t let a Levene pre-test choose for you: “p > 0.05” is not proof of equal spreads. Flip the ratio below 1 (the small group calmer) and classic ANOVA turns timid instead, under 5 %, missing real effects.

Lesson 24: Welch's ANOVA, when spreads differ →

Lesson 25 · Many groups

Bartlett’s test on heavy-tailed data

Three groups with exactly the same spread, but heavy tails (t₅), 20 values each. A test of equal variances should cry wolf 5 % of the time. Count how often Bartlett and Levene do, then add data.

The honest version

Use Levene (SciPy’s default `center='median'`, the Brown–Forsythe version) unless the data are known to be near-normal. More data doesn’t rescue Bartlett: its false alarms grow with n (about 3 in 10 at 100 a group). Hartley and Cochran lean on normality too.

Lesson 25: Equal spreads? Levene, Bartlett, Hartley, Cochran →

Lesson 26 · Many groups

Judging pairs by whether their intervals overlap

A real gap of 0.6 SD, 30 values a group. A common shortcut calls two groups different only when their separate 95 % intervals don’t overlap. Run 2,000 studies: how often does that find the gap, and how often does a t-test?

The honest version

Judge a pair by an interval for the **difference** (or a test of it), not by two separate intervals. Overlapping intervals can hide a clearly significant gap: non-overlap is a much stricter test, well under 1 % for equal SEs. With many groups, Tukey gives a difference interval for every pair at once.

Lesson 26: Which pairs differ? Tukey HSD →

Lesson 27 · Many groups

Choosing the control after looking

Five groups, none really different. Both analysts compare four groups with a control, adjusted for 4 comparisons. One fixes the control first; the other picks the worst-looking group as “the control” after seeing the data.

The honest version

The control fixed first keeps false alarms near 5 %; the control picked as the worst-looking group runs well above it, because the lowest mean is the one luck pushed furthest down. Name the control in the plan, for a reason (the placebo, the standard method), and keep it.

Lesson 27: Everyone against a control: Dunnett →

Lesson 28 · Many groups

Building the contrast after seeing the means

Four equal groups. The analyst looks at the means, builds the contrast that splits them best (“the top two vs the bottom two”), then tests it as if it had been planned.

The honest version

Tested as if planned, the best-looking contrast is “significant” far more than 5 % of the time; against Scheffé’s cut-off it stays near 5 %. Write contrasts into the plan. One you found by looking has been fitted to the noise: report it against Scheffé, or test it on new data.

Lesson 28: Planned contrasts and Scheffé →

Lesson 29 · Many groups

Testing the winner as if it had been chosen first

Six branches, all equally good. The report finds the branch with the best mean and tests it against the other five pooled, as if it had been singled out in advance.

The honest version

With no real winner, “the top group is significantly better” comes out well above 5 % of the time, while one ANOVA stays near 5 %. Test with a procedure that allows for the pick (Tukey with the top group, Hsu’s MCB), or replicate the winner in a fresh study.

Lesson 29: Is the top group really the best? →

Lesson 30 · Many groups

Calling Kruskal–Wallis “the test of medians”

Three groups with **the same median** (0): one symmetric, one skewed right, one skewed left. The report reads Kruskal–Wallis as “the test of medians”. Run 1,500 comparisons, then change the number of values per group.

The honest version

With equal medians, Kruskal–Wallis says “different” far above 5 % of the time, and more often as groups grow, because the shapes alone make some group tend to be larger. Mood’s k-sample median test stays near 5 %. Report Kruskal–Wallis as “some group tends to be larger”.

Lesson 30: Kruskal–Wallis and Dunn's follow-up →

Lesson 31 · Many groups

Throwing away the blocks

Recipe R really is better. 12 tasters each score all four recipes, and tasters differ a lot (SD 1.5). One analyst ranks within each taster (Friedman); the other runs a one-way ANOVA on the four columns, ignoring who tasted what. Run 2,000 tastings.

The honest version

Friedman found the better recipe about 38 % of the time, the ANOVA ignoring tasters about 4 %: the taster spread sat in its noise. Keep the blocks (Friedman, or a two-way ANOVA with taster as a block). Set the taster SD to 0 and ignoring them costs nothing; ANOVA even wins (about 52 %), since ranks drop distances.

Lesson 31: Repeated measures by ranks: Friedman and Cochran's Q →

Lesson 32 · Many groups

Reading a W of 0.2 as agreement

Six judges rank eight entries **completely at random**. A W of 0.2 sounds like “some agreement”. How often does pure chance get there? Run 2,000 random panels, then change the number of judges.

The honest version

Six random judges gave W ≥ 0.2 about 31 % of the time; the χ² test of W rejected about 4 %, near the promised 5 %. W is never negative, and with no agreement it averages 1/m (1/6 ≈ 0.17 here). Always test it: χ² = m(n − 1)W on n − 1 df. With 3 judges, W ≥ 0.2 came by luck 81 % of the time.

Lesson 32: Do the judges agree? Kendall's W →

Lesson 33 · Designs with structure

“Significant in one subgroup, not the other”

A treatment works equally (d = 0.5) for men and for women, 30 per arm in each subgroup. The report finds “significant for women, not for men” and calls it an interaction. Run 2,000 trials with the same effect in both subgroups.

The honest version

With identical effects, “significant in one, not the other” happened in about 51 % of trials; the real interaction test fired about 5 %. Significant vs not significant is not itself a significant difference. Test whether the two effects differ (the interaction term) and give both effects with intervals.

Lesson 33: Two-way ANOVA: main effects and interaction →

Lesson 34 · Designs with structure

Trusting the sequential (Type I) table

Factor A does nothing; factor B has a big effect. The cells are unbalanced (20, 5 / 5, 20), so A and B overlap. The default sequential (Type I) table tests A first, ignoring B. Run 2,000 unbalanced studies, then slide the small cells.

The honest version

Tested first, the useless A was “significant” in about 54 % of studies; adjusted for B (Type II), about 5 %. With small cells of 2 it reached 75 %; with all cells at 20, both sat near 5 %. `anova_lm` defaults to `typ=1`: pass `typ=2` (or 3 with sum contrasts) on purpose.

Lesson 34: Unequal cells: Type I, II and III sums of squares →

Lesson 35 · Designs with structure

Calling multiplying effects an interaction

Varieties and fields **multiply** each other’s effects (a 30 % better variety gains 30 % in every field), one plot per cell. Tukey’s test runs 2,000 times on the raw yields and on log yields. Which scale finds “non-additivity”?

The honest version

Raw yields flag non-additivity about 94 % of the time; log yields about 4 %, close to the 5 % of a truly additive table. A significant Tukey test is often a message about the scale, not a mysterious interaction: try logs, then report main effects on the scale where they add.

Lesson 35: Tukey's test for non-additivity →

Lesson 36 · Designs with structure

Testing schools against pupils

Four schools, three classes each, eight pupils per class; schools don’t really differ, but classes do (class SD 3). Run 2,000 school studies: test the schools against pupil-level noise, or against class-level noise?

The honest version

Against pupils: about 30 % false alarms; against classes: about 5 %. The schools are compared through 12 classes, not 96 independent pupils, so their test has 8 error df, not 84. Set the class SD to 0 and the two agree; the bigger the class gaps, the worse the wrong test gets.

Lesson 36: Nested designs →

Lesson 37 · Designs with structure

Thirty parts from six machines are not thirty independent values

A 95 % interval for the factory’s mean part length, from 6 machines × 5 parts, machines differing with SD 0.6 mm. Treat the 30 parts as independent, or work from the 6 machine means? Run 2,000 factory studies; the bars show how often each interval covers the truth.

The honest version

Treating 30 parts as independent, the “95 %” interval covered the truth only about 82 % of the time; from the 6 machine means, about 95 %. When levels are a random sample, their variation belongs in the uncertainty. Set the machine SD to 0 and the two agree.

Lesson 37: Random effects and variance components →

Lesson 38 · Designs with structure

One t-test per outcome, and success if either wins

A drug affects neither systolic nor diastolic pressure; the two correlate 0.7, 20 patients a group. The report tests each outcome with its own t-test and claims success if either is significant. Run 2,000 trials with no effect.

The honest version

“Either outcome significant” gave about 9 % false alarms: two lottery tickets, partly correlated. Hotelling’s T² on both kept about 5 %. Name a primary outcome in advance, or test the outcomes jointly; the less correlated they are, the worse the either-wins rule gets.

Lesson 38: Many outcomes at once: Hotelling's T² →

Lesson 39 · Counts and tables

Estimating λ from the data, then keeping k − 1 df

The counts really are Poisson (λ = 2, 60 a sample). The analyst estimates λ from the same data, bins the counts 0, 1, 2, 3, 4+ and runs a χ² goodness-of-fit test, still on k − 1 = 4 df. Run 3,000 samples.

The honest version

On 4 df: about 2.3 % false alarms; on 3 df (k − 2): about 5.2 %. The fitted λ pulls the expected counts towards the data, so χ² comes out smaller than the k − 1 curve expects: the test is timid, and it also misses real misfits. Every parameter estimated costs one df (`ddof=1`).

Lesson 39: Goodness of fit for categories →

Lesson 40 · Counts and tables

Typing percentages into the χ² test

Two groups of 40 with the same three-way mix (50 / 30 / 20 %), so nothing is linked. The report has only percentages, and the analyst types them into the χ² test as if they were counts out of 100. Run 2,000 surveys.

The honest version

On percentages: about 31.8 % false alarms; on the real counts: about 4.2 %. χ² grows in proportion to the counts, so turning 40 people into 100 multiplies it by 2.5. It works the other way too: our districts of 200, typed in as percentages, halve χ² to 9.38 (p = 0.153). Always test counts.

Lesson 40: Independence in an r×c table →

Lesson 41 · Counts and tables

Reading Fisher’s 5 % as exactly 5 %

Two groups of 15, the same 30 % chance of “yes”, so there is no real difference. Fisher’s exact test promises at most 5 % false alarms. Run 4,000 tiny trials: how close does it come?

The honest version

Fisher: about 1.9 % false alarms; the mid-p version: about 2.7 %. With lumpy counts the exact p moves in steps, so Fisher stays well under 5 % and loses power. Mid-p (half the observed table’s chance taken off) is sharper but no longer guaranteed; Barnard’s and Boschloo’s tests are other ways back.

Lesson 41: Small counts: Fisher's exact test →

Lesson 42 · Counts and tables

A χ² for every pair of groups

Four regions of 50, the same three-way mix in each. One analyst runs a 2 × 3 χ² for every pair of regions (six tests) and reports any p under 0.05; the other runs one χ² on the whole 4 × 3 table. Run 2,000 surveys.

The honest version

Pairwise: about 21.5 % of surveys flag a “difference” that isn’t there; one table: about 5.5 %. Six looks at the same data buy six chances of a fluke. Test the whole table once, read its residuals to see where it differs, and adjust any pairwise p-values (Bonferroni or Holm).

Lesson 42: Many groups, one mix? Homogeneity →

Lesson 43 · Counts and tables

Trusting G with tiny expected counts

A fair die rolled only 12 times: 2 expected per face, far under the usual 5. G and Pearson’s χ² both read their p-values off the χ² curve with 5 df. Roll 4,000 such samples: which test keeps its 5 % promise?

The honest version

G: about 8.8 % false alarms; Pearson: about 3.0 %. With expected counts this small neither follows the χ² curve: G drifts high, Pearson errs on the cautious side. Roll more, merge sparse cells, or get an exact (multinomial or Monte-Carlo) p-value; switching formula fixes nothing.

Lesson 43: The G-test: likelihood-ratio χ² →

Lesson 44 · Counts and tables

Treating before and after as two groups

60 people answer twice; support really rises from 40 % to 55 %, and most keep their answer. One analyst counts the switchers (McNemar); the other treats before and after as two independent groups (a 2 × 2 χ²). Run 2,000 surveys: who finds the rise?

The honest version

McNemar found the real rise about 67 % of the time; the two-group χ² only about 34 %. Most answers didn’t move, and counting only the switchers removes that person-to-person noise. The same people twice are one paired sample, not two independent ones.

Lesson 44: Before and after, yes or no: McNemar →

Lesson 45 · Counts and tables

Ignoring the order: a plain χ² on ordered groups

Response really rises with dose: 10 % → 26 % over five doses, 40 patients each. The plain χ² ignores the order of the doses; the trend test uses it. Run 2,000 dose studies: how often does each find the real rise?

The honest version

The trend test found the rise about 56 % of the time; the plain χ² about 34 %. χ² spreads its 4 df over every pattern, most of which nobody expected. Set the strength to 0: both drop to about 5 %, so the extra power costs no false alarms, as long as you chose the trend test before seeing the data.

Lesson 45: Ordered groups: the Cochran–Armitage trend test →

Lesson 46 · Counts and tables

Pooling the strata: a gap made by who applied where

Departments admit men and women at exactly the same rate (70 % in X, 25 % in Y), but men apply mostly to X (300 of 400) and women mostly to Y (340 of 400). Run 2,000 admission rounds: pool the departments, or compare within them?

The honest version

Pooled χ²: a “gender gap” in about 100 % of rounds that have none. Mantel–Haenszel: about 5 %, as promised. The department drives both who applies and who gets in, so pooling turns a difference in applications into a difference in admissions. When a third variable drives group and outcome, stratify on it.

Lesson 46: Strata: Mantel–Haenszel and Simpson's paradox →

Lesson 47 · Counts and tables

Treating dependent days as independent

Two seasons of 60 days with the same chance of rain, but rain persists (rain follows rain 60 % of the time). A two-proportion χ² compares the seasons’ rainy-day counts as if the 120 days were independent. Run 2,000 pairs of seasons: is it fair?

The honest version

Days as independent: about 20 % false alarms. Six ten-day block shares per season, compared with Welch: about 5 %. Rainy spells make neighbouring days repeat each other, so 60 days hold far fewer independent looks. Test for dependence first; set the persistence to 20 % and the naive test behaves.

Lesson 47: Does what follows depend on what came before? →

Lesson 48 · Relationships

Reading r ≈ 0 as “no relationship”

Every data set has a strong link: y is x² plus noise, a U shape, 30 points each. The analyst computes only r and tests it. Run 2,000 curved data sets: how often does the r test find the link, and how often does a curve (x and x²)?

The honest version

The r test finds the link in only about 28.3 % of data sets; a model that allows the curve finds it in about 99.2 %. r measures straight lines: r ≈ 0 means “no straight line”, not “no relationship”. Plot the scatter first, and if it bends, model the bend.

Lesson 48: Is r zero? Testing a correlation →

Lesson 49 · Relationships

“Significant in one, not the other” read as a difference

Both cities have exactly the same correlation (ρ = 0.3), 40 days each. The report tests each city on its own and calls them different when one is significant and the other isn’t. Run 2,000 pairs of cities.

The honest version

One significant and one not in about 50.1 % of pairs, though the cities are identical; Fisher’s z on the difference: about 4.5 %. Two p’s on either side of 0.05 say nothing about the gap. Our cities: A p = 0.0001, B p = 0.107, but the difference has p = 0.163.

Lesson 49: Comparing correlations: Fisher's z →

Lesson 50 · Relationships

One wild point makes a Pearson correlation

19 pairs of unrelated numbers, plus one wild point at (3.5, 3.5), 3.5 SDs out on both. No real relationship at all. Run 2,000 data sets: how often does Pearson’s r test, and how often Spearman’s, call the link significant?

The honest version

Pearson: “significant” in about 42.0 % of data sets, all from one point. Spearman: about 7.8 %, since the wild point is just rank 20 on both. The wines show the reverse: the trophy bottle hides a link (r 0.351; 0.685 without it). Look at the scatter.

Lesson 50: Spearman and Kendall: correlation by ranks →

Lesson 51 · Relationships

Regression to the mean: the weakest always “improve”

100 people take a test twice; nothing happens in between, and the two scores share only each person’s true ability. A programme enrols the 20 lowest first scores and celebrates their second score. Run 2,000 programmes.

The honest version

The weakest 20 “improved” significantly (paired t) in about 89.5 % of runs; against a control group chosen the same way, about 6.2 %. Part of a low first score is bad luck, so retest slopes fall below 1 whenever r < 1. Judge a programme against an equally selected control.

Lesson 51: The slope test is the r test →

Lesson 52 · Relationships

A high R², so the line must be right

The response really bends (diminishing returns), 6 doses × 4 plants. The analyst fits a straight line and reports a high R² as proof of a good fit. Run 2,000 curved dose studies.

The honest version

R² was above 0.75 in about 82.0 % of studies, while the lack-of-fit F caught the bend in 100.0 % (all but 1 of 2,000). R² says how much a line explains, not whether a line is the right shape. Plot the means, test lack of fit, and if it fails fit the curve.

Lesson 52: Is it really a line? Lack-of-fit →

Lesson 53 · Relationships

Dropping predictors whose t is “not significant”

Two predictors both really matter, but they nearly copy each other (correlation 0.9); 60 cases. The analyst reads each coefficient’s t and drops the “non-significant” ones. Run 2,000 regressions.

The honest version

The pair mattered (F) in about 74 % of regressions; in about 54 % of all regressions neither t was significant even though F was. Each t asks about one predictor given the other. Test overlapping predictors together (a partial F) and check how correlated they are.

Lesson 53: Many predictors: t per coefficient, F for the lot →

Lesson 54 · Relationships

Trusting the slope test on monthly data

Advertising spend drifts upward over 48 months and has **no effect** on sales, but each month’s sales error carries into the next (ρ = 0.75). Run 2,000 four-year series: how often does the ordinary slope test call advertising significant?

The honest version

Ordinary test: about 34.0 % false alarms; after one Cochrane–Orcutt step: about 7.8 %, far closer to 5 %. Carry-over and a trending x make 48 months worth far fewer. Check DW, then model the errors (Cochrane–Orcutt, GLS), use HAC standard errors, or difference the series. At ρ = 0 the ordinary test behaves.

Lesson 54: Autocorrelated errors: Durbin–Watson →

Lesson 55 · Relationships

Coding categories as numbers

Three groups of 20: the middle group really scores higher (0.8 SD), the outer two are equal. The file codes the groups 1, 2, 3, and the analyst regresses on that column as a number. Run 2,000 studies: how often is the difference found?

The honest version

As a number: found about 3.8 % of the time, since a straight line through 1, 2, 3 can’t go up and then down. As dummies (the one-way ANOVA): about 72.2 %. Categories enter a linear model as 0/1 columns, not as their codes (unless you mean a straight-line trend); in statsmodels, wrap the column in `C()`.

Lesson 55: Everything is a linear model →

Lesson 56 · Relationships

Trusting the Wald test with 20 tries

The true rate really is 20 %. Take 20 tries and test p = 0.2 three ways, all at 5 %. Repeat 4,000 times: how often does each one cry wolf?

The honest version

Wald: about 8.1 % false alarms; score and likelihood ratio: about 4.0 % each. Wald judges the SE at p̂, which shrinks when p̂ lands near 0, so small gaps look huge. With few tries or rates near a boundary, prefer score or LR (or an exact test); with big samples all three agree.

Lesson 56: Wald, score and likelihood ratio →

Lesson 57 · Shape and fit

A big sample “fails” normality, so the t-test is dropped

The data are very slightly skewed, harmless for a t-test on means. Run 600 pairs of samples: Shapiro–Wilk on 50 values and on 1,000. How often does it reject normality?

The honest version

n = 50: about 12.2 % rejections; n = 1,000: about 93.2 %. The departure is the same, only the test got sharper, and it rejects exactly when the t-test needs normality least (big n). Read a rejection with the Q–Q plot: is the bend big enough to matter for what you plan to do?

Lesson 57: Is it normal? Q–Q plots and Shapiro–Wilk →

Lesson 58 · Shape and fit

Fitting the curve, then reading KS’s own p

The data really are normal, 30 values. The analyst estimates the mean and SD from them, runs KS against that fitted normal and reads KS’s own p. Run 2,000 normal samples: how often does it reject at 5 %?

The honest version

KS’s own p: about 0.0 % rejections, where 5 % was promised; Lilliefors’ cut-off: about 5.7 %. Fitting pulls the curve onto the data, so D runs small and KS’s table almost never fires, which also means it misses real non-normality. Use Lilliefors (or simulate, lesson 62), or Shapiro–Wilk.

Lesson 58: Kolmogorov–Smirnov and Lilliefors →

Lesson 59 · Shape and fit

Trusting a KS pass when the tails are the problem

50 values from a heavy-tailed curve (t with 3 df): not normal, mostly in the tails. Run 1,000 samples and test normality at 5 % with Lilliefors (KS) and with Anderson–Darling. Which test notices?

The honest version

Lilliefors noticed about 48.5 % of the time, Anderson–Darling about 63.2 %. KS takes the one biggest gap, usually mid-curve where the curves are steep; AD weights each gap by how surprising it is in its place, so tail gaps count. A KS pass says little about the tails.

Lesson 59: Anderson–Darling: watching the tails →

Lesson 60 · Shape and fit

Using KS to look for a shift

Group B is really shifted up by 0.6 SD, with the same shape and spread; 30 per group. The question is “is one typically bigger?”. Run 2,000 studies: how often does each test find the shift?

The honest version

Mann–Whitney found the shift about 60.4 % of the time, KS about 46.2 %. KS spreads its attention over every possible difference, so for a pure shift a location test is sharper. Match the test to the question: KS for “any difference”, Mann–Whitney or Welch for “which is bigger”.

Lesson 60: Two distributions: two-sample KS →

Lesson 61 · Shape and fit

Six pairwise KS tests instead of one

Four samples of 30 from one and the same distribution. One analyst runs a two-sample KS test on every pair (6 tests); the other runs one K-sample Anderson–Darling. Run 1,000 studies: how often does each raise a false alarm?

The honest version

Pairwise: about 16.1 % of studies flagged at least one pair; one K-sample test: about 5.9 %. Six looks, six chances. Test all groups at once first; if that rejects, follow up pair by pair with a correction (Holm, Bonferroni).

Lesson 61: Several samples, one distribution? →

Lesson 62 · Shape and fit

Reading a pass as proof the model is right

The data come from a clearly skewed (lognormal) curve. The analyst runs Shapiro–Wilk and, if p ≥ 0.05, declares the normal model fine. Run 2,000 samples of 15 and of 100: how often does the wrong model pass?

The honest version

With 15 values the wrong normal model passed about 61.9 % of the time; with 100, about 0.2 %. A large p means “not enough data to object”, not “the model is right”. On the bus gaps gamma and normal both pass, yet the normal allows negative waits: check the model makes sense too.

Lesson 62: Choosing a model: testing the fit honestly →

Lesson 63 · Randomness and order

Asking only “too few runs?”

The sequences really are not random: each value tends to flip side (lag-1 correlation −0.5), a see-saw. 40 values each. The analyst only asks whether there are too few runs (clumping). Run 2,000 see-saw sequences.

The honest version

The one-sided test found the pattern about 0.0 % of the time, since a see-saw makes too **many** runs; the two-sided test about 48.0 %. Too few runs means spells, too many means alternation: both are non-random. Test both ways unless the question fixed one direction before the data.

Lesson 63: Runs: is this sequence random? →

Lesson 64 · Randomness and order

Spells read as a trend

40 years with **no trend**, but each year carries over into the next (lag-1 correlation 0.6), so wet and dry spells last. Mann–Kendall assumes independent years. Run 2,000 trendless series; slide the carry-over φ.

The honest version

Raw Mann–Kendall found a “trend” in about 31.8 % of series; after prewhitening (subtract r̂ × last year, then test) about 5.5 %. At φ = 0 both stay near 5 %. Check the carry-over first; prewhiten, or use a block bootstrap that resamples whole stretches of years.

Lesson 64: Trend: Cox–Stuart and Mann–Kendall →

Lesson 65 · Randomness and order

Any bar outside the band means correlated

200 values of pure noise. The analyst draws the autocorrelation plot and calls the series correlated if **any** of the first 20 bars pokes outside the ±1.96/√n band. Run 2,000 series of pure noise.

The honest version

Some bar fell outside the band in about 58.4 % of noise series; one Ljung–Box test on 20 lags about 5.8 %. Twenty bars are twenty looks, and the band is for one lag chosen in advance. Choose the lags first and test them together.

Lesson 65: Serial correlation: von Neumann and Ljung–Box →

Lesson 66 · Randomness and order

Using a runs test to look for a shift

Group 2 is really shifted up by 0.6 SD, same shape; 30 a group. Both tests are rank-based, and the analyst picks the runs test because it “notices any difference”. Run 2,000 studies: which finds the shift?

The honest version

Mann–Whitney found the shift about 60.4 % of the time, Wald–Wolfowitz about 18.6 %. The runs test only counts colour changes: a shift leaves the middle of the pooled line well mixed. Broad tests pay for breadth; when the question is a shift, use a shift test.

Lesson 66: Two samples interleaved: Wald–Wolfowitz →

Lesson 67 · Randomness and order

Calling it B because the evidence favours B

Species B is rare (5 % of birds). Four wing lengths per bird, A ~ N(62, 3), B ~ N(66, 3). The analyst calls a bird B whenever the likelihood ratio favours B. Classify 2,000 birds: how many “B” calls are wrong?

The honest version

Calling B whenever LR > 1 was wrong for about 62.3 % of the “B” calls: most birds are A, and some A birds look like B. Calling B only when the posterior passes ½ (LR above 19 when B is 5 %): about 11.1 % wrong. The likelihood ratio is the evidence, not the answer.

Lesson 67: Which population made this series? →

Lesson 68 · Randomness and order

Finding the streak first, then testing it

20 players, 50 shots each, every shot a coin flip (50 %). A streak of 9 hits or more happens to about 4 % of players by chance. The reporter finds the player with the longest streak and calls it a hot hand. Run 2,000 seasons.

The honest version

The best of 20 had a “significant” streak in about 56.8 % of seasons (1 − 0.96²⁰ ≈ 0.56); one player named in advance, about 3.9 %. Choosing the streak after looking is many tests in disguise. Name the player and the statistic first, or test the season’s best against the best of 20 chance players.

Lesson 68: Streaks and the hot hand →

Lesson 69 · Deciding between hypotheses

Choosing α after seeing p

No real difference, 20 a group, a two-sample t-test. The analyst planned α = 0.05, but whenever p lands between 0.05 and 0.10 writes “significant at the 10 % level”. Repeat 2,000 times: how often is there a false alarm?

The honest version

Moving the goalposts: about 11.6 % false alarms (10 % in theory), twice the plan. Fixed α: about 5.7 % (5 %). In the Neyman–Pearson picture α belongs to the rule and is set before the data; a rule that slides with p is a 10 % rule. Report the exact p if you like, but don’t relabel α.

Lesson 69: Simple vs simple: the Neyman–Pearson picture →

Lesson 70 · Deciding between hypotheses

Reading a boundary LR on χ² with 1 df

A drug can only help or do nothing, so its fitted effect is never allowed below 0: half the time it sticks at 0. “No effect” is tested by LR on the usual χ² with 1 df, at 5 %. Run 4,000 studies of a useless drug: how often is there a false alarm?

The honest version

On χ²₁: about 2.2 % false alarms (2.5 % in theory), not 5 %, because half the studies give LR = 0. The right yardstick is an even mix of 0 and χ²₁ (cut-off 2.71, not 3.84): about 4.6 % (5 %). The χ² rule needs the null value inside the parameter range; on its edge the test is too timid.

Lesson 70: Likelihood ratio tests →

Lesson 71 · Deciding between hypotheses

A one-sided test for a change that went the other way

The new process is really **worse**, by 0.5 SD; 30 units per trial. The team ran a one-sided test for “better” because they “only cared about improvement”. Repeat 2,000 times: how often is the change noticed?

The honest version

One-sided: about 0.0 %, it never noticed the harm. Two-sided: about 76.8 %. A one-sided test is most powerful in its own direction only. Use it when the other direction would truly change nothing, and say so before the data; otherwise test two-sided.

Lesson 71: Uniformly most powerful tests →

Lesson 72 · Deciding between hypotheses

Reporting the rate seen at the stop

An SPRT of 10 % vs 15 % sign-ups, while the truth is 12 %. Whenever it declares 15 %, the team reports the sign-up rate it saw at the moment it stopped. Run 2,000 sequential tests: how often is that rate 15 % or more?

The honest version

It declared 15 % in about 28.9 % of runs, and in about 59.9 % of those the reported rate was 15 % or more, though the truth is 12 %. The test stops for 15 % right after a lucky run of sign-ups: the decision keeps its error rates, the estimate at the stop is biased upwards. Report the decision, not that rate.

Lesson 72: Sequential testing: the SPRT →

Lesson 73 · Deciding between hypotheses

Stopping at the first p < 0.05

Both pages are identical (10 % sign-ups), 200 users per page in all. The analyst runs a two-proportion test after every batch, 20 looks, and stops as soon as p < 0.05. Run 2,000 A/A tests, then try other numbers of looks.

The honest version

With 20 looks, about 22.3 % of A/A tests “won”; one look at the end, about 4.9 %. Peeking turns one test into many correlated ones. Decide the looks in advance and use a cut-off built for them (Pocock, O’Brien–Fleming), or a sequential method; otherwise look once.

Lesson 73: Peeking without a plan →

Lesson 74 · Deciding between hypotheses

“Not significant, so equivalent”

The generic really differs by 0.6 SD, well outside the agreed margin of ±0.3 SD. 20 tablets each. One analyst calls the products equal whenever the t-test is not significant. Run 2,000 bioequivalence studies: how often is a real difference waved through?

The honest version

“Not significant, so equal” declared equivalence in about 53.1 % of studies; TOST in about 0.0 %. With 20 tablets each the 90 % interval is about ±0.53 SD wide, wider than the ±0.3 margin, so TOST almost never passes, even for identical products: the honest verdict is “not enough data”, never “equal”.

Lesson 74: Equivalence (TOST) and Bayes factors →

Lesson 75 · Circular data

R̄ near 0, so the birds have no direction

Birds fly along a coastline: half towards 30°, half towards 210°, tightly (κ = 3). 30 birds. A strong pattern, but in two opposite directions. Run 2,000 flocks: how often does Rayleigh find it?

The honest version

Rayleigh found a preferred direction about 0.0 % of the time: the two clusters cancel and R̄ ≈ 0. Doubling every angle (30° and 210° both become 60°) and testing again found it about 94.0 % of the time. R̄ near 0 can mean no direction or two opposite ones: plot first, and for an axis double the angles.

Lesson 75: Angles break the mean: the Rayleigh test →

Lesson 76 · Circular data

Cut the circle where KS looks worst

40 bearings with no preferred direction at all. KS needs the circle cut open somewhere; the analyst tries every cut and keeps the one with the biggest gap. Run 1,000 sets of random bearings: how often is “not uniform” declared?

The honest version

KS at the most damning cut gave a false alarm about 28.1 % of the time; Kuiper, the same from every cut, about 5.1 %. Choosing the cut after looking is a forking path. On a circle there is no first angle: use a test that does not need one.

Lesson 76: Fit for angles: Kuiper and Watson →

Lesson 77 · Circular data

A t-test on the degrees

Two release sites, mean bearings 350° and 20°, really 30° apart (κ = 2.5, 20 birds each). The analyst runs a t-test on the bearings as numbers. Run 2,000 pairs of sites: how often does each test find the difference?

The honest version

t on the degrees found it about 40.2 % of the time, often for the wrong reason (350° looks “bigger” than 20°); Watson–Williams about 61.5 %. Angles wrap: their tests must too. On the homing data the t gives p = 0.134 against WW’s 0.0034.

Lesson 77: Two circular samples →

Lesson 78 · Circular data

Pooling κ when the spreads differ

Three sites, one true mean direction (0°). One site is large and tight (30 birds, κ = 8), two are small and scattered (8 birds each, κ = 1). Watson–Williams assumes one shared κ. Run 2,000 three-site studies: how often a false alarm?

The honest version

With very unequal spreads, about 30.9 % false alarms; with equal spreads (κ = 2 everywhere), about 5.1 %. The circular ANOVA inherits ANOVA’s equal-spread assumption: check the R̄s first, and when they differ a lot use a test that doesn’t pool them.

Lesson 78: Several circular groups: Watson–Williams →

Lesson 79 · Case files

Levene first, then Student or Welch

The recipe the client’s analyst used: run Levene; if p > 0.05 pool with Student, else Welch. Here there is no real difference, the spreads really differ (2×) and the groups are 10 and 40. Run 3,000 experiments and count the false alarms.

The honest version

Pre-test-then-pick: about 9.0 % false alarms; Welch alone about 5.2 %. On the baskets Levene gives p = 0.0563, so the recipe picks Student: p = 0.0755 against Welch’s 0.0757, the same verdict only because the pages have 80 each. Use Welch every time.

Lesson 79: Case file: did the redesign change basket sizes? →

Lesson 80 · Case files

Classic ANOVA when the small clinic is the noisy one

Three clinics with the same mean wait: two big calm ones (30 patients each) and one small one (10) with 3× their SD. Classic ANOVA pools the spreads; Welch’s ANOVA doesn’t. Run 2,000 no-difference experiments and count the false alarms.

The honest version

Classic ANOVA: about 24.0 % false alarms; Welch’s ANOVA about 5.0 %. The clinics data sit in that corner (C: 15 patients, SD 25.57), so classic’s p = 0.025 can’t be trusted, and Tukey’s and Dunnett’s “C differs” lean on the same pooled spread.

Lesson 80: Case file: four clinics and a waiting list →

Lesson 81 · Case files

Pooling the strata: a gap made by who is in each group

The same mistake in its classic form: departments admit men and women at exactly the same rate (70 % in X, 25 % in Y), but men apply mostly to X and women mostly to Y. Run 2,000 admission rounds: pool the departments, or compare within them?

The honest version

Pooled χ²: a gap in about 100 % of rounds that have none; Mantel–Haenszel about 4.9 %. The survey is the same story: pooled, urban people recommend less (p = 6.1e-5); within age bands the odds ratios are 0.95 and 0.89, MH p = 0.676. The gap is age, not region.

Lesson 81: Case file: survey tables →

Lesson 82 · Case files

Raw Mann–Kendall on days that echo each other

The mistake in its plain form: 40 years with no trend, but each year carries over into the next (lag-1 correlation 0.6), so spells last. Run 2,000 trendless series: Mann–Kendall on the raw values, or after prewhitening?

The honest version

Raw: a “trend” in about 31.8 % of trendless series; prewhitened about 5.5 %; at φ = 0 both stay near 5 %. The masts’ differences echo even more (0.711): raw Mann–Kendall p = 3.7e-9, prewhitened τ = 0.224, p = 0.0127. The drift is real, but far less certain than the raw test says.

Lesson 82: Case file: wind directions and sensor drift →