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.
Understanding Statistics: Chi-Square Test of Independence
Independence is about whether the pattern of one variable changes across the categories of the other. Imagine a school survey on preferred lunch option by grade. If lunch preference is independent of grade, each grade should have roughly the same mix of preferences as the whole survey.
A difference in counts alone does not prove a relationship, because grades may have different numbers of students. The comparison must focus on proportions.
This is why the table totals matter. They provide the baseline pattern that would occur if grade had no connection to lunch preference.
Each cell makes its own contribution to the final result. A cell with many more or many fewer students than expected adds evidence against independence. The size of that contribution depends on the gap relative to the expected count.
A difference of ten is important when only twenty responses were expected. The same difference matters less when five hundred responses were expected.
After a significant result, inspect the cells rather than stopping at the p-value. Comparing observed counts with expected counts, or using standardized residuals when available, shows which category combinations create the pattern.
The test has conditions that protect its conclusions. Each person or object should appear in one cell only. For example, one student cannot be counted twice in a survey of grade and lunch choice.
The observations should come from a random sample or a study design that reasonably represents the group of interest. Counts must be actual frequencies, not percentages, averages, ratings, or measurements such as height. Expected counts should usually be at least five in most cells.
Very small expected counts make the usual p-value unreliable. Researchers may combine sensible categories, collect more data, or use an exact alternative when the table is sparse.
A significant result shows evidence of an association, but it does not show that one variable causes the other. If screen time and sleep category are associated in a student survey, many other factors could influence both, including homework load, age, or family routines. The result also does not tell how strong the association is.
Large samples can make tiny differences significant. Measures such as Cramer's V describe the size of the relationship, while the table shows its direction and practical meaning. When learning this test, state the variables clearly, check the data conditions, interpret the p-value in context, then describe the actual pattern using percentages and cell comparisons.
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.