- Introduced by
- Karl Pearson
- Year
- 1900
- Type
- Nonparametric association / goodness-of-fit
What does it do?
The chi-square test of independence is a nonparametric hypothesis test that asks whether two categorical variables are associated in a contingency table.
The chi-square criterion on which it rests was introduced by Karl Pearson in 1900. The test requires independent observations and sufficiently large expected cell frequencies, but it does not assume normally distributed data.
The intuition behind the method
Imagine you survey patients and record both their smoking status and whether they developed a disease. If smoking and disease were completely unrelated, the proportion of smokers among the sick should match the proportion among the healthy. The chi-square test formalises this intuition: it measures how far the observed cell counts in a cross-tabulation deviate from the counts you would expect if the two variables were truly independent, then asks whether those deviations are larger than chance alone can explain.
History
Karl Pearson introduced the chi-square criterion in a 1900 paper in the Philosophical Magazine, and the statistic it defines underlies the test described here.
When to use it
Use the chi-square test of independence when you want to know whether two categorical variables are associated and each observation is independent, meaning each participant contributes to exactly one cell. Before interpreting the result, check that all expected cell frequencies are at least 5, the conventional rule of thumb for the adequacy of the chi-square approximation. If expected frequencies fall below 5, which can happen in small samples or sparse tables, Fisher's Exact Test is the alternative this page recommends. For a 2 × 2 table, Yates' continuity correction is sometimes applied when expected counts are small; the result then depends on whether the correction is used, so state which version was reported. Fisher's Exact Test is also the usual alternative for 2 × 2 tables with small expected counts. Do not use this test for paired or matched designs, where the observations are not independent and McNemar's test applies. The chi-square statistic also appears in a goodness-of-fit form, which compares the observed counts of one variable with the counts expected under a hypothesised distribution. That form is referred to a chi-square distribution with its own degrees of freedom, which depend on the number of classes and on any parameters estimated from the data, so the (r − 1)(c − 1) rule given above does not apply to it.
Limitations and considerations
- The requirement that expected cell frequencies be at least 5 is a hard condition. When it fails, the chi-square approximation is unreliable and an exact method is needed.
- The test indicates that an association exists, but not its direction or which cells drive it. Inspecting the cell-level deviations is needed for that.
- Cramér's V has no universal benchmark. The 0.10 and 0.30 cut-offs on this page are conventions, not properties of the test.
- The statistic grows with N, so very large samples can flag trivially small associations as statistically significant.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- It makes no normality assumption, because it operates on counts in a contingency table and so applies to nominal data with any number of categories.
- It applies to r × c tables, not only 2 × 2 tables.
- Cramér's V is computed from the same chi-square value and total N, so an effect size can be reported alongside the test without collecting additional data.
Applications
- Testing whether treatment group and clinical outcome are associated in medical and public-health research.
- Examining whether survey responses on Likert or nominal items differ across demographic groups.
- Quality control: checking whether defect categories are independent of production shift or machine.
- Social science: investigating whether voting preference is independent of educational attainment.
- Genetics: testing whether observed genotype frequencies conform to Hardy-Weinberg expectations (goodness-of-fit form).
How it works
How it works
The null hypothesis states that the two categorical variables are independent: knowing the value of one tells you nothing about the other. The alternative hypothesis states that they are associated. The test evaluates the evidence against independence across all cells of the contingency table.
Formula
H_0:\text{ the two categorical variables are independent} \quad H_1:\text{ they are associated}For each cell of the r × c table, the expected frequency is the product of its row total and column total divided by the grand total. The statistic sums the squared differences between observed and expected counts, each divided by the expected count. Under the null hypothesis, and when expected frequencies are adequate (a conventional rule of thumb is at least 5 per cell), it approximately follows a chi-square distribution with (r − 1)(c − 1) degrees of freedom.
Formula
\chi^2 = \sum_{i,j} \frac{(O_{ij} - E_{ij})^2}{E_{ij}}, \quad E_{ij} = \frac{R_i \cdot C_j}{N}If the p-value falls below 0.05 the null hypothesis is rejected, indicating a statistically significant association between the two variables. Because a significant p-value does not convey the strength of association, you should also report Cramér's V, a standardised effect-size measure that ranges from 0 (no association) to 1 (perfect association). Values below 0.10 are conventionally described as weak, 0.10 – 0.30 as moderate, and above 0.30 as strong. These cut-offs are conventions rather than properties of the test, and the appropriate reading of V depends on the dimensions of the table.
Formula
\text{reject } H_0 \text{ if } p < 0.05Common pitfalls
- Reporting a chi-square result for a table in which some expected counts are below 5, without noting the violation.
- Reporting only the p-value without Cramér's V or another measure of effect size.
- Applying the independence test to paired or matched data. The observations are not independent in that design, so McNemar's test is the appropriate choice.
- Reading a significant result as evidence of causation or of a specific pattern. The test rejects independence only; it does not establish why the variables are associated.
Frequently asked questions
What if some expected cell counts are less than 5?
The chi-square approximation becomes unreliable when expected frequencies fall below 5, the conventional rule of thumb used on this page. In that case use Fisher's Exact Test, which computes an exact p-value rather than relying on the large-sample chi-square approximation. Check the expected frequencies before interpreting the test, not after.
What is Cramér's V and how do I interpret it?
Cramér's V is a normalised measure of association derived from the chi-square statistic. It ranges from 0 to 1 regardless of table size: values below 0.10 are conventionally read as a weak association, 0.10 to 0.30 as moderate, and above 0.30 as strong. These cut-offs are conventions, and the reading of V should take the table dimensions into account. Always report it alongside the p-value so readers can judge practical significance.
Can I use the chi-square test for ordinal variables?
Technically yes — ordinal variables are categorical — but the chi-square test ignores the natural ordering of categories and therefore discards information. For two ordinal variables, Kendall's tau or Spearman's rho are more powerful because they exploit the order. Reserve the chi-square test for truly nominal categories.
How is this different from a goodness-of-fit chi-square test?
The test of independence compares two categorical variables in a contingency table to assess their association. The goodness-of-fit form compares a single variable's observed frequency distribution against a theoretically expected distribution (e.g., equal proportions or Hardy-Weinberg frequencies). Both use the chi-square statistic built from observed and expected counts, but they differ in purpose, in how the expected frequencies are derived, and in the degrees of freedom: the goodness-of-fit form does not use (r − 1)(c − 1).
Related methods
Sources
Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables. Philosophical Magazine, Series 5, 50(302), 157–175.
Open publication reference