The chi-square test of independence helps determine whether two categorical variables are associated. It is used when data are counts sorted into categories, such as survey responses by grade level or treatment outcome by group. The test compares the counts you observed in a two-way table with the counts you would expect if the variables were unrelated.
It matters because it gives a structured way to decide whether a pattern in categorical data is likely to be real or just due to random variation.
The test begins by finding the expected count for each cell using the row total, column total, and grand total. Then it adds up how far the observed counts are from the expected counts using the chi-square test statistic. A large chi-square value means the observed table is far from what independence predicts.
The p-value tells whether that difference is statistically significant, based on the degrees of freedom from the table size.
Key Facts
- Use the chi-square test of independence for two categorical variables measured as counts.
- Expected count: E = (row total)(column total) / grand total.
- Test statistic: χ² = Σ((O - E)² / E), where O is observed count and E is expected count.
- Degrees of freedom: df = (number of rows - 1)(number of columns - 1).
- Null hypothesis H0: the two categorical variables are independent.
- If p-value < α, reject H0 and conclude there is evidence of an association.
Vocabulary
- Contingency table
- A table that displays counts for combinations of categories from two variables.
- Observed count
- The actual number of cases recorded in a cell of the table.
- Expected count
- The count predicted for a cell if the two variables are independent.
- Chi-square statistic
- A measure of how far the observed counts are from the expected counts across all cells.
- P-value
- The probability of getting a chi-square statistic at least as large as the observed one if the null hypothesis is true.
Common Mistakes to Avoid
- Using percentages instead of counts, because the chi-square formula requires actual frequency counts in each cell.
- Forgetting to check expected counts, because very small expected counts can make the chi-square approximation unreliable.
- Interpreting rejection as proof of causation, because the test shows association between variables, not that one variable causes the other.
- Using the wrong degrees of freedom, because df depends on the number of rows and columns as df = (r - 1)(c - 1).
Practice Questions
- 1 A survey of 100 students records favorite subject by gender. The row total for males is 45, the column total for math is 30, and the grand total is 100. What is the expected count for males who prefer math?
- 2 For one cell in a two-way table, O = 18 and E = 12. What is that cell's contribution to the chi-square statistic, (O - E)² / E?
- 3 A chi-square test of independence gives p = 0.03 at α = 0.05. State the decision about H0 and explain what the result means in context of two categorical variables.