Chi-square Test of Independence

Statistics
Introduced by
Karl Pearson
Year
1900
Type
Nonparametric test of association

What does it do?

The chi-square test of independence is a nonparametric hypothesis test that examines whether two categorical variables are associated by comparing observed and expected frequencies in a cross-tabulation.

It rests on the chi-square criterion introduced by Karl Pearson in 1900.

The intuition behind the method

Suppose you have counts cross-classified by two categorical variables — for example treatment group by outcome category — and you want to know whether the two are related or merely vary by chance. The test works out how many cases you would expect in each cell if the variables were truly independent, then measures how far the observed counts stray from those expectations; large discrepancies signal a real association.

History

Karl Pearson set out the chi-square criterion in a 1900 paper in the Philosophical Magazine (Pearson, 1900), which is the standard reference for the criterion. The test of independence for contingency tables is built on this criterion. When the large-sample approximation is doubtful, Fisher's exact test is the usual alternative.

When to use it

Use the test when two categorical variables are cross-classified in a contingency table and the question is whether they are associated, for example treatment group against outcome category. It assumes that observations are independent and that each case contributes to exactly one cell. The chi-square approximation is commonly considered adequate when every cell's expected frequency is at least 5. This rule is conservative, and some authors tolerate a small share of cells below 5 when no expected count is very small. If expected counts are clearly low, or the total sample is small, Fisher's exact test is the more appropriate choice. Do not use the test for paired or repeated measurements of the same subjects, where McNemar's test applies. To describe how strongly two variables are related, report an effect size such as Cramér's V alongside the result.

Limitations and considerations

  • The p-value relies on a chi-square approximation to the statistic's sampling distribution, which becomes unreliable when expected cell frequencies are small (below 5).
  • A significant result shows that the variables are associated but not the direction or pattern of that association; standardized residuals are needed for that.
  • The statistic grows with sample size, so very large samples can make trivial associations significant.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • It works directly on frequency counts and does not require the variables to be normally distributed.
  • It is simple to compute from observed and expected counts and is available in most statistics software.
  • The same formula extends from a 2x2 table to any r-by-c cross-tabulation, with degrees of freedom (r − 1)(c − 1).

Applications

  • Testing whether a treatment group and an outcome category are related in clinical or experimental research.
  • Examining association between demographic categories (e.g. region, gender) and a survey response.
  • Checking whether product choice depends on a customer segment in market research.
  • Assessing whether an observed distribution of categories departs from independence in social science surveys.

How it works

How it works

1

The null hypothesis states that the two categorical variables are independent: knowing one tells you nothing about the other. The alternative states that they are associated. The test decides between these two claims.

Formula
H_0:\ \text{the two variables are independent} \quad H_1:\ \text{they are associated}
2

Under independence, the expected count in each cell is the product of its row and column totals divided by the grand total. The chi-square statistic sums the squared gap between observed and expected counts, each scaled by its expected count, across all cells of the r-by-c table. Larger systematic deviations push the statistic higher. It is compared against the chi-square distribution with (r − 1)(c − 1) degrees of freedom; the rejection region contains values above the 1 − α percentile of that distribution.

Formula
\chi^2 = \sum_{i=1}^{r}\sum_{j=1}^{c} \dfrac{(O_{ij} - E_{ij})^2}{E_{ij}}, \quad E_{ij} = \dfrac{R_i\, C_j}{N}
3

If the p-value falls below the chosen significance level (conventionally 0.05) the null hypothesis of independence is rejected, indicating that the variables are associated. Because the statistic grows with sample size, pair the verdict with an effect size such as Cramér's V. Cramér's V has no universal interpretation thresholds; judge its size in the context of the field and the dimensions of the table. To see which cells drive the association, inspect the cell residuals; the adjusted (standardized) residual is (O − E) / sqrt(E (1 − R_i/N)(1 − C_j/N)), and absolute values above about 2 are commonly used as a rule of thumb to flag cells for closer inspection.

Formula
\text{reject } H_0 \text{ if } p < \alpha \ (\text{e.g. } 0.05); \quad V = \sqrt{\dfrac{\chi^2}{N\,(\min(r,c)-1)}}

Common pitfalls

  • Ignoring low expected frequencies — switch to Fisher's exact test when any cell expects fewer than 5.
  • Reporting only the p-value without an effect size such as Cramér's V.
  • Applying the test to dependent or repeated observations, where McNemar's test is appropriate instead.
  • Reading a significant overall result as identifying which categories differ, without checking the standardized residuals of individual cells.

Frequently asked questions

What if some expected cell counts are below 5?

The chi-square approximation becomes unreliable when expected frequencies are small. A common rule of thumb asks for expected counts of at least 5 in every cell, though some authors allow a small share of cells below 5. If the condition clearly fails, or the total sample is small, use Fisher's exact test, which computes the exact probability rather than relying on the asymptotic chi-square distribution.

Does a significant result tell me how strong the association is?

No. The chi-square statistic increases with sample size, so significance alone does not measure strength. Report an effect size such as Cramér's V. It has no universal thresholds for weak or strong, so interpret it in the context of your field and the size of the table.

Which cells are driving the result?

A significant overall test does not say where the association lies. Adjusted (standardized) residuals show which individual cells deviate most from their expected counts; absolute values above about 2 are a common rule of thumb for flagging them.

How is it different from McNemar's test?

The chi-square test of independence assumes the observations are independent. When the data are paired or matched, such as the same subjects measured before and after, McNemar's test is the correct choice instead.

Related methods

Sources

  1. Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine, 50(302), 157–175.

    Open DOI reference
  2. Agresti, A. (2007). An Introduction to Categorical Data Analysis (2nd ed.). Wiley.

    ISBN: 978-0471226185