The chi-square test of independence
5 min read
Short answer
Build a table of observed counts, compute the expected count for each cell , and form . Compare with the chi-square distribution with degrees of freedom. A large means the variables are probably not independent.
The idea
If the variables were independent, each cell's share would equal its row share times its column share. The expected counts encode that. adds up the squared gaps, scaled by the size of the expected count.
Conditions
Observations must be independent, and every expected count should be at least about . If not, merge categories or use an exact test.
Worked example
Two groups answer yes/no: group A has yes and no; group B has yes and no. Test independence at 5%.
Totals: per row, yes, no, overall, so every expected count is . . With degree of freedom the 5% critical value is . Since , reject independence ().
Try it yourself
How many degrees of freedom does a table with 3 rows and 4 columns have?
Show the answer
degrees of freedom: (rows − 1) times (columns − 1).
Keep going with practice
Vidi's probability lessons define independence, the exact condition this test checks.