Lesson 17: Chi-Square Tests — Goodness of Fit, Homogeneity, IndependenceAP
🎧 Listen to this lesson
When both variables are categorical, proportions and means no longer apply — we compare counts in a table against the counts we would expect under a null model. The chi-square tests of CED Unit 8 do this with one statistic, χ² = Σ (Observed − Expected)²/Expected, in three costumes that share the machinery but answer different questions. Choosing the right costume is half the exam.
The three chi-square tests
- Goodness of fit: ONE categorical variable, ONE sample. H0: the population distribution matches a claimed set of proportions. Expected counts: E = n × p_claimed. df = (number of categories) − 1.
- Homogeneity: ONE categorical variable measured in two or more populations (or treatment groups). H0: the distribution of the variable is the same across populations. Expected counts from the table margins. df = (r − 1)(c − 1).
- Independence: TWO categorical variables measured in ONE sample. H0: the variables are independent (no association) in the population. Same expected-count formula and df as homogeneity — the distinction is the *design* (one sample vs several populations) and therefore the wording of hypotheses and conclusions.
For table tests, expected count for a cell = (row total × column total)/(grand total) — this is what independence/no-difference predicts: each row gets the column's overall share. Conditions: Random sample(s); all expected counts at least 5 (the check uses expected counts, not observed); independent observations / 10% condition. The χ² statistic sums components (O−E)²/E over cells; large components identify which cells drive a significant result — always worth a sentence in the conclusion. Chi-square tests are inherently right-tailed: big χ² means observed counts stray far from the null model.
Worked example 1 (goodness of fit). A die is rolled 120 times with face counts 16, 22, 18, 25, 19, 20. Testing fairness (H0: each face has probability 1/6), expected counts are all 20. χ² = (16−20)²/20 + (22−20)²/20 + (18−20)²/20 + (25−20)²/20 + (19−20)²/20 + (20−20)²/20 = (16 + 4 + 4 + 25 + 1 + 0)/20 = 50/20 = 2.5. With df = 5, the p-value ≈ 0.777 — nowhere near significant. Conclusion: there is no convincing evidence the die is unfair; counts this uneven (or more so) arise by chance about 78% of the time with a fair die. The largest component comes from the face rolled 25 times, but even it is unremarkable.
Worked example 2 (independence). A survey of 200 students cross-tabulates study time preference by year: first-years — morning 30, evening 70; seniors — morning 45, evening 55. Column totals: morning 75, evening 125. Expected counts under independence: first-year/morning = 100 × 75/200 = 37.5; first-year/evening = 62.5; senior/morning = 37.5; senior/evening = 62.5. χ² = (30−37.5)²/37.5 + (70−62.5)²/62.5 + (45−37.5)²/37.5 + (55−62.5)²/62.5 = 1.5 + 0.9 + 1.5 + 0.9 = 4.8. With df = (2−1)(2−1) = 1, p ≈ 0.028 < 0.05: reject H0 — there is convincing evidence of an association between year and study-time preference in the population; first-years skew more toward evening study than independence would predict (30 observed vs 37.5 expected in the morning cell). Note the exact conclusion words: *association*, not causation — this was a survey.
Real-world application
Genetics runs on goodness of fit: Mendel's pea ratios (9:3:3:1) were validated by comparing observed offspring counts against theoretical proportions — chi-square is literally the test that launched modern genetics' data standards. Market researchers use homogeneity tests to ask whether product preferences differ across regions; political scientists use independence tests on vote choice vs demographics.
Common mistakes
- Running chi-square on percents or means. χ² needs raw counts; feeding it percentages destroys the sample-size information that drives the statistic.
- Choosing the wrong test: if data come from several populations being compared, it is homogeneity, not independence — hypotheses wording must match ("distribution is the same across..." vs "no association between...").
- Checking conditions on observed counts. The ≥5 rule applies to *expected* counts.
- χ² df errors: categories − 1 for GOF (not n − 1); (r−1)(c−1) for tables.
- Causal conclusions from an independence test, or claiming "the variables are dependent" as a *proven* fact rather than evidence against independence.
AP Exam Experience
Question 1. A researcher samples voters from three different cities and records each voter's preference among four candidates, to test whether the distribution of preferences is the same in all three cities. The appropriate test is:
- (A) Chi-square goodness of fit, df = 3
- (B) Chi-square test for homogeneity, df = 6
- (C) Chi-square test for independence, df = 6
- (D) Chi-square test for homogeneity, df = 11
- (E) One-proportion z-test
Answer: (B). Several populations (cities), one categorical variable — homogeneity. The table is 3 × 4, so df = (3−1)(4−1) = 6. (C) has the right df but wrong design: independence requires ONE sample cross-classified by two variables; here samples were drawn separately from each population.
Question 2. In a 3 × 4 contingency table the row totals are 50, 80, 70 and the first column total is 60, with grand total 200. The expected count for the cell in row 2, column 1 under the null model is:
- (A) 24
- (B) 16
- (C) 40
- (D) 26.7
- (E) 60
Answer: (A). E = (row total × column total)/grand total = (80 × 60)/200 = 24. Every expected count in every chi-square table problem is this one formula — and it needs the *margins*, not the observed cell value.
Question 3. A goodness-of-fit test will be performed on a single categorical variable with 6 categories. A sample of size 60 is planned, with claimed proportions that include one category at 0.05. The chi-square conditions are:
- (A) Satisfied, because n = 60 ≥ 30
- (B) Not satisfied, because the expected count for the small category is 60 × 0.05 = 3 < 5
- (C) Satisfied, because all observed counts will be at least 5
- (D) Not satisfied, because df = 5 is too small
- (E) Satisfied, because the sample is random
Answer: (B). Expected counts drive the condition, and 3 < 5 violates it (combine categories or enlarge the sample). (A) imports an irrelevant rule of thumb; (C) checks the wrong counts — observed counts may legitimately be small.
Free-response question. A confectionery company claims its fruit candies come in equal proportions of four flavours. A consumer group buys a random sample of 200 candies and counts: cherry 62, lemon 48, lime 41, orange 49. Test the company's claim at the 5% level.
Scoring guideline.
- State: Essentially correct if H0: the true proportions are equal (p_cherry = p_lemon = p_lime = p_orange = 0.25) and Ha: at least one proportion differs from the claim. (For GOF, Ha is never directional; "not all equal to the claimed proportions" is the correct shape.)
- Plan: Essentially correct if a chi-square goodness-of-fit test is named and conditions verified: random sample (stated); expected counts all 200 × 0.25 = 50 ≥ 5. Partially correct if the condition check cites observed counts instead of expected.
- Do: Essentially correct if χ² = [(62−50)² + (48−50)² + (41−50)² + (49−50)²]/50 = (144 + 4 + 81 + 1)/50 = 230/50 = 4.6, with df = 3 and p-value ≈ 0.20. Partially correct if one component is miscomputed but the method is complete and visible.
- Conclude: Essentially correct if: 0.20 > 0.05, fail to reject H0; there is no convincing evidence that the flavour proportions differ from equal. Incorrect if it claims the test "proves the proportions are exactly equal" — goodness of fit, like every test, cannot prove the null.
Deeper dive: components — reading a significant chi-square
Rejecting H0 with χ² tells you the table disagrees with the null model *somewhere*; the components (O−E)²/E tell you where. In Worked Example 2, the morning cells contribute 1.5 each and the evening cells 0.9 each, but relative to their expected counts the morning discrepancy dominates — and the *signs* of (O − E) complete the story: first-years are over-represented among evening studiers (70 observed vs 62.5 expected) and under-represented in the morning (30 vs 37.5). A conclusion that names the driving cells and their direction ("the association is driven mainly by first-years choosing evening study more than independence predicts") is materially stronger than "the variables are associated", and rubric writers build that expectation into the top score band. One caution: with large samples, tiny, uninteresting discrepancies produce huge χ² — significance again confuses size with importance, and the component analysis is your antidote: if the largest contribution is a fraction of a percent off expectation, say so.
Choosing the test: a thirty-second flowchart
Three questions, in order, identify any chi-square problem. (1) How many samples/populations were data collected from — one, or several? (2) How many categorical variables were recorded — one, or two? (3) Is there a *claimed* distribution from theory or a company? If a claim with specified proportions exists and one variable was measured once, it is goodness of fit. If several populations were each measured on one variable, it is homogeneity — the samples' separate origins are the tell, and it makes no difference that the data arrive printed as one table. If one sample was measured on two variables, it is independence. Write the identification sentence in the Plan step ("One sample, two categorical variables → chi-square test for independence"); readers award it, and it inoculates your hypotheses against the most common mismatch: independence wording pasted onto a homogeneity design.
Second worked example: homogeneity, computed end to end
Two schools survey 100 students each on preferred lunch: School A — pizza 40, salad 25, sandwich 35; School B — pizza 30, salad 35, sandwich 35. Column totals: pizza 70, salad 60, sandwich 70; grand total 200. Under H0 (the distribution of preferences is the same at both schools), each school's expected counts are its row total (100) times the column shares: pizza 35, salad 30, sandwich 35 for *both* schools. χ² = (40−35)²/35 + (25−30)²/30 + (35−35)²/35 + (30−35)²/35 + (35−30)²/30 + (35−35)²/35 = 0.714 + 0.833 + 0 + 0.714 + 0.833 + 0 = 3.09, with df = (2−1)(3−1) = 2 and p-value ≈ 0.21. Fail to reject: no convincing evidence the two schools' preference distributions differ. Two structural notes for the FRQ: the expected counts are identical across schools *because the sample sizes are equal* — unequal samples give row-specific expected counts via the same margin formula; and the hypotheses and conclusion are phrased about *distributions being the same across populations*, homogeneity's signature wording, not about "association".
📊 Interactive
Interactive — hover or explore the chart above.
🎬 Watch & Learn
Free YouTube video lessons on “Chi-Square Tests — Goodness of Fit, Homogeneity, Independence” — pick a result below:
- AP Statistics — Chi-Square Tests — Goodness of Fit, Homogeneity, Independence: full video lesson
- Chi-Square Tests — Goodness of Fit, Homogeneity, Independence on Khan Academy
- Chi-Square Tests — Goodness of Fit, Homogeneity, Independence on jbstatistics
- Chi-Square Tests — Goodness of Fit, Homogeneity, Independence on StatQuest
- Exam practice & worked examples: Chi-Square Tests — Goodness of Fit, Homogeneity, Independence