Statistics › Section K · The chi-square distribution › Topic K.3
Test of independence
The contingency-table topic asked whether two categorical variables travel together; the chi-square test of independence puts that question on formal footing. Expected counts are built from the hypothesis that they don't, and the familiar statistic prices the gap.
From tables to tests
The contingency-table topic compared conditionals by eye: does warranty choice depend on age? This topic formalises the question. From one random sample cross-classified by two categorical variables, the test of independence asks whether the variables are associated - whether knowing one changes the probabilities of the other. The null: they are independent, and the table's row and column patterns are unrelated - knowing a buyer's age tells nothing about their warranty choice, and vice versa.
Expected counts under independence
If two variables are independent, a cell's share is the product of its row and column shares - so the expected count is
The warranty table of 300 buyers had row totals 150 and 150, column totals 108 (warranty) and 192 (no warranty): independence expects \(\frac{150 \times 108}{300} = 54\) under-40 warranty buyers, and the same 54 for buyers 40 or older. Every cell gets its own \(E\) from the margins alone - the null never looks inside the cells.
The statistic and its df
The statistic is the chi-square sum over every cell of the table:
with degrees of freedom \((r-1)(c-1)\) for an \(r \times c\) table. The formula's logic: once the margins are fixed, a \(2 \times 2\) table has only ONE free comparison - pick any cell and the other three are forced - so \((2-1)(2-1) = 1\). Larger tables keep more freedom: a \(3 \times 2\) has \(2 \times 1 = 2\). The df, as always, counts what is free to wander.
Worked example: warranty and age, tested
The warranty table: 42, 108, 66, 84 with margins 150, 150, 108, 192. 1. Expected under independence: 54, 96, 54, 96. 2. \(\chi^2 = \frac{144}{54} + \frac{144}{96} + \frac{144}{54} + \frac{144}{96} \approx 2.67 + 1.50 + 2.67 + 1.50 = 8.33\) with df = 1. 3. \(p \approx 0.004\): at df 1, the curve's mean is 1, and 8.33 lies far into the right tail. 4. \(p \le 0.05\): reject independence - convincing evidence that warranty choice and age group are associated, with the under-40s buying fewer warranties than independence predicts (42 observed against 54 expected) and those 40 or older more (66 against 54).
Worked example: three study formats
Pass rates for 300 students: online 60 of 100 pass, hybrid 75 of 100, in-person 81 of 100. Does pass rate depend on format? 1. Margins: 216 pass, 84 fail. 2. Expected: online pass \(\frac{100 \times 216}{300} = 72\), online fail 28, and the same 72/28 for each format. 3. \(\chi^2 = \frac{144}{72} + \frac{144}{28} + \frac{9}{72} + \frac{9}{28} + \frac{81}{72} + \frac{81}{28} \approx 2.00 + 5.14 + 0.13 + 0.32 + 1.13 + 2.89 = 11.6\) with df = \((3-1)(2-1) = 2\). 4. \(p \approx 0.003\): reject - format and pass rate are associated, and the residuals locate the story: online under-performs (60 against 72 expected), in-person over-performs (81 against 72).
Residuals tell the story
The statistic says WHETHER the variables associate; the residuals say WHERE. Each cell's residual \((O - E)/\sqrt{E}\) scores its own departure, with big values marking the cells that drove the verdict - in the study-format example the online fail cell (40 against 28 expected, residual about 2.3) leads, followed by in-person fail (19 against 28, about -1.7), while in the warranty table all four cells share the work. Reporting a chi-square test without its residuals is like reporting a verdict without reasons: the reader learns that something differs, but not what. The next topic's homogeneity test reads the same way, and a good habit forms here.
Conditions: the same, by cell
The conditions carry over with "each expected count at least about 5" now applied to every cell of the table. The data must be one random sample, cross-classified - not two samples compared (that design is the homogeneity topic's business) and not percentages recycled as counts. Thin cells call for merged categories or more data. And the association the test finds is exactly that - association: a cross-classified survey cannot establish which variable leads which, or what third variable drives both, a caution the contingency-table topic already earned and this test inherits.
Common mistakes to avoid
First, computing expected counts from the observed cells - independence builds them from the margins only. Second, wrong df: \((r-1)(c-1)\), not \(rc - 1\). Third, feeding percentages or proportions to the formula: \(\chi^2\) eats counts. Fourth, claiming causation from association - the design measures travel-together, not why. Fifth, ignoring cells with small expecteds rather than merging them. Sixth, reporting the statistic and p-value with no residuals - the sum hides the very pattern the test exists to find.
Key takeaways
The test of independence asks whether two categorical variables from one random sample are associated, under the null that they are not. Expected counts come from the margins: \(E = \text{row} \times \text{column}/\text{grand}\). The statistic \(\chi^2 = \sum (O-E)^2/E\) runs on \((r-1)(c-1)\) degrees of freedom, right tail only, expected counts of at least about 5 per cell. The warranty table: \(\chi^2 = 8.33\), df 1, \(p \approx 0.004\) - warranty choice associates with age. The study formats: \(\chi^2 = 11.6\), df 2, \(p \approx 0.003\), online under-performing. Residuals tell where; association is not causation.
Flashcards
Flashcard
Expected count under independence
Test your understanding
Question 1 of 5
In a test of independence, expected counts are built from:
Question 2 of 5
For a 2 × 2 table, the degrees of freedom are:
Question 3 of 5
With expected counts 54, 96, 54, 96 and observed 42, 108, 66, 84, χ² is about:
Question 4 of 5
The warranty test gives χ² = 8.33 at df = 1, p ≈ 0.004. At α = 0.05:
Question 5 of 5
A significant chi-square result in an independence test supports:
