Test whether two categorical variables are related using a table of counts, or whether observed counts fit expected proportions, with the chi-square statistic, p-value and expected counts.
χ² = Σ (observed − expected)² ÷ expected
Each line is a row of the table, such as an age group; each column is a category, such as drink choice.
A chi-square test compares the counts you observed with the counts you'd expect if nothing interesting were going on. The bigger the gaps, the bigger χ², and the less plausible the "nothing going on" explanation.
The test of independence asks whether two categorical variables are linked, such as age group and drink choice. If they're unrelated, each row should split across the columns in the same proportions as the overall totals.
The goodness-of-fit test asks whether one set of counts matches a claimed pattern, such as a die landing on each face equally often, or customers spreading across days in the proportions a model predicts.
As given in OpenStax Introductory Statistics, sections 11.2 and 11.3. See Sources.
Just short of significance at 5%. Younger people leaned towards coffee in this sample, but 200 people aren't quite enough to rule out chance. Cramér's V of 0.17 marks the link as weak anyway.
60 rolls of a die. A fair die expects 10 of each face.
| Face | Observed | Expected | (O − E)² ÷ E |
|---|---|---|---|
| 1 | 8 | 10 | 0.4 |
| 2 | 9 | 10 | 0.1 |
| 3 | 12 | 10 | 0.4 |
| 4 | 11 | 10 | 0.1 |
| 5 | 6 | 10 | 1.6 |
| 6 | 14 | 10 | 1.6 |
χ²(5) = 4.2, p = 0.521: no evidence the die is unfair, despite one face coming up more than twice as often as another.
Not much without the degrees of freedom. A χ² of 6 is significant with 2 df but not with 10. The p-value puts it in context.
A measure of association from 0 (none) to 1 (perfect). Roughly, 0.1 is weak, 0.3 moderate and 0.5 strong.
Some textbooks apply it to 2 × 2 tables. It makes the test more conservative; Fisher’s exact test is a better choice when counts are small.
Yes, in goodness-of-fit mode. Enter them as 25, 25, 50 or 1, 1, 2; they’re rescaled to the total.
No, only an association. Something else, such as income, could drive both variables.
Any size with at least 2 rows and 2 columns. Larger tables need more data to keep expected counts above 5.
=CHISQ.TEST(observed_range, expected_range) gives the p-value; you need to build the expected table yourself.
Chi-square uses an approximation that works with decent counts. Fisher’s test is exact for 2 × 2 tables and better for small samples.
Related Tools