Section 2.7

Chi-Square Tests

Everything so far has compared means of numeric data. But what about counts: how many people picked option A vs. B, recovered vs. didn't, voted left vs. right? The chi-square (χ²) test works with frequencies in categories, and its most common job is asking: are two categorical variables associated, or independent?

Observed vs. expected

The whole test rests on one comparison. You have the observed counts (what actually happened). Then you compute the expected counts: what you'd see if the two variables were completely unrelated (each cell's expected count is just its row total × column total ÷ grand total). The bigger the gap between observed and expected, the more evidence of a real association:

χ² = Σ (observed − expected)² / expected

That formula, the expected-count rule, the df and Cramér's V are four consecutive rows on the printable formula sheet, worth having beside you the first few times.

🎮 Contingency Table Explorer

A treatment trial. Each bar shows the recovery split for one group. When the two splits match the dashed "no-association" line, χ² is tiny. Pull them apart and watch χ² climb.

χ² statistic
Degrees of freedom1
p-value
Association?

Reading the result

The degrees of freedom for a table are (rows − 1) × (columns − 1) — just 1 for our 2×2. A χ² statistic far from zero, with p < 0.05, means the observed counts would be surprising if the variables were truly independent — so you conclude they're associated. In the trial: treatment and recovery are related.

Association, not amount. Like correlation, a significant χ² tells you a relationship exists, not how strong it is. For strength, report an effect size such as Cramér's V or the odds ratio alongside the test; the effect-size converter will turn an odds ratio into the more familiar d or r if you need to compare it with the rest of your results.

Two flavors of chi-square

  • Test of independence is the one above: are two categorical variables related? (Treatment × outcome, gender × preference.)
  • Goodness-of-fit: does one categorical variable match an expected distribution? (Is this die fair? Do customers pick the four flavors equally?)

What you're assuming

  • Counts are independent — each observation falls in exactly one cell, and one person's category doesn't affect another's.
  • Expected counts are large enough — a common rule is every expected count ≥ 5. For small 2×2 tables, use Yates' continuity correction or Fisher's exact test instead. Counts are cheap to collect and easy to under-collect, so if the study is still ahead of you, the power calculator will tell you how many observations a given association needs.

Why it matters: survey responses, A/B test conversions, medical outcomes, demographic breakdowns — categorical data is everywhere, and chi-square is the workhorse for testing whether the categories hang together. Its neighbors in the association family, and when each one applies, sit in the third panel of the printable test-chooser poster.

Problem 19 in the practice problems works a 2 × 3 table from expected counts through to Cramér's V, and shows how to find the cell that is doing the damage.

Common questions

My chi-square is significant. Which cell is responsible?

The test itself will not tell you, because it pools every cell into one number. Ask the table for adjusted standardized residuals, which SPSS offers under Crosstabs → Cells and R returns as chisq.test(tab)$stdres. Each one is roughly a z-score for its cell under independence, so a value beyond about ±2 marks a cell holding noticeably more or fewer cases than independence predicts, and the sign tells you which direction. Read the pattern before you write the sentence: a significant χ² on a 3 × 4 table usually comes from one or two cells, not from the whole table drifting at once. With many cells, treat the residuals as exploratory rather than as a stack of formal tests.

What if my expected counts are less than 5?

The χ² p-value is an approximation that degrades with small expected counts. The standard rule: all (or at least 80% of) expected counts should be ≥ 5. Below that, use Fisher's exact test for 2×2 tables (exact, no approximation) — or collapse sparse categories together when it makes conceptual sense.

Can a chi-square test tell me how strong the association is?

χ² itself can't; it grows with sample size, so a huge study can produce an enormous χ² from a trivial association. Pair the test with an effect size: Cramér's V (0 = none, 1 = perfect) for general tables, or the odds ratio for 2×2 tables, which our effect-size converter can translate into other metrics.