Chi-Square Test

Testing association between categorical variables

Back

Idea

The chi-square test compares observed counts to expected counts under independence.

χ² = Σ ( (O − E)² / E ) , df = (r−1)(c−1)

Rule-of-thumb: expected counts should usually be ≥ 5 in most cells; otherwise consider Fisher's exact test for 2×2 tables.

Interactive 2×2 chi-square (teaching demo)

Enter a 2×2 table (e.g., treatment vs outcome) and see observed vs expected.

Outcome +
Outcome −
Treatment
Control
χ²: -
df: 1
Note: This demo doesn't compute exact p-values. In real work, use software to get p.

Observed vs expected

Big gaps between observed and expected contribute to χ².

Real Dental Scenario

Is Smoking Associated with Periodontal Disease?

The study: A periodontist examined 300 patients and recorded their smoking status and whether they had periodontal disease. Is there an association between smoking and periodontal disease?

Observed Data (Contingency Table)

Periodontal Disease (Yes) Periodontal Disease (No) Row Total
Smoker 45 30 75
Non-Smoker 55 170 225
Column Total 100 200 300
1

Step 1: Calculate Expected Values

E = (Row Total × Column Total) / Grand Total

E(Smoker, Disease):
(75 × 100) / 300 = 25.00
E(Smoker, No Disease):
(75 × 200) / 300 = 50.00
E(Non-Smoker, Disease):
(225 × 100) / 300 = 75.00
E(Non-Smoker, No Disease):
(225 × 200) / 300 = 150.00
2

Step 2: Compute (O − E)² / E for Each Cell

Cell (Smoker, Disease):
(45 − 25)² / 25 = 400/25 = 16.000
Cell (Smoker, No Disease):
(30 − 50)² / 50 = 400/50 = 8.000
Cell (Non-Smoker, Disease):
(55 − 75)² / 75 = 400/75 = 5.333
Cell (Non-Smoker, No Disease):
(170 − 150)² / 150 = 400/150 = 2.667
3

Step 3: Sum & Make a Decision

χ² = 16.000 + 8.000 + 5.333 + 2.667 = 32.000
df = (2−1)(2−1) = 1
Critical value (α = 0.05, df = 1): χ²crit = 3.841
Our χ² = 32.000 >> 3.841
p-value < 0.0001

Significant Association Found!

χ²(1) = 32.00, p < 0.0001

There is a highly significant association between smoking status and periodontal disease. Smokers are substantially more likely to have periodontal disease than non-smokers (60% vs 24.4%).

60%
Smokers with disease
(45 / 75)
24.4%
Non-smokers with disease
(55 / 225)

Dental use

Use chi-square for associations like "smoker vs non-smoker" and "periodontitis yes/no," or "device positive/negative" across groups. Always report the table, effect size (e.g., risk ratio/odds ratio), and CI if possible.