66 次浏览

Chi-Square Test of Independence: A Beginner-Friendly Practical Guide

What Is the Chi-Square Test of Independence?

The chi-square test of independence examines whether two categorical variables are associated. It compares the pattern we actually observe in a contingency table with the pattern we would expect if the two variables were unrelated.

This test is useful when your data are counts in categories rather than measurements such as height or blood pressure. Typical questions include whether treatment choice differs by age group, whether customer satisfaction differs by store location, or whether pass rates differ by teaching format.

The Core Formula and Its Meaning

The test statistic is:

chi-square = sum((Observed - Expected)^2 / Expected)

Each cell contributes to the overall statistic. The larger the gap between observed and expected counts, the larger the chi-square statistic becomes. A large value suggests that the variables are probably not independent.

When Should You Use This Test?

  • Both variables are categorical.
  • The data are frequencies or counts.
  • Each observation belongs to one cell only.
  • You want to test association, not causation.

Key Assumptions

  • Observations are independent.
  • Categories are mutually exclusive.
  • Expected counts are not too small. A common rule is that expected counts should usually be at least 5 in most cells.

Step-by-Step Method

  1. Create a contingency table with observed counts.
  2. Compute row totals, column totals, and the grand total.
  3. Calculate each expected count with (row total x column total) / grand total.
  4. Compute the chi-square contribution for each cell.
  5. Add all contributions to obtain the test statistic.
  6. Find the degrees of freedom with (rows - 1) x (columns - 1).
  7. Use the p-value to decide whether the association is statistically significant.

An Original Worked Example

Suppose a training center wants to know whether course format is related to certification outcome. The observed data are:

Course format Passed Failed
Live workshop 32 8
Recorded video 18 12
Self-study packet 20 10

The grand total is 100. If course format and outcome were unrelated, we would calculate expected counts for each cell from the row and column totals. After computing all cell contributions, suppose the final result is chi-square = 6.67 with df = 2 and p = 0.036.

This result suggests that certification outcome differs across course formats. The live workshop appears to have more passes than expected under independence, while the recorded video format has fewer passes than expected.

How to Interpret the Result

A significant result means the two variables are associated, but it does not tell you that one variable causes the other. You should also inspect the observed and expected counts to understand which cells drive the difference.

If the test is not significant, you do not have enough evidence to claim an association in the sample. That does not prove the variables are truly unrelated in every setting.

Common Mistakes

  • Using percentages instead of counts.
  • Applying the test when the same person appears in multiple cells.
  • Ignoring very small expected counts.
  • Claiming causation from an observational table.

Short Summary

The chi-square test of independence is a practical tool for studying relationships between categorical variables. If your data are organized as counts in a contingency table and the assumptions are reasonable, this test gives a clear starting point for deciding whether an observed pattern is likely to reflect a real association.