Skip to content

Chi-Square Tests for Independence and Homogeneity

Chi-square test for independence (one sample, two categorical variables) and for homogeneity (multiple independent samples), including expected counts, degrees of freedom, and conditions.

Written and reviewed by the Study Mondo Education TeamLast updated
🎯⭐ INTERACTIVE LESSON

Try the Interactive Version!

Learn step-by-step with practice exercises built right in.

Start Interactive Lesson →

🔲 Chi-Square Tests for Independence and Homogeneity

Chi-square tests are used to analyze the relationship between two categorical variables. Two common scenarios are tested: independence (one sample, two categorical variables) and homogeneity (multiple independent samples, one categorical variable each).

The Chi-Square Test Statistic

Both tests use the same test statistic:

χ2=∑all cells(Observed−Expected)2Expected\chi^2 = \sum_{\text{all cells}} \frac{(\text{Observed} - \text{Expected})^2}{\text{Expected}}

where:

  • Observed = actual count in each cell of the contingency table
  • Expected = count predicted under the null hypothesis

The test statistic follows a chi-square distribution with degrees of freedom depending on the context.

Test for Independence

Purpose: Test whether two categorical variables in a single population are independent.

Hypotheses:

  • H0H_0: The two variables are independent (no association)
  • HaH_a: The two variables are associated (not independent)

Expected Cell Counts (under H0H_0 of independence): Eij=(Row totali)×(Column totalj)Grand totalE_{ij} = \frac{(\text{Row total}_i) \times (\text{Column total}_j)}{\text{Grand total}}

Degrees of Freedom: df=(r−1)(c−1)df = (r - 1)(c - 1) where rr = number of rows, cc = number of columns in the contingency table.

Test for Homogeneity

Purpose: Test whether the distribution of a categorical variable is the same across multiple independent groups (samples).

Hypotheses:

  • H0H_0: The distribution of the variable is the same in all groups (homogeneous)
  • HaH_a: The distribution of the variable differs across groups (not homogeneous)

Expected Cell Counts (under H0H_0 of homogeneity): Eij=(Row totali)×(Column totalj)Grand totalE_{ij} = \frac{(\text{Row total}_i) \times (\text{Column total}_j)}{\text{Grand total}}

Note: Formula is identical to the independence test, but interpretation differs.

Degrees of Freedom: df=(r−1)(c−1)df = (r - 1)(c - 1) where rr = number of categories in the variable, cc = number of groups/samples.

Conditions for Chi-Square Tests

ConditionRequirement
Random samplingData must be from random samples.
IndependenceObservations are independent within each cell.
Large CountsAll expected cell counts must be ≥5\geq 5 (some allow ≥1\geq 1 if no more than 20% of cells are <5< 5).
Sample SizeUsually n≥20n \geq 20 to ensure reliable results.

Worked Example 1: Test for Independence

A study of 200 college students asks about Gender (M/F) and Exercise Habit (Regular/Irregular). The data:

RegularIrregularTotal
Male403070
Female6070130
Total100100200

Test H0H_0: Gender and Exercise are independent, at α=0.05\alpha = 0.05.

Calculate expected counts:

  • EM,R=70×100200=35E_{M,R} = \frac{70 \times 100}{200} = 35
  • EM,I=70×100200=35E_{M,I} = \frac{70 \times 100}{200} = 35
  • EF,R=130×100200=65E_{F,R} = \frac{130 \times 100}{200} = 65
  • EF,I=130×100200=65E_{F,I} = \frac{130 \times 100}{200} = 65

All expected counts ≥5\geq 5 ✓

Calculate χ2\chi^2: χ2=(40−35)235+(30−35)235+(60−65)265+(70−65)265\chi^2 = \frac{(40-35)^2}{35} + \frac{(30-35)^2}{35} + \frac{(60-65)^2}{65} + \frac{(70-65)^2}{65} =2535+2535+2565+2565=0.714+0.714+0.385+0.385=2.198= \frac{25}{35} + \frac{25}{35} + \frac{25}{65} + \frac{25}{65} = 0.714 + 0.714 + 0.385 + 0.385 = 2.198

Degrees of freedom: df=(2−1)(2−1)=1df = (2-1)(2-1) = 1

p-value: For χ2=2.198\chi^2 = 2.198 with df=1df = 1, P(χ2>2.198)≈0.138P(\chi^2 > 2.198) \approx 0.138.

Since p-value≈0.138>0.05p\text{-value} \approx 0.138 > 0.05, fail to reject H0H_0. No significant evidence that gender and exercise are associated.

Worked Example 2: Test for Homogeneity

Compare the distribution of Political Party (Democrat/Republican/Independent) across three Age Groups (18–30, 31–50, 50+). Sample of 600 people:

Party18–3031–5050+Total
Dem.809070240
Rep.50100110260
Ind.20303080
Total150220230600

Test H0H_0: Political party distribution is the same across age groups, at α=0.05\alpha = 0.05.

Calculate expected counts (sample):

  • ED,1=240×150600=60E_{D,1} = \frac{240 \times 150}{600} = 60
  • ED,2=240×220600=88E_{D,2} = \frac{240 \times 220}{600} = 88
  • ... (all ≥5\geq 5) ✓

Calculate χ2\chi^2 (simplified; full calculation omitted): χ2≈15.38\chi^2 \approx 15.38

Degrees of freedom: df=(3−1)(3−1)=4df = (3-1)(3-1) = 4

p-value: For χ2≈15.38\chi^2 \approx 15.38 with df=4df = 4, P(χ2>15.38)≈0.0036P(\chi^2 > 15.38) \approx 0.0036.

Since p-value≈0.0036<0.05p\text{-value} \approx 0.0036 < 0.05, reject H0H_0. Significant evidence that political party distribution differs across age groups.

Common Pitfalls

⚠️ Using Observed Instead of Expected Counts: The chi-square statistic compares observed counts to expected counts under H0H_0. Always compute expected counts carefully; a mistake here invalidates the entire test.

⚠️ Ignoring the Large Counts Condition: If expected counts are too small (typically <5< 5), the chi-square distribution is not a good approximation. Combine categories or use Fisher's exact test if appropriate.

⚠️ Confusing Independence and Homogeneity: Both use the same χ2\chi^2 statistic and formula, but test different hypotheses. Independence: one sample, two variables. Homogeneity: multiple samples, one variable.

Calculator Tip

💡 TI-84 / TI-Nspire: Use χ2\chi^2 Goodness-of-Fit or χ2\chi^2 Test. Enter the observed counts in a matrix, then calculate. The calculator computes expected counts, χ2\chi^2, df, and p-value automatically. (Some calculators use "Chi2 Test" for homogeneity/independence and "Chi2 GOF" for goodness-of-fit.)

📚 Practice Problems

1Problem 1easy

❓ Question:

In a 2×32 \times 3 contingency table with row totals (100, 150) and column totals (80, 110, 60), find the expected count for the cell in row 1, column 2.

💡 Show Solution

Grand total: Grand Total=100+150=250\text{Grand Total} = 100 + 150 = 250

Expected count: E1,2=(Row 1 Total)×(Column 2 Total)Grand Total=100×110250=11000250=44E_{1,2} = \frac{(\text{Row 1 Total}) \times (\text{Column 2 Total})}{\text{Grand Total}} = \frac{100 \times 110}{250} = \frac{11000}{250} = 44

Answer: Expected count = 44.

2Problem 2medium

❓ Question:

A contingency table for Color (Red/Blue) and Size (Small/Large) has observed counts: (30, 20, 25, 40). Row totals: (50, 65), Column totals: (55, 55). Compute χ2\chi^2 and determine whether to reject H0:independenceH_0: \text{independence} at α=0.05\alpha = 0.05.

💡 Show Solution

Organize:

RedBlueTotal
Small302050
Large254065
Total5555110

Expected counts:

  • ES,R=50×55110=25E_{S,R} = \frac{50 \times 55}{110} = 25
  • ES,B=50×55110=25E_{S,B} = \frac{50 \times 55}{110} = 25
  • EL,R=65×55110=32.5E_{L,R} = \frac{65 \times 55}{110} = 32.5
  • EL,B=65×55110=32.5E_{L,B} = \frac{65 \times 55}{110} = 32.5

All ≥5\geq 5 ✓

Chi-square: χ2=(30−25)225+(20−25)225+(25−32.5)232.5+(40−32.5)232.5\chi^2 = \frac{(30-25)^2}{25} + \frac{(20-25)^2}{25} + \frac{(25-32.5)^2}{32.5} + \frac{(40-32.5)^2}{32.5} =2525+2525+56.2532.5+56.2532.5=1+1+1.73+1.73=5.46= \frac{25}{25} + \frac{25}{25} + \frac{56.25}{32.5} + \frac{56.25}{32.5} = 1 + 1 + 1.73 + 1.73 = 5.46

Degrees of freedom: df=(2−1)(2−1)=1df = (2-1)(2-1) = 1

p-value: P(χ2>5.46∣df=1)≈0.019P(\chi^2 > 5.46 \mid df=1) \approx 0.019

Since 0.019<0.050.019 < 0.05, reject H0H_0. Significant evidence that Size and Color are associated.

3Problem 3hard

❓ Question:

A test of homogeneity compares Preference (Yes/No) across four Groups (A, B, C, D). The observed χ2=8.45\chi^2 = 8.45. With df=3df = 3 and α=0.05\alpha = 0.05, find the critical value and determine the conclusion.

💡 Show Solution

Critical value from chi-square table: For df=3df = 3 and α=0.05\alpha = 0.05, the critical value is χ0.05,32≈7.815\chi^2_{0.05,3} \approx 7.815.

Decision: Since the observed χ2=8.45>7.815\chi^2 = 8.45 > 7.815, we reject H0H_0.

Alternatively, using p-value: P(χ2>8.45∣df=3)≈0.038P(\chi^2 > 8.45 \mid df=3) \approx 0.038

Since p-value≈0.038<0.05p\text{-value} \approx 0.038 < 0.05, we reject H0H_0.

Conclusion: There is significant evidence that the distribution of preferences (Yes/No) differs across the four groups. At least one group has a different preference distribution than the others.

Explain using:

⚠️ Common Mistakes: Chi-Square Tests for Independence and Homogeneity

Avoid these 3 frequent errors

📌 Related Topics in Unit 8: Inference for Categorical Data — Chi-Square

❓ Frequently Asked Questions

What is Chi-Square Tests for Independence and Homogeneity?▾
Chi-square test for independence (one sample, two categorical variables) and for homogeneity (multiple independent samples), including expected counts, degrees of freedom, and conditions.
How can I study Chi-Square Tests for Independence and Homogeneity effectively?▾
Start by reading the study notes and working through the examples on this page. Then use the flashcards to test your recall. Practice with the 3 problems provided, checking solutions as you go. Regular review and active practice are key to retention.
Is this Chi-Square Tests for Independence and Homogeneity study guide free?▾
Yes — all study notes, flashcards, and practice problems for Chi-Square Tests for Independence and Homogeneity on Study Mondo are free to access. No account is needed.
What course covers Chi-Square Tests for Independence and Homogeneity?▾
Chi-Square Tests for Independence and Homogeneity is part of the AP Statistics course on Study Mondo, specifically in the Unit 8: Inference for Categorical Data — Chi-Square section. You can explore the full course for more related topics and practice resources.
Are there practice problems for Chi-Square Tests for Independence and Homogeneity?▾
Yes, this page includes 3 practice problems with detailed solutions. Each problem includes a step-by-step explanation to help you understand the approach.