📖 Contents · Hub · Full version Chapter 13 · Chi-Square & ANOVA
Statistics Easy Read · Chapter 13

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

A chi-square distribution curve with the right-hand tail shaded to show the p-value region
Reference. A chi-square distribution with the right tail shaded. Every chi-square test puts its p-value in that upper tail. Source and license: see the figure credits

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:

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.

CategoryObserved OClaimed pExpected E = npO − E(O − E)2/E
Bronze400.2550−10100/50 = 2.0000
Silver950.4080+15225/80 = 2.8125
Gold650.3570−525/70 = 0.3571
Total2001.002000χ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
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.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.

The biggest term tells you the story. Even when you fail to reject, look at which group added the most. Here Silver added 2.81 of the 5.17, since the sample had 95 Silver where 80 were predicted. That is the direction to watch if you collect more data. The overall test is a smoke alarm, and the single terms tell you which room to check.
Interactive Set a claimed color mix and a hidden truth, then open real sampled bags of candy and watch chi-square assemble itself one cell at a time: expected counts from the claim, misses squared and scaled, stacked against the critical value and verified over thousands of simulated bags. Open full ↑
Key points
  • 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

A two-way contingency table showing counts arranged in rows and columns with marginal totals
Reference. A contingency table: two categorical variables crossed, with row, column and grand totals in the margins. Source and license: see the figure credits

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.

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 countsGood sleepFair sleepPoor sleepRow total
Exercises regularly755025150
Does not exercise455550150
Column total12010575300

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.

CellObserved OExpected EO − E(O − E)2/E
Exercise & Good7560.0+15.0225/60 = 3.7500
Exercise & Fair5052.5−2.56.25/52.5 = 0.1190
Exercise & Poor2537.5−12.5156.25/37.5 = 4.1667
No exercise & Good4560.0−15.0225/60 = 3.7500
No exercise & Fair5552.5+2.56.25/52.5 = 0.1190
No exercise & Poor5037.5+12.5156.25/37.5 = 4.1667
Total300300.00χ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.

Association is not causation, and a survey cannot make it one. These data come from watching, not from an experiment (they are observational). Exercise may improve sleep. Good sleep may make people feel like exercising. Or a third factor, such as age, stress, shift work or long lasting pain, may drive both. A significant χ2 shows that the variables move together. Only a randomized experiment shows which one pushes.
Interactive Survey real people, cross-tabulate two categorical variables, build the expected counts from the row and column totals, and test whether the two variables are associated. Open full ↑
Key points
  • 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

An F distribution curve with the rejection region in the upper tail shaded
Reference. The F distribution with its upper tail rejection region. It is the reference curve for every ANOVA. Source and license: see the figure credits

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.

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:

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:

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.

GroupScoresSumnjMean x̄jΣ(x − x̄j)2
A68, 71, 72, 73, 7636057216+1+0+1+16 = 34
B72, 75, 77, 79, 8238557725+4+0+4+25 = 58
C78, 80, 82, 83, 8741058216+4+0+1+25 = 46
Overall-115515x̄ = 77SSwithin = 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.

SourceSSdfMS = SS/dfFp-value
Between groups250k − 1 = 2125.0010.87≈ 0.0020
Within groups (error)138N − k = 1211.50--
Total388N − 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
2123.89
2203.49
3203.10
3302.92
4302.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."

With exactly two groups, ANOVA and the pooled t test are the same test. Run both on the same two samples, and you will find F = t2, with the same p-values. ANOVA is not a different idea from the two-sample t test. It is the same idea, widened so it does not fall apart when you add a third group.
Interactive Drag each group's mean bar apart or widen the within-group scatter and watch the one-way ANOVA F statistic, its sums-of-squares decomposition, p-value, and a live power simulation all recompute in real time. Open full ↑
Key points
  • 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

A histogram of sample data with a normal curve overlaid to assess whether the data are approximately normal
Reference. A histogram checked against a normal curve. This is the everyday way to judge the normality condition. Source and license: see the figure credits

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:

GroupSSs2 = SS/(n−1)s
A3434/4 = 8.502.92
B5858/4 = 14.503.81
C4646/4 = 11.503.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 failedSymptomWhat to do instead
Expected counts too smallAny E < 5, sparse tableCombine categories; or use Fisher's exact test
Paired categorical dataSame subjects measured twiceMcNemar's test
Unequal ANOVA variancessmax/smin > 2, especially with unequal nWelch's ANOVA (does not pool variances)
Strong non-normality, small groupsHeavy skew or clear outliersKruskal-Wallis test (rank-based)
Same subjects in every groupRepeated measurementsRepeated-measures ANOVA
Non-random sampleConvenience or self-selected dataDescribe only; no valid inference to a population
Check the conditions before you look at the p-value, not after. Once you have seen a promising p-value, the urge to declare the assumptions "close enough" is nearly impossible to resist, and the decision is no longer honest. Write the assumption check as step one of your method. Let its verdict stand, whichever way the test comes out.
Interactive A live assumption checker for the chi-square test and one-way ANOVA: move sliders to watch expected cell counts, group standard deviations, the variance ratio, normality, and independence get evaluated in real time, with the χ² statistic and p-value computed from a fresh sample. Open full ↑
Key points
  • 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

Side-by-side boxplots comparing the distributions of several groups
Reference. Side by side boxplots: the natural picture for comparing several groups after an ANOVA. Source and license: see the figure credits

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.

ComparisonDifference in means|Difference|vs. HSD = 5.72Conclusion
A vs B72 − 77 = −55.005.00 < 5.72Not significant
A vs C72 − 82 = −1010.0010.00 > 5.72Significant
B vs C77 − 82 = −55.005.00 < 5.72Not 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

MethodBest used forCharacter
Tukey's HSDAll pairwise comparisons after ANOVAThe default choice; most powerful for this exact job
BonferroniA small, pre-specified set of comparisonsSimple, universally valid, conservative
Dunnett's testEvery group vs. a single control groupMore powerful than Tukey when only control contrasts matter
Scheffé's methodAny contrast, including ones you thought of afterwardMost flexible, most conservative
Games-HowellPairwise comparisons with unequal variancesThe 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 is a beginning, not a conclusion. It tells you the groups are not all the same. Everything a reader truly wants comes from the post-hoc comparisons, the confidence intervals and the effect size. That means which groups differ, by how much, with what uncertainty and whether it matters in practice. Report all four, and your analysis is complete.
Interactive A significant ANOVA says the arms are not all alike but not which ones: run the post-hoc comparisons live, watch confidence intervals widen under a correction, and simulate how uncorrected pairwise testing inflates the false-alarm rate. Open full ↑
Key points
  • 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.

Check yourself

1. A study claims that a population splits 40/35/25 across three groups. In a sample of 400, what are the expected counts, and what are the degrees of freedom?
E = 160, 140 and 100; df = 2. The expected counts are E = np: 400(0.40) = 160, 400(0.35) = 140 and 400(0.25) = 100, which add up to 400 as a check. With k = 3 groups, df = k − 1 = 2.
2. Why is a chi-square test always right-tailed, and why can χ2 never be negative?
Every term is a squared amount divided by a positive expected count, so the sum cannot be negative, and only large values show a mismatch. A χ2 near zero means the observed counts nearly equal the expected ones, which supports H0. So evidence against H0 can only show up in the upper tail.
3. A goodness-of-fit test gives χ2 = 5.17 with df = 2 and p = 0.075. A classmate writes, "There is a 7.5% chance the company's claim is correct." Fix the sentence.
"If the claimed distribution were exactly true, about 7.5% of samples of this size would show a mismatch this large or larger." A p-value is a probability about data, worked out under the null hypothesis. It is never the probability that the hypothesis itself is true. Also, since 0.075 > 0.05, we fail to reject, which is not the same as proving the claim correct.
4. In a 3 × 4 contingency table with a grand total of 500, a cell sits in a row totaling 200 and a column totaling 125. Find its expected count and the table's degrees of freedom.
E = (200 × 125)/500 = 50; df = (3 − 1)(4 − 1) = 6. Expected counts in a test of independence always come from the margins. The degrees of freedom are (r − 1)(c − 1), not rc − 1.
5. A test of independence on 300 people gives χ2 = 16.07, df = 2 and p ≈ 0.0003. What may you conclude, and what may you not?
You may conclude that the two variables are linked in the population. You may not conclude that one causes the other, nor read a direction from the test statistic alone. Data from watching cannot rule out reverse causation or a hidden third variable. To describe the pattern, look at the cells and the standardized residuals. To judge size, work out Cramér's V (here √(16.07/300) = 0.23, a moderate link).
6. Why not simply run three two-sample t tests instead of one ANOVA when comparing three groups?
Because the family-wise error rate inflates: 1 − (0.95)3 ≈ 0.143. That is about a 14% chance of at least one false alarm instead of 5%. With five groups (ten pairwise tests), it reaches 1 − (0.95)10 ≈ 0.40. ANOVA answers the question with a single test at a single α.
7. Four groups of 8 subjects each give SSbetween = 180 and SSwithin = 336. Build the ANOVA table and work out F.
F = 5.00 on (3, 28) degrees of freedom. N = 32 and k = 4. dfbetween = 3, so MSB = 180/3 = 60. dfwithin = 32 − 4 = 28, so MSW = 336/28 = 12. F = 60/12 = 5.00. SStotal = 516 with df = 31, and η2 = 180/516 = 0.35.
8. Explain in plain language why F = MSB/MSW should be near 1 when the null hypothesis is true.
If all population means are equal, MSB and MSW are two independent estimates of the same population variance σ2. So their ratio hovers around 1. When the means truly differ, real separation adds to the top number, while the bottom number still measures only within-group noise. That pushes F well above 1, which is why only large F values count as evidence.
9. A 2 × 2 table has expected counts of 3.2, 6.8, 4.1 and 8.9. What is the problem, and what are two ways forward?
Two expected counts fall below 5, so the chi-square approximation cannot be trusted. The choices are to collect more data, or to merge groups where that makes real sense. The standard fix for a small 2 × 2 table is Fisher's exact test, which needs no large sample approximation. Note that the rule applies to expected counts, not observed ones.
10. Three groups have sample standard deviations of 4.0, 7.5 and 9.0. Does the equal variance condition for ANOVA look satisfied?
Just barely not: smax/smin = 9.0/4.0 = 2.25, above the rule of thumb limit of 2 (the variance ratio is 81/16 = 5.06, above 4). Confirm with Levene's test and a look at side by side boxplots. If the condition really fails, most of all with unequal group sizes, use Welch's ANOVA, followed by Games-Howell comparisons instead of Tukey's HSD.
11. An ANOVA on three groups is significant. The group means are 72, 77 and 82; MSW = 11.5, n = 5 per group and q0.05, 3, 12 = 3.77. Which pairs differ by Tukey's HSD?
Only the 72 vs 82 pair. HSD = 3.77 × √(11.5/5) = 3.77 × 1.517 = 5.72. The gaps are 5, 5 and 10. Only 10 is bigger than 5.72, so the lowest and highest groups differ, while neither can be told apart from the middle group. A significant F plainly does not mean every pair differs.
12. Tukey gives a 95% confidence interval of (−15.72, −4.28) for μA − μC. State what that interval means, and what it does not.
It means the method for building the interval catches the true mean difference in 95% of all possible samples. Because the interval leaves out 0, the difference is significant at the 5% level. It does not mean there is a 95% probability that this one interval, already worked out, contains μA − μC. The parameter is a fixed number, and the interval is what varies from sample to sample. In practice, the data fit with group C averaging about 4 to 16 points higher than group A.