Learn / Biostatistics / Analysing categorical data
Chi-square and Fisher's exact tests
13 minute read · 6-question quiz
What you will learn
Carry out and interpret the chi-square test of association
Calculate expected counts and decide whether the test is valid
Use Fisher's exact test, and test for trend across ordered groups
Does the association we saw in the two-by-two table reflect real association or chance? The chi-square (χ²) test compares the observed counts with the counts we would expect if exposure and outcome were unrelated.
The idea
If smoke exposure made no difference, the pneumonia rate would be the same in both groups: 60 cases among 500 children = 12%. So we would expect 12% of the 200 exposed children (24 cases) and 12% of the 300 unexposed (36 cases). The test measures how far observed counts depart from these.
When chi-square is not reliable
The chi-square statistic is an approximation. It works well when all expected counts are at least 5 (some say 80% of cells at least 5 and none below 1). With small samples it can give p-values that are too small.
Fisher's exact test calculates the exact probability of the observed table and tables more extreme, given fixed row and column totals. It is valid for any sample size and is the safe choice for small tables.
Larger tables and ordered categories
For tables with more than two rows or columns, the chi-square test still applies with df = (r - 1)(c - 1), but a significant result only says 'somewhere there is an association'. Inspect the standardised residuals or collapse sensibly.
If one variable is ordered (dose level, WHO stage, age group), use the chi-square test for trend (Cochran-Armitage), which looks for a steadily rising or falling proportion and is more powerful than the general test.
Paired binary data: McNemar
When the same patients are tested twice (two diagnostic tests on each person), use McNemar's test on the discordant pairs only. Ordinary chi-square wrongly treats the paired results as independent.
Summary
Chi-square compares observed with expected counts under independence: Σ(O − E)²/E.
df = (rows − 1) × (columns − 1); 2×2 tables have 1 df and a 5% critical value of 3.84.
Check expected counts ≥ 5; otherwise use Fisher's exact test.
Use trend tests for ordered categories and McNemar for paired binary data.
Always follow a significant test with an effect measure and CI.
Check your understanding
Draft study guide. Spotted an error or something unclear? Tell us at hello@scintria.com. This is educational material, not clinical or regulatory advice.