Durgical
EN
Open the app

Chi-square test

  • Statistical test

It compares proportions between groups by measuring how far the observed counts are from those expected if there were no association.

Updated

What it is

The chi-square (χ²) test of independence assesses whether two categorical variables are associated in a contingency table, for example exposure (yes/no) and disease (yes/no). For each cell it calculates the count expected if there were no association and adds up the squared differences between observed and expected, divided by expected. With small expected counts it becomes unreliable and the Fisher exact test is used.

When to use it

  • Proportions in two or more independent groups (r × c table).
  • Goodness of fit: whether an observed distribution matches an expected one.
  • Fisher exact test: 2 × 2 tables with any expected count below 5.

Worked example

  1. Data: after a lunch, of 50 people who ate the salad 30 fell ill; of 50 who did not, 10 fell ill.
  2. Totals: 40 ill and 60 well out of 100 people.
  3. Expected per row: ill = 50 × 40 / 100 = 20; well = 50 × 60 / 100 = 30 (the same in both rows).
  4. Ate: (30 − 20)² / 20 = 5.0 and (20 − 30)² / 30 = 3.33.
  5. Did not eat: (10 − 20)² / 20 = 5.0 and (40 − 30)² / 30 = 3.33.
  6. χ² = 5.0 + 3.33 + 5.0 + 3.33 = 16.7 with 1 df. It exceeds 3.84; p < 0.001.
  7. Attack rate: 60% in those who ate versus 20% in those who did not; RR = 0.60 / 0.20 = 3.0.
  8. Reading: illness was clearly associated with the salad; χ² gives the significance and the RR gives the size.

The example’s 2 × 2 table (observed and, in brackets, expected)

ExposureIllWellTotal
Ate the salad30 (20)20 (30)50
Did not eat it10 (20)40 (30)50
Total4060100

Markers

  • χ²
  • df
  • Fisher

Assumptions and pitfalls

  • Using it with expected counts below 5 (use Fisher).
  • Using it on paired data (use McNemar).
  • Calculating it from percentages instead of absolute counts.
  • Reading a large χ² as a strong association: it also grows with sample size.

Test yourself

Think of the answer, then tap the question to see it.

How is the expected count of a cell calculated?

Multiply its row total by its column total and divide by the grand total.

How many degrees of freedom does a 3 × 4 table have?

(3 − 1) × (4 − 1) = 6.

When is the Fisher exact test preferred?

When any expected count in a 2 × 2 table is below 5.

What limits χ² as a measure of the strength of an association?

Its value grows with sample size; strength is reported with the RR or OR and its confidence interval.

Add to my cards (4)

Connections

← All of epidemiology

Educational content on epidemiological and statistical methods; the examples use made-up numbers to teach the calculation. Not a clinical or legal guide: current Colombian rules are in the official sources.

Sources: How can we compare the results of classifying according to several categories? (NIST/SEMATECH e-Handbook of Statistical Methods, National Institute of Standards and Technology, 2012); Principles of Epidemiology | Lesson 3 - Section 5 (Centers for Disease Control and Prevention, 2012); What are statistical tests? (NIST/SEMATECH e-Handbook of Statistical Methods, National Institute of Standards and Technology, 2012).

Spotted a mistake?We are always improving for the community. Tell us what is wrong and our team will review it.Report a mistake

Representative model, for educational purposes only.