What Is a Chi-Square Test?
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.
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 question | Does one variable follow a specified distribution? | Are two categorical variables associated? |
| Number of variables | One | Two |
| Data layout | Single frequency column | Contingency table (rows × columns) |
| Degrees of freedom | k − 1 (k = categories) | (r − 1)(c − 1) |
| Expected frequency formula | E = n × pi | E = (row total × col total) / n |
| Typical example | Does 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 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:
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.
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.
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.
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.
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.
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.
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₀.
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.
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.
Calculate Expected Frequencies
Goodness-of-fit: Ei = n × pi. Independence: Eij = (Ri × Cj) / n. Verify all E values are ≥ 5 before proceeding.
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₀.
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
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.
| Face | 1 | 2 | 3 | 4 | 5 | 6 | Total |
|---|---|---|---|---|---|---|---|
| Observed (O) | 25 | 17 | 15 | 23 | 24 | 16 | 120 |
| Expected (E) | 20 | 20 | 20 | 20 | 20 | 20 | 120 |
n = 120 total rolls
k = 6 faces
df = k − 1 = 5
Hypotheses: H₀: The die is fair (each face has probability 1/6) | H₁: At least one face has a different probability
α = 0.05. df = 6 − 1 = 5. From the chi-square table: χ²* = 11.070
Expected frequencies: All E = 120/6 = 20. All ≥ 5 ✓
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
p-value: For χ² = 5.00 with df = 5: p ≈ 0.416
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)
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 Color | Observed (O) | Expected (E) | (O−E)²/E |
|---|---|---|---|
| Purple | 290 | 300 | 0.333 |
| White | 110 | 100 | 1.000 |
| Total | 400 | 400 | χ² = 1.333 |
Hypotheses: H₀: Offspring follow a 3:1 ratio (p₁ = 0.75, p₂ = 0.25) | H₁: They do not follow a 3:1 ratio
α = 0.05. df = 2 − 1 = 1. Critical value: χ²* = 3.841
Expected frequencies: E(Purple) = 400 × 0.75 = 300. E(White) = 400 × 0.25 = 100. Both ≥ 5 ✓
Chi-square statistic:
χ² = (290−300)²/300 + (110−100)²/100
= 100/300 + 100/100
= 0.333 + 1.000 = 1.333
p-value: For χ² = 1.333 with df = 1: p ≈ 0.248
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.
Example 3 — Commute Mode Distribution
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.
| Mode | Observed | Expected | (O−E)²/E |
|---|---|---|---|
| Car | 285 | 300 | 0.750 |
| Transit | 130 | 125 | 0.200 |
| Bike | 60 | 50 | 2.000 |
| Walk | 25 | 25 | 0.000 |
| Total | 500 | 500 | χ² = 2.950 |
Hypotheses: H₀: Current distribution matches historical proportions (60/25/10/5%) | H₁: At least one proportion has changed
α = 0.01. df = 4 − 1 = 3. Critical value: χ²* = 11.345
Expected frequencies: 500×0.60=300; 500×0.25=125; 500×0.10=50; 500×0.05=25. All ≥ 5 ✓
χ² = 0.75 + 0.20 + 2.00 + 0.00 = 2.950
p-value: p ≈ 0.399
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
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 A | Brand B | Row Total | |
|---|---|---|---|
| Male | 55 | 45 | 100 |
| Female | 35 | 65 | 100 |
| Column Total | 90 | 110 | 200 |
df = (2−1)(2−1) = 1
χ²* at α=0.05, df=1: 3.841
Hypotheses: H₀: Gender and brand preference are independent | H₁: They are associated
α = 0.05, df = 1, χ²* = 3.841
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 ✓
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
p-value: For χ² = 8.08 with df = 1: p ≈ 0.0045
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
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: Yes | Lung Disease: No | Row Total | |
|---|---|---|---|
| Never Smoked | 15 | 185 | 200 |
| Former Smoker | 25 | 125 | 150 |
| Current Smoker | 40 | 60 | 100 |
| Column Total | 80 | 370 | 450 |
Hypotheses: H₀: Smoking status and lung disease are independent | H₁: They are associated
α = 0.05, df = (3−1)(2−1) = 2, χ²* = 5.991
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 ✓
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
p-value: χ² = 48.39, df = 2 → p < 0.0001
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.
Example 6 — Education Level and Job Satisfaction
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.
| Satisfied | Neutral | Dissatisfied | Total | |
|---|---|---|---|---|
| High School | 30 | 25 | 45 | 100 |
| Bachelor's | 60 | 40 | 20 | 120 |
| Graduate | 55 | 15 | 10 | 80 |
| Total | 145 | 80 | 75 | 300 |
Hypotheses: H₀: Education level and job satisfaction are independent | H₁: They are associated
α = 0.05, df = (3−1)(3−1) = 4, χ²* = 9.488
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 ✓
χ² 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
p-value: χ² = 42.20, df = 4 → p < 0.0001
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
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 Recovery | Partial | No Recovery | Total | |
|---|---|---|---|---|
| Antibiotic | 65 | 12 | 3 | 80 |
| Placebo | 35 | 28 | 17 | 80 |
| Supportive | 45 | 25 | 10 | 80 |
| Total | 145 | 65 | 30 | 240 |
Hypotheses: H₀: Treatment type and recovery outcome are independent | H₁: They are associated
α = 0.01, df = (3−1)(3−1) = 4, χ²* = 13.277
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 ✓
χ² = (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
p-value: χ² = 26.14, df = 4 → p < 0.0001
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.
Example 8 — Website Device Usage and Purchase Rate
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.
| Purchased | Did Not Purchase | Total | |
|---|---|---|---|
| Mobile | 55 | 245 | 300 |
| Desktop | 70 | 130 | 200 |
| Tablet | 25 | 75 | 100 |
| Total | 150 | 450 | 600 |
Hypotheses: H₀: Device type and purchase behavior are independent | H₁: They are associated
α = 0.05, df = (3−1)(2−1) = 2, χ²* = 5.991
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 ✓
χ² 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
p-value: χ² = 17.778, df = 2 → p = 0.00014
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
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.
| Scratch | Dent | Misprint | Other | Total | |
|---|---|---|---|---|---|
| Morning | 35 | 25 | 20 | 20 | 100 |
| Afternoon | 40 | 45 | 30 | 35 | 150 |
| Night | 55 | 60 | 35 | 50 | 200 |
| Total | 130 | 130 | 85 | 105 | 450 |
Hypotheses: H₀: Defect type and production shift are independent | H₁: They are associated
α = 0.05, df = (3−1)(4−1) = 6, χ²* = 12.592
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
χ² ≈ (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
p-value: χ² = 3.44, df = 6 → p ≈ 0.752
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
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.
| Daily | Weekly | Rarely | Total | |
|---|---|---|---|---|
| STEM | 80 | 30 | 10 | 120 |
| Humanities | 40 | 60 | 20 | 120 |
| Business | 30 | 70 | 20 | 120 |
| Total | 150 | 160 | 50 | 360 |
Hypotheses: H₀: Major and study frequency are independent | H₁: They are associated
α = 0.05, df = (3−1)(3−1) = 4, χ²* = 9.488
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 ✓
χ² 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
p-value: χ² = 48.27, df = 4 → p < 0.0001
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.
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 distribution | Chi-Square Goodness-of-Fit | Tests fit to a specified distribution |
| Two categorical variables, large sample (all E ≥ 5) | Chi-Square Independence | Reliable approximation with adequate n |
| Two categorical variables, small sample (any E < 5) | Fisher's Exact Test | Exact probability, no approximation needed |
| Same subjects measured before and after (2×2) | McNemar's Test | Handles dependent (paired) categorical data |
| Alternative to chi-square with better small-sample behavior | G-Test (Likelihood Ratio) | Based on log-likelihood, less biased in small n |
Quick Decision Guide: Which Chi-Square (or Alternative) to Use?
Common Mistakes in Chi-Square Tests
| Mistake | Wrong | Correct |
|---|---|---|
| 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 |
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
| Term | Symbol / Formula | Definition |
|---|---|---|
| Chi-Square Statistic | χ² | Sum of (O−E)²/E across all categories; measures departure from expectation |
| Observed Frequency | O | The actual count in a category or cell from your data |
| Expected Frequency | E | The count predicted under H₀; goodness-of-fit: n×p; independence: (row×col)/n |
| Degrees of Freedom | df | Goodness-of-fit: k−1; Independence: (r−1)(c−1) |
| Contingency Table | r × c | Cross-tabulation showing joint frequencies of two categorical variables |
| p-value | p | Probability 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 V | V = √(χ²/(n×min(r−1,c−1))) | Effect size for larger tables; same benchmarks as phi |
| Null Hypothesis | H₀ | Assumes independence or that the distribution fits the expected model |
| Alternative Hypothesis | H₁ | Claims an association exists or the distribution does not fit |
| Statistical Significance | p < α | The result is unlikely under H₀ at the chosen significance level |
| Karl Pearson | — | Introduced the chi-square test in 1900; foundational statistician |
| Fisher's Exact Test | — | Exact alternative when expected frequencies < 5; developed by Ronald Fisher |
Frequently Asked Questions
k − 1, where k is the number of categories. For a test of independence, they are calculated as (rows − 1) × (columns − 1).
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.
Related Statistical Tests & Resources
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.