Chi-Square & ANOVA
Every test you have met so far has compared one mean, or two. Real questions are rarely that tidy. You may want to know whether a whole set of groups falls out the way somebody claimed. You may want to know whether two categorical variables travel together, or whether three, four or five groups have the same average. This chapter gives you three tools for just those jobs: the chi-square goodness-of-fit test, the chi-square test of independence and one-way analysis of variance. Then it tells you the truth that most courses rush past. It covers what these tests need before you may trust them, and what to do the moment one of them comes back significant. The math is mostly subtraction, squaring and division. If you can do that, you can do this.
By the end of this chapter you can
- Work out expected counts and the chi-square statistic, χ2 = Σ(O − E)2/E, by hand.
- Run a goodness-of-fit test to decide whether data match a claimed distribution, using df = k − 1.
- Run a test of independence on a two-way table, using df = (r − 1)(c − 1), and describe the link you find.
- Split variability into between-group and within-group sums of squares, and build a complete ANOVA table.
- Explain why the F statistic is a ratio of two variance estimates, and why many t tests are a bad stand in for one F test.
- State and check the assumptions behind chi-square and ANOVA, and name the right other test when one fails.
- Carry out and read a post-hoc comparison (Tukey's HSD or a Bonferroni correction) after a significant F.
- Read p-values, confidence intervals and effect sizes exactly, without the usual overstatements.
Section 1Chi-square goodness of fit

The question this test answers
You have one categorical variable with k groups (categories), and somebody has made a claim about how the population splits across them. A maker says its bags of candy are 30% red, 30% brown and 40% yellow. A textbook says a fair die lands on each face one sixth of the time. A subscription service says its customers split 25/40/35 across three tiers. You collect a sample and count. The counts never match the claim exactly, because sampling sees to that. The goodness-of-fit test asks a single question: is the mismatch bigger than sampling noise can easily explain?
The hypotheses are stated in words as much as symbols:
- H0: the population proportions are exactly as claimed (say, p1 = 0.25, p2 = 0.40 and p3 = 0.35).
- Ha: at least one proportion differs from its claimed value.
Notice that the alternative is vague on purpose. It says something is off, but it does not say which group or in which direction. That vagueness is the price of testing all the groups at once. It comes back to bite us in Section 5, in the ANOVA setting.
Observed, expected, and the statistic
The observed counts O are what you actually tallied. The expected counts E are what the null hypothesis predicts on average for a sample of your size: Ei = n × pi. Expected counts are often not whole numbers. 200 × 0.35 = 70 is tidy, but 137 × 0.35 = 47.95 is not, and you must not round it. Rounding expected counts is one of the most common ways a chi-square gets quietly wrecked by hand.
The statistic adds up one share per group:
χ2 = Σ (O − E)2 / E
Read that formula slowly, because it is the whole chapter in small. The top part, (O − E)2, measures how far a group strayed from the prediction. It is squared so that going over and going under both count as evidence. Dividing by E puts that miss on a fair scale. Being 10 counts off when you expected 20 is a scandal; being 10 counts off when you expected 2,000 is nothing. Every term is a square divided by a positive number, so χ2 is never negative, and a value near zero means the data hug the claim. Big values, and only big values, are evidence against H0. That is why the chi-square test is always right-tailed.
The degrees of freedom are df = k − 1, one less than the number of groups. Here is the gut sense. Once you know the total and all but one group count, the last one is forced, so only k − 1 counts are free to vary. (Say you had to estimate m parameters from the data to build the expected counts, such as when fitting a Poisson model. Then you subtract those too: df = k − 1 − m.)
A worked example, start to finish
A meal plan service claims its members split across three tiers as Bronze 25%, Silver 40% and Gold 35%. A random sample of n = 200 members gives Bronze 40, Silver 95 and Gold 65. Test at α = 0.05.
Step 0: check the conditions first. The four rules are laid out in Section 4, and they are met here. The data are raw counts, not percentages. The sample is random. Each member is counted once and lands in just one tier, so the observations are independent. And every expected count worked out in Step 1 is at least 5 (the smallest is 50). Do this before you look at any p-value, not after.
Step 1: expected counts. EBronze = 200(0.25) = 50, ESilver = 200(0.40) = 80 and EGold = 200(0.35) = 70. They add up to 200, which is a useful math check, since expected counts always total n.
| Category | Observed O | Claimed p | Expected E = np | O − E | (O − E)2/E |
|---|---|---|---|---|---|
| Bronze | 40 | 0.25 | 50 | −10 | 100/50 = 2.0000 |
| Silver | 95 | 0.40 | 80 | +15 | 225/80 = 2.8125 |
| Gold | 65 | 0.35 | 70 | −5 | 25/70 = 0.3571 |
| Total | 200 | 1.00 | 200 | 0 | χ2 = 5.170 |
Step 2: the statistic. 2.0000 + 2.8125 + 0.3571 = χ2 = 5.17.
Step 3: degrees of freedom and critical value. There are k = 3 groups, so df = 3 − 1 = 2. From the table below, the critical value at α = 0.05 with df = 2 is 5.991.
| Degrees of freedom | α = 0.10 | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 |
| 2 | 4.605 | 5.991 | 9.210 |
| 3 | 6.251 | 7.815 | 11.345 |
| 4 | 7.779 | 9.488 | 13.277 |
| 5 | 9.236 | 11.070 | 15.086 |
| 6 | 10.645 | 12.592 | 16.812 |
Step 4: decide. 5.17 is less than 5.991, so we fail to reject H0. The p-value is about 0.075, which is larger than 0.05 and confirms the same decision.
Step 5: say what that means, with care. "At the 5% level, these data do not give enough evidence that the true tier proportions differ from the claimed 25/40/35 split." That sentence is doing something exact. It does not say the claim is true. We fail to reject H0; we never accept it. Those are different verdicts, just as "not guilty" is not "innocent." A sample of 200 simply may not have had the power to detect a mismatch of the size that is really there. Absence of evidence is not evidence of absence. And the p-value of 0.075 is not a 7.5% chance that the service is right. It means this: if the claimed split were exactly correct, samples of 200 would give a mismatch this extreme or worse about 7.5% of the time. The probability lives in the process that makes the data, not in the hypothesis.
- Goodness of fit compares one categorical variable's observed counts against a claimed distribution.
- E = n × p. Never round expected counts, and check that they add up to n.
- χ2 = Σ(O − E)2/E is never negative, and the test is always right-tailed. df = k − 1.
- A p-value is the probability of data this extreme given H0, not the probability that H0 is true.
- Check the four conditions before the p-value, and remember that fail to reject never means accept.
Section 2Chi-square test of independence

Two variables, one table
Now you have two categorical variables measured on the same people. You cross them into a contingency table (also called a two-way table or crosstab) with r rows and c columns. Does exercise habit go with sleep quality? Does region go with brand choice? Does treatment group go with the kind of outcome? The test of independence asks whether knowing a person's row tells you anything about their column.
- H0: the two variables are independent in the population, so there is no link (association).
- Ha: the two variables are associated, so they are not independent.
The statistic is the same formula as in Section 1, cell by cell, and the test is still right-tailed. Only two things change: how you get the expected counts, and how you count degrees of freedom.
Expected counts from the margins
Under independence, the probability of landing in a given row and a given column is the product of the two separate probabilities. Turn that into counts, and you get the working formula every cell obeys:
E = (row total × column total) / grand total
Here is why it works. The row total divided by n estimates the probability of that row. Multiply by the column total, and you get how many of that column's members should fall in that row if the row split were the same everywhere. That last phrase is the practical meaning of independence: every row has the same column profile.
The degrees of freedom are df = (r − 1)(c − 1). The logic is the same as before. With the margins fixed, once you fill in an (r − 1) by (c − 1) block of the table, subtraction forces every other cell.
A worked example, start to finish
A researcher surveys n = 300 adults, recording whether they exercise regularly and how they rate their sleep. Test for a link at α = 0.05.
| Observed counts | Good sleep | Fair sleep | Poor sleep | Row total |
|---|---|---|---|---|
| Exercises regularly | 75 | 50 | 25 | 150 |
| Does not exercise | 45 | 55 | 50 | 150 |
| Column total | 120 | 105 | 75 | 300 |
Step 1: expected counts. Top left: (150 × 120)/300 = 60.0. Top middle: (150 × 105)/300 = 52.5. Top right: (150 × 75)/300 = 37.5. The two row totals happen to be equal here, so the bottom row repeats those values. Every expected count is at least 5, so the test is safe to run.
| Cell | Observed O | Expected E | O − E | (O − E)2/E |
|---|---|---|---|---|
| Exercise & Good | 75 | 60.0 | +15.0 | 225/60 = 3.7500 |
| Exercise & Fair | 50 | 52.5 | −2.5 | 6.25/52.5 = 0.1190 |
| Exercise & Poor | 25 | 37.5 | −12.5 | 156.25/37.5 = 4.1667 |
| No exercise & Good | 45 | 60.0 | −15.0 | 225/60 = 3.7500 |
| No exercise & Fair | 55 | 52.5 | +2.5 | 6.25/52.5 = 0.1190 |
| No exercise & Poor | 50 | 37.5 | +12.5 | 156.25/37.5 = 4.1667 |
| Total | 300 | 300.0 | 0 | χ2 = 16.071 |
Step 2: the statistic. Adding the last column: χ2 = 16.07.
Step 3: degrees of freedom. There are r = 2 rows and c = 3 columns, so df = (2 − 1)(3 − 1) = 2. The critical value at α = 0.05 is again 5.991.
Step 4: decide and explain. 16.07 is far above 5.991, and the p-value is about 0.0003. We reject H0. There is strong evidence of a link between regular exercise and how people rate their own sleep in this population.
Step 5: describe the link. The test says "associated" and stops there, so you have to look at the cells yourself. The two largest shares are the two "Poor" cells, at 4.1667 each. These are Exercise and Poor (observed 25, expected 37.5) and No exercise and Poor (observed 50, expected 37.5). Next come the two "Good" cells, at 3.7500 each. The row totals happen to be equal here, so the shares come in mirrored pairs. So it is the Good and Poor columns together that drive the result. People who exercise landed in "Good" more often and "Poor" less often than independence predicts, and people who do not exercise did the reverse. A tidier way to say the same thing is the standardized residual, (O − E)/√E. For Exercise and Good, that is 15/√60 = +1.94. For Exercise and Poor, it is −12.5/√37.5 = −2.04. The no exercise row reverses both signs. Residuals beyond about ±2 mark the cells that drove the result. Here only the two Poor cells clear that bar, with the two Good cells just short of it.
Step 6: measure how big it is. With 300 people, even a modest link gets a tiny p-value, so report an effect size. Cramér's V = √[χ2 / (n × min(r−1, c−1))] = √[16.071 / (300 × 1)] = √0.05357 = 0.23. On a scale from 0 to 1, that is a real but moderate link. It is clear in the statistics, but modest in practice.
- The test of independence crosses two categorical variables in an r × c table.
- E = (row total × column total)/grand total, and df = (r − 1)(c − 1).
- Rejecting H0 means "associated," not "which way." Read the cells and the standardized residuals to describe the pattern.
- Report an effect size such as Cramér's V. With a large n, significance alone says very little about importance.
Section 3One-way ANOVA

Why not just run a lot of t tests?
Say you have three training methods, and you want to know whether their mean test scores differ. The obvious move is three t tests: A vs B, A vs C and B vs C. The obvious move is wrong, and it is worth seeing just why.
Each test at α = 0.05 has a 5% chance of a false alarm. If the three tests were independent, the chance that at least one raises a false alarm would be 1 − (0.95)3 = 1 − 0.857 = 0.143. With five groups, there are ten pairwise tests, and the figure climbs to 1 − (0.95)10 = 0.401. Be honest about that math. Pairwise tests on the same groups are not independent, because every pair reuses a sample the other pairs also used. So treat 14% and 40% as pictures of the size of the problem, not exact rates. The direction is what matters, and it is not in doubt. You set out to run a 5% risk and quietly took on a far larger one. This inflated risk is the family-wise error rate, and it is the reason ANOVA exists: one test, one α, one answer.
- H0: μ1 = μ2 = μ3 = … = μk (all population means are equal).
- Ha: at least one mean differs from at least one other. (It is not "all means differ," which is a very common misstatement.)
The idea: two ways to measure spread
The name is honest: you analyze variance in order to learn about means. Here is the trick. If all the group means were truly equal, then two fully different calculations would both estimate the same population variance σ2:
- Within-group variability (MSW): pool the scatter inside each group. Nothing about group differences touches this number. It is pure background noise, and it estimates σ2 whether H0 is true or not.
- Between-group variability (MSB): measure how far the group means sit from the grand mean. If H0 is true, the means differ only by sampling noise, and this also estimates σ2. If H0 is false, real differences in the means inflate it.
So the ratio
F = MSB / MSW = (signal + noise) / noise
should sit near 1 when the means are equal, and grow large when they are not. That is why ANOVA, like chi-square, is a right-tailed test: only big F values are evidence against H0. And both mean squares are sums of squares divided by positive degrees of freedom. So neither can be negative, and F is never negative either.
Here are the building blocks. N = total observations, k = number of groups, nj and x̄j are the size and mean of group j, and x̄ is the grand mean:
- SSbetween = Σ nj(x̄j − x̄)2, with df = k − 1
- SSwithin = ΣΣ(x − x̄j)2, with df = N − k
- SStotal = SSbetween + SSwithin, with df = N − 1
- MS = SS / df in each row, and F = MSB/MSW with (k − 1, N − k) degrees of freedom.
A worked example, start to finish
There are three training methods, with five people each (N = 15, k = 3), and the data are test scores. Check the conditions first, as always. The groups are independent, each is about symmetric with no outliers and the response is a number (quantitative). The equal variance condition is checked plainly with these very numbers in Section 4. ANOVA is the right tool here.
| Group | Scores | Sum | nj | Mean x̄j | Σ(x − x̄j)2 |
|---|---|---|---|---|---|
| A | 68, 71, 72, 73, 76 | 360 | 5 | 72 | 16+1+0+1+16 = 34 |
| B | 72, 75, 77, 79, 82 | 385 | 5 | 77 | 25+4+0+4+25 = 58 |
| C | 78, 80, 82, 83, 87 | 410 | 5 | 82 | 16+4+0+1+25 = 46 |
| Overall | - | 1155 | 15 | x̄ = 77 | SSwithin = 138 |
Step 1: grand mean. (360 + 385 + 410)/15 = 1155/15 = 77.
Step 2: between-group sum of squares. SSbetween = 5(72 − 77)2 + 5(77 − 77)2 + 5(82 − 77)2 = 5(25) + 5(0) + 5(25) = 125 + 0 + 125 = 250.
Step 3: within-group sum of squares. Add the last column of the table: 34 + 58 + 46 = 138.
Step 4: check the split. SStotal should equal 250 + 138 = 388. Working it out directly from all fifteen deviations about 77 gives 159 + 58 + 171 = 388. The identity holds, which is a strong sign the math is right.
Step 5: mean squares and F. MSB = 250/2 = 125.00. MSW = 138/12 = 11.50. F = 125.00/11.50 = 10.87.
| Source | SS | df | MS = SS/df | F | p-value |
|---|---|---|---|---|---|
| Between groups | 250 | k − 1 = 2 | 125.00 | 10.87 | ≈ 0.0020 |
| Within groups (error) | 138 | N − k = 12 | 11.50 | - | - |
| Total | 388 | N − 1 = 14 | - | - | - |
Step 6: decide. The critical value for F(2, 12) at α = 0.05 is 3.89. Our 10.87 sails past it, with p ≈ 0.0020, so we reject H0.
| Numerator df (k − 1) | Denominator df (N − k) | Critical F, α = 0.05 |
|---|---|---|
| 2 | 12 | 3.89 |
| 2 | 20 | 3.49 |
| 3 | 20 | 3.10 |
| 3 | 30 | 2.92 |
| 4 | 30 | 2.69 |
Step 7: explain it exactly. "There is strong evidence that at least one of the three method means differs from the others." That is all the F test earns you. It does not say A differs from B, and it does not say every pair differs. Section 5 is where you find out which pairs are really apart, and the answer will surprise you.
Step 8: report an effect size. Eta squared, η2 = SSbetween/SStotal = 250/388 = 0.64. About 64% of the variation in test scores is explained by which method a person got. That is a large effect, and a far more useful number to a decision maker than "p < 0.05."
- Running many pairwise t tests inflates the family-wise error rate: about 14% with three groups and 40% with five.
- ANOVA compares MSB (between-group variability) with MSW (within-group noise): F = MSB/MSW.
- SStotal = SSbetween + SSwithin. The df are k − 1, N − k and N − 1.
- A significant F means at least one mean differs, never "all means differ." Report η2 alongside it.
Section 4Assumptions

What chi-square requires
A p-value is a promise, and the promise comes with conditions. Every chi-square p-value assumes four things, and software will happily print a number even when all four are broken.
1. The data are counts. Chi-square uses raw frequencies: how many people, how many items. Feeding it percentages, proportions or group means is the most common misuse. If your table holds "42%" instead of "42 people," convert back to counts first. If you cannot, you do not have the data you need.
2. Observations are independent, and each falls in just one cell. There should be one row of data per person or item. Say the same person is counted twice, such as before and after an intervention. Then the observations are paired, and chi-square is the wrong test. Use McNemar's test for a paired 2 × 2 table.
3. Expected counts are large enough. The chi-square curve is a smooth approximation to a problem about whole number counts, and the approximation frays when expected counts are tiny. The common working rule is that all expected counts are ≥ 5. Cochran's slightly more forgiving version allows up to 20% of cells to have an E between 1 and 5, as long as none falls below 1. Note that this is a condition on expected counts, not observed ones, so an observed zero is perfectly fine.
4. The sample is random. Every claim about the population depends on the sample standing for it. No formula repairs a convenience sample.
When rule 3 fails, you have real choices. You can merge sparse groups into a sensible larger one, such as two rarely used answer levels next to each other becoming a single "other" group. You can collect more data. Or you can switch to Fisher's exact test, which works out the probability directly and needs no large sample approximation at all.
What ANOVA requires
1. Independence, both within and between groups. This is the assumption ANOVA is least willing to forgive, and no amount of data fixes a breach of it. If the same subjects appear in every group, you need repeated-measures ANOVA instead.
2. Approximate normality of the response within each group (or in the same way, of the residuals). ANOVA truly holds up well here (it is robust). With group sizes about equal and a sample of decent size, moderate skew barely dents the F test, and the Central Limit Theorem is on your side. The condition matters most when groups are small (under about 15), or the data are strongly skewed or full of outliers. Check it with a histogram or normal quantile plot for each group, not with a formal normality test on tiny samples.
3. Homogeneity of variance: the spreads in the populations are equal across groups. MSW pools all the groups' scatter into one number, and that pooling only makes sense if there is one shared σ2 to pool. There are two quick checks. The largest sample standard deviation should be less than about twice the smallest. Or, in the same way, the largest variance should be less than about four times the smallest. Levene's test is the formal version.
4. The response is quantitative and measured on an interval or ratio scale. You cannot average a group label.
Let us actually run check 3 on the Section 3 data. The within-group sums of squares were 34, 58 and 46, each with df = 4:
| Group | SS | s2 = SS/(n−1) | s |
|---|---|---|---|
| A | 34 | 34/4 = 8.50 | 2.92 |
| B | 58 | 58/4 = 14.50 | 3.81 |
| C | 46 | 46/4 = 11.50 | 3.39 |
The largest s divided by the smallest s = 3.81/2.92 = 1.31, well under 2. The largest variance over the smallest = 14.50/8.50 = 1.71, well under 4. The equal variance condition is met, so the pooled MSW of 11.50 was a fair thing to work out.
When a condition fails
A failed assumption is not the end of the analysis. It is a signpost to a different test.
| Condition that failed | Symptom | What to do instead |
|---|---|---|
| Expected counts too small | Any E < 5, sparse table | Combine categories; or use Fisher's exact test |
| Paired categorical data | Same subjects measured twice | McNemar's test |
| Unequal ANOVA variances | smax/smin > 2, especially with unequal n | Welch's ANOVA (does not pool variances) |
| Strong non-normality, small groups | Heavy skew or clear outliers | Kruskal-Wallis test (rank-based) |
| Same subjects in every group | Repeated measurements | Repeated-measures ANOVA |
| Non-random sample | Convenience or self-selected data | Describe only; no valid inference to a population |
- Chi-square needs counts, independent observations, expected counts ≥ 5 and a random sample.
- ANOVA needs independence, approximate normality within groups, equal variances and a quantitative response.
- Rules of thumb: all E ≥ 5, and smax/smin < 2 (or a variance ratio < 4).
- Failed conditions point to a specific stand in test: Fisher's exact, McNemar, Welch or Kruskal-Wallis.
Section 5After a significant ANOVA

The F test leaves you with a question
We rejected H0 in Section 3 with F = 10.87. What we know is that the three method means are not all equal. What we do not know is which ones differ. That gap is just what post-hoc ("after this") comparisons fill. They go back through the pairs one at a time, while keeping the total false alarm risk across the whole family of comparisons at α.
And this is where you cannot simply run ordinary t tests, for the very reason ANOVA existed in the first place. Three unadjusted pairwise tests carry a family-wise error rate of about 14%. Post-hoc methods are pairwise tests with the inflation built out.
Two workhorses: Bonferroni and Tukey
The Bonferroni correction is the simplest honest fix in all of statistics. If you plan m comparisons, test each one at α/m. With three groups, m = 3, and each comparison is judged at 0.05/3 = 0.0167. Put another way, multiply each raw p-value by 3 and compare it with 0.05. It works for any set of comparisons, and it takes ten seconds to explain. It is also somewhat cautious (conservative). It guards against false alarms so firmly that it can miss real differences, most of all when m is large.
Tukey's HSD (Honestly Significant Difference) is built for the one job of comparing all pairs after an ANOVA, and for that job it is more powerful than Bonferroni. Instead of a t distribution, it uses the studentized range distribution q. That already accounts for the fact that you are looking at the largest gaps among k means. For equal group sizes, the rule is beautifully simple: any two means further apart than the HSD value are significantly different.
HSD = qα, k, N−k × √(MSW / n)
Working it out on our data
From the ANOVA table: MSW = 11.50, N − k = 12, k = 3 and n = 5 per group. The studentized range value q for α = 0.05, k = 3 and df = 12 is 3.77.
Step 1: the standard error piece. √(MSW/n) = √(11.50/5) = √2.30 = 1.517.
Step 2: the HSD cutoff. HSD = 3.77 × 1.517 = 5.72. Any two sample means more than 5.72 points apart are significantly different, and any pair closer than that is not.
Step 3: compare every pair. The means were A = 72, B = 77 and C = 82.
| Comparison | Difference in means | |Difference| | vs. HSD = 5.72 | Conclusion |
|---|---|---|---|---|
| A vs B | 72 − 77 = −5 | 5.00 | 5.00 < 5.72 | Not significant |
| A vs C | 72 − 82 = −10 | 10.00 | 10.00 > 5.72 | Significant |
| B vs C | 77 − 82 = −5 | 5.00 | 5.00 < 5.72 | Not significant |
Read that result with care, because it is the whole point of the section. The overall F was highly significant, yet only one of the three pairs is apart. Method C beats method A, but neither can be told apart from the middle method B. Say an analyst reported, "The ANOVA was significant, so all three methods differ." That analyst would have gotten the science wrong while getting the math right.
Step 4: give intervals, not just verdicts. Tukey also gives confidence intervals: difference ± HSD. For A vs C, that is −10 ± 5.72, or (−15.72, −4.28). The interval leaves out zero, so the difference is significant. And the interval says far more than the p-value does. It says the believable edge of C over A runs from about 4 to about 16 points. Say what such an interval means with care. The method that made it catches the true mean difference in 95% of all possible samples. It is not a 95% chance that this one interval, already worked out and sitting on the page, contains the parameter. The parameter is fixed, and the interval is what varies from sample to sample.
Step 5: cross check with Bonferroni. The standard error of a difference is √[MSW(1/n + 1/n)] = √[11.50(0.4)] = √4.60 = 2.145. For A vs C, t = 10/2.145 = 4.66. For A vs B, t = 5/2.145 = 2.33. The Bonferroni critical value is the t for α = 0.0167 two-tailed with df = 12, about 2.78. So A vs C (4.66) clears it, and A vs B (2.33) does not. That is the same conclusion Tukey reached, which is reassuring.
Choosing a method, and when not to bother
| Method | Best used for | Character |
|---|---|---|
| Tukey's HSD | All pairwise comparisons after ANOVA | The default choice; most powerful for this exact job |
| Bonferroni | A small, pre-specified set of comparisons | Simple, universally valid, conservative |
| Dunnett's test | Every group vs. a single control group | More powerful than Tukey when only control contrasts matter |
| Scheffé's method | Any contrast, including ones you thought of afterward | Most flexible, most conservative |
| Games-Howell | Pairwise comparisons with unequal variances | The post-hoc partner to Welch's ANOVA |
Two habits keep this honest. First, if the overall F is not significant, do not go fishing through the pairs hoping one turns up. That is just the error inflation the F test protected you from. (Planned contrasts, named before seeing the data, are the fair exception.) Second, always show the picture. Side by side boxplots of the three groups show the overlap between A and B, and the clean gap between A and C, faster than any table of p-values.
- A significant F says "at least one mean differs." Post-hoc tests find which pairs.
- Tukey's HSD = q × √(MSW/n) is the standard for all pairwise comparisons. Bonferroni (α/m) is the simple, all purpose fix.
- Significant overall does not mean every pair differs. Here only A vs C were apart.
- A 95% interval is a statement about the method over the long run, not a 95% chance for the interval in front of you.
The chapter in one breath
- Every chi-square test uses χ2 = Σ(O − E)2/E. It is never negative, and it is always right-tailed.
- Goodness of fit tests one categorical variable against a claimed distribution: E = np and df = k − 1.
- The test of independence tests two categorical variables for a link: E = (row × column)/total and df = (r − 1)(c − 1). And association is not causation.
- One-way ANOVA compares three or more means with F = MSB/MSW, avoiding the family-wise error that many t tests would create.
- The split SStotal = SSbetween + SSwithin is both the engine of ANOVA and a built in math check.
- Chi-square needs counts, independence and expected counts ≥ 5. ANOVA needs independence, rough normality and equal variances. Each failure has a named other test.
- A significant F means at least one mean differs. Tukey's HSD or a Bonferroni correction tells you which pairs, without inflating α.
- Always pair a p-value with an effect size (Cramér's V, η2) and an interval, and state both as exactly as they demand.
ReferenceWords worth knowing
A quick reference for the terms in this chapter. Skim it now, or come back whenever a word trips you up.
- Alpha (α)
- The significance level: the risk of a false alarm you agree to accept before collecting data. It is most often 0.05.
- Analysis of variance (ANOVA)
- A method that compares three or more population means by comparing two estimates of variance, between-group and within-group.
- Bonferroni correction
- Testing each of m planned comparisons at α/m, so the family-wise error rate stays at α. It is simple and cautious.
- Chi-square statistic (χ2)
- Σ(O − E)2/E, a measure of total mismatch between observed and expected counts that is never negative.
- Contingency table
- A two-way table of counts crossing two categorical variables, with row, column and grand totals in the margins.
- Cramér's V
- An effect size for a contingency table, √[χ2/(n × min(r−1, c−1))]. It runs from 0 (no link) to 1.
- Degrees of freedom
- The number of values free to vary once the limits are set. It is k − 1 for goodness of fit, (r−1)(c−1) for independence and (k−1, N−k) for ANOVA.
- Eta squared (η2)
- SSbetween/SStotal: the share of variation in the response explained by which group a person is in.
- Expected count (E)
- The count a cell would show on average if the null hypothesis were true. Never round it.
- F statistic
- The ratio MSB/MSW. It is near 1 when group means are equal and large when they are not. It is never negative, and it is always tested in the upper tail.
- Family-wise error rate
- The probability of at least one false alarm across a whole family of tests. It inflates fast as the number of comparisons grows.
- Goodness-of-fit test
- A chi-square test of whether one categorical variable's observed counts match a claimed distribution.
- Homogeneity of variance
- The ANOVA condition that all groups share the same population variance. It is checked with smax/smin < 2 or Levene's test.
- Kruskal-Wallis test
- A rank based stand in for one-way ANOVA, used when the normality condition fails badly.
- Mean square (MS)
- A sum of squares divided by its degrees of freedom, which makes it a variance estimate. MSB and MSW are the two that build F.
- Observed count (O)
- The actual tally in a group or cell of your sample.
- p-value
- The probability of getting data at least as extreme as yours if the null hypothesis were true. It is not the probability that the null hypothesis is true.
- Post-hoc test
- A follow up comparison run after a significant ANOVA to find which groups differ, with the family-wise error rate controlled.
- Standardized residual
- (O − E)/√E for one cell. Values beyond about ±2 flag the cells driving a significant chi-square.
- Sum of squares (SS)
- A total of squared deviations. In ANOVA, SStotal splits exactly into SSbetween + SSwithin.
- Test of independence
- A chi-square test of whether two categorical variables measured on the same subjects are linked.
- Tukey's HSD
- Honestly Significant Difference: q × √(MSW/n). It is the standard post-hoc method for comparing all pairs of means after ANOVA.