Chi-Square Test Categorical Data Nonparametric 32 min read July 27, 2026
BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)

Chi-Square Test Examples: Step-by-Step Worked Problems & Real-Life Applications

A hospital checks whether blood type distribution matches national data. A market researcher asks whether gender affects product preference. A biologist tests whether pea flower colors follow Mendel's predicted 3:1 ratio. Each scenario calls for the same tool: a chi-square test. This guide walks through 10 fully solved examples, covering goodness-of-fit problems, tests of independence, and real-world case studies across healthcare, education, marketing, and biology.

Every example includes the problem statement, contingency table (where applicable), expected frequency calculation, chi-square statistic, p-value, degrees of freedom, decision, and a plain-English conclusion. The interactive calculator lets you run both test types directly.

What You'll Learn
  • ✓ The chi-square formula and when each type of test applies
  • ✓ How to calculate expected frequencies for goodness-of-fit and independence tests
  • ✓ 10 fully worked examples across education, healthcare, marketing, biology, and business
  • ✓ How to read the chi-square table and find critical values
  • ✓ Effect size: Cramér's V and Phi coefficient
  • ✓ When to use Fisher's exact test or McNemar's test instead
  • ✓ Common mistakes and how to avoid them

What Is a Chi-Square Test?

Definition — Chi-Square Test
A chi-square test (χ²) is a nonparametric statistical test that compares observed frequencies of categorical data to expected frequencies. If the difference between observed and expected counts is large enough relative to what chance alone would produce, the test reports a statistically significant result.
χ² = Σ [(O − E)² / E]

Where O = observed frequency and E = expected frequency for each category or cell.

Karl Pearson introduced this test in 1900, making it one of the oldest and most widely used procedures in statistics. Unlike t-tests or ANOVA, the chi-square test does not require numerical data — it works entirely with counts. That makes it the default choice whenever a research question involves categorical variables such as gender, preference, color, diagnosis, or political affiliation.

The test produces a single number, χ², that grows when the gap between what you observed and what you expected is large. You then compare that number to a critical value from the chi-square distribution table — or find its p-value directly. A large χ² means the data is unlikely under the null hypothesis.

2
Types of chi-square tests
(r−1)(c−1)
Degrees of freedom formula for independence
≥ 5
Minimum expected frequency per cell
0.05
Standard significance level (α)

Two Types of Chi-Square Tests

The two most common variants answer fundamentally different questions. Choosing the wrong one is one of the most frequent mistakes beginners make.

Feature Goodness-of-Fit Test Test of Independence
Research questionDoes one variable follow a specified distribution?Are two categorical variables associated?
Number of variablesOneTwo
Data layoutSingle frequency columnContingency table (rows × columns)
Degrees of freedomk − 1 (k = categories)(r − 1)(c − 1)
Expected frequency formulaE = n × piE = (row total × col total) / n
Typical exampleDoes a die produce equal outcomes?Does gender affect voting preference?

A third variant, the chi-square test of homogeneity, asks whether the distribution of a categorical variable is the same across multiple populations. The formula is identical to the test of independence, but the study design differs — you sample from each group separately instead of drawing one sample and cross-classifying it.

Chi-Square Formula Explained

Chi-Square Test Statistic
χ² = Σ [ (O − E)² / E ]
χ² = chi-square statistic O = observed frequency E = expected frequency Σ = sum across all categories or cells

The logic is straightforward. You square the difference (O − E) to make all terms positive. Dividing by E scales each term relative to how large the expected count is — a 10-unit gap matters more in a cell where you expected 12 than in one where you expected 400. Summing across all categories or cells gives the overall test statistic.

For a goodness-of-fit test, E = n × pi, where pi is the hypothesized proportion for category i and n is the total sample size. For a test of independence, each cell's expected frequency is:

Expected Frequency — Test of Independence
E = (Row Total × Column Total) / Grand Total

Degrees of freedom determine which chi-square distribution to use. For goodness-of-fit: df = k − 1. For the test of independence: df = (number of rows − 1) × (number of columns − 1). You can look up the critical value in the chi-square critical value table.

Assumptions of the Chi-Square Test

The chi-square approximation is only valid when four conditions are met. Violating them can lead to misleading results.

1

Categorical Data

Both variables must be nominal or ordinal categories — not continuous measurements. Hair color, blood type, and political party are valid; height and income are not.

2

Independent Observations

Each subject or observation must appear in exactly one cell. The test cannot handle repeated measures or matched pairs — use McNemar's test instead.

3

Expected Frequencies ≥ 5

Each expected cell count must be at least 5 (some sources say at least 1, with no more than 20% below 5). When this fails, use Fisher's exact test.

4

Adequate Sample Size

The chi-square statistic is an approximation that improves with larger n. Small samples — especially under 20 — should trigger consideration of exact methods.

⚠️
Small Expected Frequencies

If any expected cell frequency falls below 5, the chi-square approximation becomes unreliable. Consider merging categories or switching to Fisher's exact test, which is available in R (fisher.test()), Python (scipy.stats.fisher_exact()), and SPSS.

6-Step Procedure for Every Chi-Square Test

Every chi-square test follows the same structure, regardless of whether it is a goodness-of-fit test or a test of independence. Memorize this process and you can handle any categorical data problem.

1

State the Hypotheses

H₀ (null): The data fits the expected distribution, OR the two variables are independent. H₁ (alternative): The data does not fit, OR the variables are associated. The chi-square test is always right-tailed — a large χ² contradicts H₀.

2

Set the Significance Level (α)

Choose α = 0.05 for most research (or 0.01 for stricter standards). This is the maximum acceptable probability of a Type I error — rejecting a true H₀. See the guide on significance level for details.

3

Calculate the Degrees of Freedom

Goodness-of-fit: df = k − 1 (k = number of categories). Independence: df = (r − 1)(c − 1) (r = rows, c = columns). Find the critical value χ²* from the chi-square table at your chosen α and df.

4

Calculate Expected Frequencies

Goodness-of-fit: Ei = n × pi. Independence: Eij = (Ri × Cj) / n. Verify all E values are ≥ 5 before proceeding.

5

Calculate the Chi-Square Statistic

Apply χ² = Σ [(O − E)² / E] across all categories or cells. This single number summarizes how far the observed data sits from the expected pattern under H₀.

6

Make a Decision and State the Conclusion

If χ² > χ²* (or equivalently, p < α): Reject H₀. If χ² ≤ χ²* (or p ≥ α): Fail to Reject H₀. Always state the conclusion in the context of the original research question, not just the statistical jargon.

Goodness-of-Fit Examples

A goodness-of-fit chi-square test answers: "Does this one categorical variable follow the distribution I expect?" The expected frequencies are based on a theory, a known population, or a uniform assumption.

Example 1 — Fairness of a Six-Sided Die

Worked Example 1 — Goodness-of-Fit

Problem: A game designer suspects a six-sided die is biased. Rolling it 120 times produces the counts below. Test at α = 0.05 whether the die is fair.

Face123456Total
Observed (O)251715232416120
Expected (E)202020202020120
Expected Frequency — Uniform Distribution
E = n / k = 120 / 6 = 20
n = 120 total rolls k = 6 faces df = k − 1 = 5
1

Hypotheses: H₀: The die is fair (each face has probability 1/6)  |  H₁: At least one face has a different probability

2

α = 0.05. df = 6 − 1 = 5. From the chi-square table: χ²* = 11.070

3

Expected frequencies: All E = 120/6 = 20. All ≥ 5 ✓

4

Chi-square statistic:
χ² = (25−20)²/20 + (17−20)²/20 + (15−20)²/20 + (23−20)²/20 + (24−20)²/20 + (16−20)²/20
= 25/20 + 9/20 + 25/20 + 9/20 + 16/20 + 16/20
= 1.25 + 0.45 + 1.25 + 0.45 + 0.80 + 0.80 = 5.00

5

p-value: For χ² = 5.00 with df = 5: p ≈ 0.416

6

Decision: χ² = 5.00 < χ²* = 11.070, and p = 0.416 > 0.05 → Fail to Reject H₀

❌ Conclusion: There is insufficient evidence (χ² = 5.00, p = 0.416) to conclude the die is biased. The observed deviations from 20 per face are consistent with normal random variation.

Example 2 — Mendel's Genetics (3:1 Ratio)

Worked Example 2 — Goodness-of-Fit

Problem: A genetics experiment crosses two heterozygous pea plants. Mendel's law predicts a 3:1 ratio of purple to white flowers. Of 400 offspring, 290 are purple and 110 are white. Test at α = 0.05 whether the observed ratio fits the predicted 3:1.

Flower ColorObserved (O)Expected (E)(O−E)²/E
Purple2903000.333
White1101001.000
Total400400χ² = 1.333
1

Hypotheses: H₀: Offspring follow a 3:1 ratio (p₁ = 0.75, p₂ = 0.25)  |  H₁: They do not follow a 3:1 ratio

2

α = 0.05. df = 2 − 1 = 1. Critical value: χ²* = 3.841

3

Expected frequencies: E(Purple) = 400 × 0.75 = 300. E(White) = 400 × 0.25 = 100. Both ≥ 5 ✓

4

Chi-square statistic:
χ² = (290−300)²/300 + (110−100)²/100
= 100/300 + 100/100
= 0.333 + 1.000 = 1.333

5

p-value: For χ² = 1.333 with df = 1: p ≈ 0.248

6

Decision: χ² = 1.333 < 3.841, and p = 0.248 > 0.05 → Fail to Reject H₀

❌ Conclusion: The data is consistent with Mendel's predicted 3:1 ratio (χ² = 1.333, p = 0.248). The slight deviation — 290 observed vs 300 expected purple — is within the range of normal sampling variability.

Mendel's laws and chi-square application discussed in: Moore, D.S. (2007). The Basic Practice of Statistics (4th ed.). W.H. Freeman. Chi-square critical values verified against the NIST Engineering Statistics Handbook.

Example 3 — Commute Mode Distribution

Worked Example 3 — Goodness-of-Fit

Problem: A city planner has data from five years ago showing workers travel by: Car 60%, Transit 25%, Bike 10%, Walk 5%. A new survey of 500 workers finds: Car 285, Transit 130, Bike 60, Walk 25. Test at α = 0.01 whether commute patterns have changed.

ModeObservedExpected(O−E)²/E
Car2853000.750
Transit1301250.200
Bike60502.000
Walk25250.000
Total500500χ² = 2.950
1

Hypotheses: H₀: Current distribution matches historical proportions (60/25/10/5%)  |  H₁: At least one proportion has changed

2

α = 0.01. df = 4 − 1 = 3. Critical value: χ²* = 11.345

3

Expected frequencies: 500×0.60=300; 500×0.25=125; 500×0.10=50; 500×0.05=25. All ≥ 5 ✓

4

χ² = 0.75 + 0.20 + 2.00 + 0.00 = 2.950

5

p-value: p ≈ 0.399

6

Decision: χ² = 2.950 < 11.345 → Fail to Reject H₀

❌ Conclusion: The survey data does not provide sufficient evidence (χ² = 2.950, p = 0.399) that commute mode proportions have changed from five years ago. The slight uptick in bike use (12% vs 10%) is not statistically significant at α = 0.01.

Test of Independence Examples

A chi-square test of independence uses a contingency table to determine whether two categorical variables are statistically related or independent. A significant result means the variables are associated — knowing a subject's value on one variable tells you something about the other.

Example 4 — Gender and Brand Preference

Worked Example 4 — Test of Independence

Problem: A market researcher surveys 200 consumers to determine whether product preference (Brand A vs Brand B) is independent of gender. Test at α = 0.05.

Brand ABrand BRow Total
Male5545100
Female3565100
Column Total90110200
Expected Frequency — Each Cell
E = (Row Total × Column Total) / Grand Total
df = (2−1)(2−1) = 1 χ²* at α=0.05, df=1: 3.841
1

Hypotheses: H₀: Gender and brand preference are independent  |  H₁: They are associated

2

α = 0.05, df = 1, χ²* = 3.841

3

Expected frequencies:
E(Male, A) = (100×90)/200 = 45  |  E(Male, B) = (100×110)/200 = 55
E(Female, A) = (100×90)/200 = 45  |  E(Female, B) = (100×110)/200 = 55
All cells ≥ 5 ✓

4

Chi-square calculation:
χ² = (55−45)²/45 + (45−55)²/55 + (35−45)²/45 + (65−55)²/55
= 100/45 + 100/55 + 100/45 + 100/55
= 2.222 + 1.818 + 2.222 + 1.818 = 8.080

5

p-value: For χ² = 8.08 with df = 1: p ≈ 0.0045

6

Decision: χ² = 8.08 > 3.841, and p = 0.0045 < 0.05 → Reject H₀

✅ Conclusion: Gender and brand preference are statistically associated (χ² = 8.08, df = 1, p = 0.0045). Female respondents show a stronger preference for Brand B (65%) compared to males (45%).

Effect Size — Phi Coefficient (φ)

For 2×2 tables: φ = √(χ²/n) = √(8.08/200) = √0.0404 = 0.201. Cohen's convention: small = 0.10, medium = 0.30, large = 0.50. This association is small to medium in magnitude.

Example 5 — Smoking Status and Lung Disease

Worked Example 5 — Test of Independence

Problem: A public health study examines whether smoking status (Never, Former, Current) is associated with lung disease diagnosis (Yes/No) in a sample of 450 adults. Test at α = 0.05.

Lung Disease: YesLung Disease: NoRow Total
Never Smoked15185200
Former Smoker25125150
Current Smoker4060100
Column Total80370450
1

Hypotheses: H₀: Smoking status and lung disease are independent  |  H₁: They are associated

2

α = 0.05, df = (3−1)(2−1) = 2, χ²* = 5.991

3

Expected frequencies (Row × Col / 450):
Never/Yes: (200×80)/450 = 35.56  |  Never/No: (200×370)/450 = 164.44
Former/Yes: (150×80)/450 = 26.67  |  Former/No: (150×370)/450 = 123.33
Current/Yes: (100×80)/450 = 17.78  |  Current/No: (100×370)/450 = 82.22
All cells ≥ 5 ✓

4

Chi-square calculation:
= (15−35.56)²/35.56 + (185−164.44)²/164.44 + (25−26.67)²/26.67 + (125−123.33)²/123.33 + (40−17.78)²/17.78 + (60−82.22)²/82.22
= 11.89 + 2.57 + 0.10 + 0.02 + 27.80 + 6.01 = 48.39

5

p-value: χ² = 48.39, df = 2 → p < 0.0001

6

Decision: χ² = 48.39 >> 5.991 → Reject H₀

✅ Conclusion: Smoking status is strongly associated with lung disease diagnosis (χ² = 48.39, df = 2, p < 0.0001). Current smokers have a 40% disease rate versus 7.5% for never-smokers — a difference that is not attributable to chance.

Effect Size — Cramér's V

For tables larger than 2×2: V = √(χ² / (n × min(r−1, c−1))) = √(48.39 / (450 × 1)) = √0.1075 = 0.328. This is a medium effect size, confirming a meaningful association beyond statistical significance alone.

Chi-square in public health research: Agresti, A. (2007). An Introduction to Categorical Data Analysis (2nd ed.). Wiley. Effect size conventions from Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences.

Example 6 — Education Level and Job Satisfaction

Worked Example 6 — Test of Independence

Problem: An HR study surveys 300 employees on education level (High School, Bachelor's, Graduate) and job satisfaction (Satisfied, Neutral, Dissatisfied). Test at α = 0.05 whether education is related to satisfaction.

SatisfiedNeutralDissatisfiedTotal
High School302545100
Bachelor's604020120
Graduate55151080
Total1458075300
1

Hypotheses: H₀: Education level and job satisfaction are independent  |  H₁: They are associated

2

α = 0.05, df = (3−1)(3−1) = 4, χ²* = 9.488

3

Selected expected frequencies:
HS/Satisfied: (100×145)/300 = 48.33  |  HS/Neutral: (100×80)/300 = 26.67  |  HS/Dissatisfied: (100×75)/300 = 25.00
Bach/Satisfied: (120×145)/300 = 58.00  |  Bach/Neutral: 32.00  |  Bach/Dissatisfied: 30.00
Grad/Satisfied: (80×145)/300 = 38.67  |  Grad/Neutral: 21.33  |  Grad/Dissatisfied: 20.00
All cells ≥ 5 ✓

4

χ² calculation:
= (30−48.33)²/48.33 + (25−26.67)²/26.67 + (45−25)²/25 + (60−58)²/58 + (40−32)²/32 + (20−30)²/30 + (55−38.67)²/38.67 + (15−21.33)²/21.33 + (10−20)²/20
= 6.94 + 0.10 + 16.00 + 0.07 + 2.00 + 3.33 + 6.88 + 1.88 + 5.00 = 42.20

5

p-value: χ² = 42.20, df = 4 → p < 0.0001

6

Decision: χ² = 42.20 >> 9.488 → Reject H₀

✅ Conclusion: Education level and job satisfaction are strongly associated (χ² = 42.20, df = 4, p < 0.0001). Graduate-educated employees report the highest satisfaction (69%), while high school-educated employees report the lowest (30%), with dissatisfaction accounting for 45% of that group.

Example 7 — Treatment Type and Recovery Outcome

Worked Example 7 — Healthcare Application

Problem: A clinical study compares three treatments for a minor infection: Antibiotic (n=80), Placebo (n=80), and Supportive Care (n=80). Recovery is classified as: Full, Partial, or No Recovery. Test at α = 0.01 whether treatment type is independent of recovery outcome.

Full RecoveryPartialNo RecoveryTotal
Antibiotic6512380
Placebo35281780
Supportive45251080
Total1456530240
1

Hypotheses: H₀: Treatment type and recovery outcome are independent  |  H₁: They are associated

2

α = 0.01, df = (3−1)(3−1) = 4, χ²* = 13.277

3

Expected frequencies (each row total = 80, grand total = 240):
Antibiotic: Full = (80×145)/240 = 48.33, Partial = 21.67, No = 10.00
Placebo: Full = 48.33, Partial = 21.67, No = 10.00
Supportive: Full = 48.33, Partial = 21.67, No = 10.00
All ≥ 5 ✓

4

χ² = (65−48.33)²/48.33 + (12−21.67)²/21.67 + (3−10)²/10 + (35−48.33)²/48.33 + (28−21.67)²/21.67 + (17−10)²/10 + (45−48.33)²/48.33 + (25−21.67)²/21.67 + (10−10)²/10
= 5.75 + 4.32 + 4.90 + 3.68 + 1.85 + 4.90 + 0.23 + 0.51 + 0.00 = 26.14

5

p-value: χ² = 26.14, df = 4 → p < 0.0001

6

Decision: χ² = 26.14 > 13.277 → Reject H₀

✅ Conclusion: Treatment type is significantly associated with recovery outcome (χ² = 26.14, df = 4, p < 0.0001, α = 0.01). Antibiotic patients had the highest full recovery rate (81%), substantially above placebo (44%) and supportive care (56%). Cramér's V = √(26.14/(240×2)) = 0.234 — a small-to-medium effect.

Clinical chi-square methodology follows guidance from BMJ Statistics at Square One. For hypothesis testing in clinical trials see hypothesis testing in clinical trials.

Example 8 — Website Device Usage and Purchase Rate

Worked Example 8 — Business / Marketing

Problem: An e-commerce analyst tracks device type (Mobile, Desktop, Tablet) and whether a visitor completed a purchase (Yes/No) for 600 sessions. Test at α = 0.05 whether purchase behavior is independent of device type.

PurchasedDid Not PurchaseTotal
Mobile55245300
Desktop70130200
Tablet2575100
Total150450600
1

Hypotheses: H₀: Device type and purchase behavior are independent  |  H₁: They are associated

2

α = 0.05, df = (3−1)(2−1) = 2, χ²* = 5.991

3

Expected frequencies:
Mobile: Purchased = (300×150)/600 = 75, Not = 225
Desktop: Purchased = (200×150)/600 = 50, Not = 150
Tablet: Purchased = (100×150)/600 = 25, Not = 75
All ≥ 5 ✓

4

χ² calculation:
= (55−75)²/75 + (245−225)²/225 + (70−50)²/50 + (130−150)²/150 + (25−25)²/25 + (75−75)²/75
= 5.333 + 1.778 + 8.000 + 2.667 + 0 + 0 = 17.778

5

p-value: χ² = 17.778, df = 2 → p = 0.00014

6

Decision: χ² = 17.778 >> 5.991 → Reject H₀

✅ Conclusion: Device type significantly affects purchase behavior (χ² = 17.778, df = 2, p = 0.00014). Desktop users convert at 35% — substantially above mobile at 18.3%. Tablet usage matched expectations exactly. The company should prioritize desktop checkout experience optimization.

Example 9 — Defect Type by Production Shift

Worked Example 9 — Manufacturing / Quality Control

Problem: A factory records defect type (Scratch, Dent, Misprint, Other) by production shift (Morning, Afternoon, Night) over one month. 450 defects are classified. Test at α = 0.05 whether defect type depends on shift.

ScratchDentMisprintOtherTotal
Morning35252020100
Afternoon40453035150
Night55603550200
Total13013085105450
1

Hypotheses: H₀: Defect type and production shift are independent  |  H₁: They are associated

2

α = 0.05, df = (3−1)(4−1) = 6, χ²* = 12.592

3

Selected expected frequencies:
Morning: Scratch = (100×130)/450 = 28.89, Dent = 28.89, Misprint = 18.89, Other = 23.33
Afternoon: Scratch = 43.33, Dent = 43.33, Misprint = 28.33, Other = 35.00
Night: Scratch = 57.78, Dent = 57.78, Misprint = 37.78, Other = 46.67

4

χ² ≈ (35−28.89)²/28.89 + (25−28.89)²/28.89 + (20−18.89)²/18.89 + (20−23.33)²/23.33 + (40−43.33)²/43.33 + (45−43.33)²/43.33 + (30−28.33)²/28.33 + (35−35)²/35 + (55−57.78)²/57.78 + (60−57.78)²/57.78 + (35−37.78)²/37.78 + (50−46.67)²/46.67
≈ 1.29 + 0.52 + 0.07 + 0.48 + 0.26 + 0.06 + 0.10 + 0.00 + 0.13 + 0.09 + 0.20 + 0.24 = 3.44

5

p-value: χ² = 3.44, df = 6 → p ≈ 0.752

6

Decision: χ² = 3.44 < 12.592 → Fail to Reject H₀

❌ Conclusion: There is no significant association between defect type and production shift (χ² = 3.44, df = 6, p = 0.752). The proportional mix of defect types is roughly consistent across all three shifts. The quality control team should look at total defect volume per shift rather than type-specific patterns.

Example 10 — Student Major and Study Habit

Worked Example 10 — Education Research

Problem: A university counselor surveys 360 students on their academic major (STEM, Humanities, Business) and study frequency (Daily, Weekly, Rarely). Test at α = 0.05 whether major is associated with study habit.

DailyWeeklyRarelyTotal
STEM803010120
Humanities406020120
Business307020120
Total15016050360
1

Hypotheses: H₀: Major and study frequency are independent  |  H₁: They are associated

2

α = 0.05, df = (3−1)(3−1) = 4, χ²* = 9.488

3

Expected frequencies (each row = 120, grand = 360):
All rows: Daily = (120×150)/360 = 50, Weekly = (120×160)/360 = 53.33, Rarely = (120×50)/360 = 16.67
All ≥ 5 ✓

4

χ² calculation:
STEM: (80−50)²/50 + (30−53.33)²/53.33 + (10−16.67)²/16.67 = 18.00 + 10.21 + 2.67 = 30.88
Humanities: (40−50)²/50 + (60−53.33)²/53.33 + (20−16.67)²/16.67 = 2.00 + 0.84 + 0.67 = 3.51
Business: (30−50)²/50 + (70−53.33)²/53.33 + (20−16.67)²/16.67 = 8.00 + 5.21 + 0.67 = 13.88
χ² = 30.88 + 3.51 + 13.88 = 48.27

5

p-value: χ² = 48.27, df = 4 → p < 0.0001

6

Decision: χ² = 48.27 >> 9.488 → Reject H₀

✅ Conclusion: Academic major is significantly associated with study frequency (χ² = 48.27, df = 4, p < 0.0001). STEM students study daily at nearly twice the rate of Humanities and Business students (67% vs 33% and 25%). Business and Humanities students study weekly far more often. Cramér's V = √(48.27/(360×2)) = 0.259 — a medium effect.

Interactive Chi-Square Calculator

Use this calculator to run either a goodness-of-fit test or a 2×2 test of independence. Enter your observed frequencies and, for goodness-of-fit, your expected proportions. The calculator returns χ², degrees of freedom, the p-value, and a decision at α = 0.05.

Chi-Square Test Calculator

Enter observed counts and expected proportions (must sum to 1.0). Leave extra rows blank.

Effect Size for Chi-Square Tests

A significant p-value tells you the result is unlikely due to chance. It does not say how large or meaningful the association is. For chi-square tests, two effect size measures handle this.

Phi Coefficient — 2×2 Tables Only
φ = √(χ² / n)
Small: φ ≥ 0.10 Medium: φ ≥ 0.30 Large: φ ≥ 0.50
Cramér's V — All Table Sizes
V = √(χ² / (n × min(r−1, c−1)))
n = sample size r = number of rows c = number of columns Same thresholds as φ (0.10, 0.30, 0.50)

Always report effect size alongside the chi-square statistic. A study with n = 10,000 can produce a statistically significant χ² for a trivially small association that would have no practical relevance. Cramér's V guards against that misreading.

Choosing the Right Test for Categorical Data

The chi-square test is the workhorse for categorical data, but several alternatives handle situations it cannot.

Scenario Best Test Why
One categorical variable vs expected distributionChi-Square Goodness-of-FitTests fit to a specified distribution
Two categorical variables, large sample (all E ≥ 5)Chi-Square IndependenceReliable approximation with adequate n
Two categorical variables, small sample (any E < 5)Fisher's Exact TestExact probability, no approximation needed
Same subjects measured before and after (2×2)McNemar's TestHandles dependent (paired) categorical data
Alternative to chi-square with better small-sample behaviorG-Test (Likelihood Ratio)Based on log-likelihood, less biased in small n

Quick Decision Guide: Which Chi-Square (or Alternative) to Use?

How many categorical variables?
One → Goodness-of-Fit    Two → Independence Test
Any expected cell frequency < 5?
Yes → Consider Fisher's Exact Test or merge categories
Are observations paired or repeated?
Yes → McNemar's Test (2×2 only)
All conditions met for chi-square?
Yes → Use standard chi-square test

Common Mistakes in Chi-Square Tests

MistakeWrongCorrect
Using percentages instead of counts Entering 55%, 45% as cell values Always enter raw frequency counts
Ignoring the expected frequency rule Running chi-square when E = 2 in several cells Use Fisher's exact test or merge categories
Confusing independence with causation "Gender causes Brand B preference" "Gender is associated with Brand B preference"
Using chi-square for continuous data Chi-square on weight in grams Bin into categories first, or use a t-test/ANOVA
Applying chi-square to paired/repeated data Chi-square on before-vs-after responses Use McNemar's test for dependent samples
Forgetting to report effect size "χ² = 4.2, p = 0.04 — significant association" Add Cramér's V or phi to quantify the size
💡
Yates' Continuity Correction

For 2×2 tables with small samples, some textbooks apply Yates' correction: subtract 0.5 from |O − E| before squaring. This correction is conservative and is now considered controversial — most statisticians prefer Fisher's exact test for small samples. See the full discussion in the chi-square test guide.

Real-Life Applications of the Chi-Square Test

🏥

Healthcare & Epidemiology

Testing whether a disease diagnosis is independent of risk factors such as smoking, diet, or age group. Used in case-control and cohort studies.

📊

Market Research

Determining whether consumer preference varies by demographic segment (age, gender, income). Guides advertising and product development decisions.

🧬

Genetics & Biology

Verifying whether observed trait frequencies match Mendelian inheritance ratios. Used in Hardy-Weinberg equilibrium testing.

🗳️

Political Science & Polling

Testing whether voting preference is independent of region, education level, or income. Standard in electoral analysis and survey research.

🎓

Educational Research

Assessing whether pass/fail rates differ across teaching methods, or whether student satisfaction varies by faculty department.

🏭

Quality Control

Checking whether defect frequencies match expected rates, or whether defect type varies by production line or shift. Standard in Six Sigma methodology.

Entity & Formula Glossary

TermSymbol / FormulaDefinition
Chi-Square Statisticχ²Sum of (O−E)²/E across all categories; measures departure from expectation
Observed FrequencyOThe actual count in a category or cell from your data
Expected FrequencyEThe count predicted under H₀; goodness-of-fit: n×p; independence: (row×col)/n
Degrees of FreedomdfGoodness-of-fit: k−1; Independence: (r−1)(c−1)
Contingency Tabler × cCross-tabulation showing joint frequencies of two categorical variables
p-valuepProbability of obtaining χ² this large (or larger) if H₀ is true
Critical Valueχ²*Threshold from the chi-square table at chosen df and α; reject H₀ if χ² > χ²*
Phi Coefficientφ = √(χ²/n)Effect size for 2×2 tables; small=0.10, medium=0.30, large=0.50
Cramér's VV = √(χ²/(n×min(r−1,c−1)))Effect size for larger tables; same benchmarks as phi
Null HypothesisH₀Assumes independence or that the distribution fits the expected model
Alternative HypothesisH₁Claims an association exists or the distribution does not fit
Statistical Significancep < αThe result is unlikely under H₀ at the chosen significance level
Karl PearsonIntroduced the chi-square test in 1900; foundational statistician
Fisher's Exact TestExact alternative when expected frequencies < 5; developed by Ronald Fisher

Frequently Asked Questions

A chi-square test determines whether the pattern observed in categorical data differs significantly from what would be expected by chance. It compares observed frequencies with expected frequencies and calculates a chi-square statistic to determine whether the differences are statistically significant. It is commonly used for goodness-of-fit and tests of independence.
Degrees of freedom determine which chi-square distribution is used to calculate the p-value or critical value. For a goodness-of-fit test, the degrees of freedom are k − 1, where k is the number of categories. For a test of independence, they are calculated as (rows − 1) × (columns − 1).
The p-value represents the probability of obtaining a chi-square statistic at least as extreme as the observed value if the null hypothesis is true. If the p-value is less than the chosen significance level (commonly 0.05), you reject the null hypothesis and conclude that a statistically significant association or difference exists. A large p-value indicates insufficient evidence to reject the null hypothesis.
Fisher's exact test is recommended when sample sizes are small or when one or more expected cell frequencies are less than 5. Unlike the chi-square test, Fisher's exact test calculates the exact probability rather than relying on an approximation, making it more accurate for small datasets, particularly in 2 × 2 contingency tables.
No. A chi-square test cannot prove independence. If the test is not statistically significant, you simply fail to reject the null hypothesis, meaning there is not enough evidence to conclude that an association exists. This does not prove that the variables are truly independent, especially if the sample size is small.
Most statistical software includes built-in chi-square functions. In R, use chisq.test(). In Python, use scipy.stats.chisquare() for goodness-of-fit or scipy.stats.chi2_contingency() for contingency tables. In SPSS, choose Analyze → Descriptive Statistics → Crosstabs → Statistics → Chi-Square. In Excel, use the CHISQ.TEST() function to calculate the p-value from observed and expected frequencies.
A chi-square test is used for independent observations, where each subject appears in only one category. McNemar's test is designed for paired or repeated measurements, such as before-and-after studies or matched pairs. Using a standard chi-square test for paired data violates the assumption of independence and may produce misleading results.

The chi-square test is one tool in a broader framework of hypothesis testing. These related topics extend the concepts covered here.

📋

Chi-Square Test Guide

Complete theory, formula derivation, and worked examples for both test types. The canonical reference page.

📊

Chi-Square Table

Critical values at α = 0.10, 0.05, 0.025, 0.01, and 0.001 for df 1–100.

🧮

Chi-Square Calculator

Full-featured calculator with contingency table builder, expected frequencies, and effect size output.

🔬

McNemar's Test

The right choice for paired categorical data — before/after designs and matched pairs.

🎯

Hypothesis Testing Examples

Seven fully worked examples covering z-test, t-test (three types), chi-square, ANOVA, and proportion tests.

⚖️

Chi-Square vs T-Test

When each test is appropriate — the key decision criteria for categorical vs. continuous data.