Skip to content
Scintria
ToolsGrant writerFunding
HomeLiteratureClinical trialsEvidence LabProtocol packData analysisLearnProjectsLibraryReferencesApplications
Start free
ScintriaStart free

Learn / Biostatistics / Analysing categorical data

Chi-square and Fisher's exact tests

13 minute read · 6-question quiz

Download this lesson as a colour Word or PDF study guide with the figures and answers. Included in paid plans; reading and quizzes stay free.Sign in

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.

Expected counts and the test statistic

Expected count in a cell = ((row total) × (column total))/(N)

χ^2 = Σ ((O - E)^2)/(E), df = (rows - 1)(columns - 1)

For a 2×2 table, a quick form is χ^2 = (N(ad - bc)^2)/((a+b)(c+d)(a+c)(b+d)).

Worked example

Table: a = 40, b = 160, c = 20, d = 280, N = 500.

CellObservedExpected
Exposed, pneumonia4024
Exposed, none160176
Unexposed, pneumonia2036
Unexposed, none280264

χ^2 = (16^2)/(24) + (16^2)/(176) + (16^2)/(36) + (16^2)/(264) = 10.67 + 1.45 + 7.11 + 0.97 = 20.2

With 1 df, the critical value for p = 0.05 is 3.84. Our 20.2 is far larger: p < 0.0001. Conclude strong evidence of an association, then report the RR with its CI (3.0, 1.8 to 5.0), not just p.

010203040Children with pneumonia40Exposed: observed24Exposed: expected20Unexposed: observed36Unexposed: expected
Observed against expected pneumonia cases if smoke were unrelated to illness.

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.

Small sample: exact versus approximate

A pilot: 8 of 10 children given a new regimen are cured, compared with 3 of 10 given standard care. OR = 9.3.

  • Pearson chi-square gives p = 0.025.
  • Fisher's exact test gives p = 0.070.

The expected counts here are 5.5, right at the edge of the rule of thumb, and the two tests disagree about significance. In small studies report the exact result; and note the CI for the OR is very wide (roughly 1.2 to 73), so the pilot suggests a benefit but cannot confirm one.

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.

Do not run chi-square on percentages or on repeated outcomes

Use the raw counts. Also never apply it where the same person contributes more than one observation (e.g. several episodes of malaria per child): use a method that respects clusters.

A significant chi-square says nothing about size

With 50,000 participants, an increase from 10.0% to 10.7% can be 'highly significant'. Decide whether the difference matters before celebrating the p-value.

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

Question 1
1

The degrees of freedom for a 3×4 contingency table are:

Question 2
2

Which situation calls for Fisher's exact test?

Question 3
3

The expected count in a cell with row total 200, column total 60 and N = 500 is:

Question 4
4

Two diagnostic tests are applied to the same 100 patients. The right test of whether positivity rates differ is:

Question 5
5

A chi-square statistic of 20.2 on 1 df means:

Question 6
6

The test for trend is preferred over a general chi-square when:

Draft study guide. Spotted an error or something unclear? Tell us at hello@scintria.com. This is educational material, not clinical or regulatory advice.

Risk, odds and the measures of associationConfounding, stratification and the Mantel-Haenszel estimate