Chi-Square Test of Independence

What Is the Chi-Square Test of Independence?

The Chi-Square test of independence is a statistical method used to determine whether two categorical variables are related to each other. Categorical variables are those that place people or things into groups or categories rather than measuring them on a numerical scale. Examples include gender (male, female, non-binary), political affiliation (Democrat, Republican, Independent), or preferred mode of transport (car, bus, bicycle).

Imagine a sociologist who surveys 400 people and records both their age group (under 30, 30–50, over 50) and their preferred news source (television, online, print). She wants to know: is there a relationship between age group and news preference, or are the two variables independent of each other? The Chi-Square test of independence is designed to answer exactly this kind of question.

Contingency Tables

The data for a Chi-Square test of independence is organized in a contingency table (also called a cross-tabulation). This is a grid where the rows represent the categories of one variable and the columns represent the categories of the other. Each cell in the table contains the count of observations that fall into that particular combination of categories.

In the news example, the contingency table would have three rows (one for each age group) and three columns (one for each news source), creating nine cells. Each cell shows how many people in a given age group prefer a given news source. The totals along the edges of the table — called marginal totals — play an important role in the calculation.

Observed vs. Expected Frequencies

The test works by comparing two sets of numbers: the observed frequencies (the actual counts you collected) and the expected frequencies (the counts you would expect to see if the two variables were completely independent of each other).

Expected frequencies are calculated using the marginal totals. For any cell, the expected frequency equals the row total multiplied by the column total, divided by the grand total (the overall number of observations). The logic is simple: if age and news preference were unrelated, knowing someone’s age group should not help you predict their news preference. The expected frequencies represent that scenario of no relationship.

The Chi-Square statistic measures how far the observed frequencies deviate from the expected frequencies. For each cell, you take the difference between observed and expected, square it, and divide by the expected frequency. Then you add up these values across all cells. A larger Chi-Square statistic indicates a greater discrepancy between what was observed and what would be expected under independence.

Degrees of Freedom and the P-Value

To interpret the Chi-Square statistic, you need the degrees of freedom, which depend on the size of your contingency table. The formula is straightforward: (number of rows minus 1) multiplied by (number of columns minus 1). For the 3 × 3 news example, the degrees of freedom would be (3 − 1) × (3 − 1) = 4.

The Chi-Square statistic and the degrees of freedom together allow you to find a p-value. The p-value tells you the probability of obtaining a Chi-Square statistic at least as large as the one you calculated, assuming the two variables really are independent. A small p-value (typically less than 0.05) leads you to reject the null hypothesis of independence and conclude that the two variables are related.

Key Assumptions

The Chi-Square test of independence requires several conditions to produce reliable results:

  • Categorical data — Both variables must be categorical. The test does not work with continuous measurements.
  • Independence of observations — Each observation should contribute to only one cell in the contingency table. The same individual should not be counted twice.
  • Sufficient expected cell counts — A common rule of thumb is that all expected frequencies should be 5 or greater. When expected counts are too small, the Chi-Square approximation becomes unreliable. If you have small expected counts, Fisher’s exact test is a common alternative for 2 × 2 tables.
  • Random sampling — The data should come from a random sample of the population so the results can be generalized.

What the Result Does and Does Not Tell You

A significant Chi-Square result tells you that the two variables are associated — they are not independent. However, it does not tell you the strength of that association or which specific categories are driving the relationship. For measures of strength, you can look at statistics such as Cramér’s V. To identify which cells contribute most to the result, you can examine the standardized residuals for each cell.

It is also important to remember that association does not mean causation. Even if age group and news preference are significantly related, the test cannot tell you that age causes people to prefer certain news sources. Other factors may be involved.