Skip to content
🎯⭐ INTERACTIVE LESSON

Chi-Square Tests for Independence and Homogeneity

Learn step-by-step with interactive practice!

Chi-Square Tests for Independence and Homogeneity - Complete Interactive Lesson

Part 1: The Chi-Square Statistic and Its Distribution

📊 The Chi-Square Statistic and Its Distribution

Part 1 of 7 — Measuring How Far Counts Are From Expected


Where Chi-Square Tests Fit

Chi-square tests answer questions about two-way tables of categorical data. On the AP exam there are two of them:

TestQuestion it answers
HomogeneityIs the distribution of one categorical variable the same in two or more populations (or treatment groups)?
IndependenceIn one population, are two categorical variables associated?

Both tests use the same statistic, the same expected counts and the same degrees of freedom. This part builds those tools; Parts 2 and 3 cover each test.

ℹ️ The goodness-of-fit test (one categorical variable against a claimed distribution) is not part of the current AP Statistics course.


Expected Counts

If the null hypothesis is true, each cell of a two-way table has an expected count:

expected count=row total×column totaltable total\boxed{\text{expected count} = \frac{\text{row total} \times \text{column total}}{\text{table total}}}

Example: 200 students (100 in Grade 10, 100 in Grade 12) report how they get to school.

BusCarWalkTotal
Grade 10324028100
Grade 12185032100
Total509060200

Expected count for Grade 10, Bus: 100×50200=25\frac{100 \times 50}{200} = 25. The full set of expected counts is 25, 45, 30 in each row.


The Chi-Square Statistic

χ2=∑(observed−expected)2expected\chi^2 = \sum \frac{(\text{observed} - \text{expected})^2}{\text{expected}}

The sum runs over every cell of the table. Each term measures the distance between an observed and an expected count relative to the expected count, so a gap of 7 matters more in a cell that expects 25 than in a cell that expects 250.

For the example:

χ2=(32−25)225+(40−45)245+(28−30)230+(18−25)225+(50−45)245+(32−30)230\chi^2 = \frac{(32-25)^2}{25} + \frac{(40-45)^2}{45} + \frac{(28-30)^2}{30} + \frac{(18-25)^2}{25} + \frac{(50-45)^2}{45} + \frac{(32-30)^2}{30}

=1.960+0.556+0.133+1.960+0.556+0.133≈5.30= 1.960 + 0.556 + 0.133 + 1.960 + 0.556 + 0.133 \approx 5.30

🔑 χ2=0\chi^2 = 0 only when every observed count equals its expected count. The farther the counts are from expected, the larger χ2\chi^2 gets.

The Statistic Check 🎯

📈 Chi-Square Distributions

When the null hypothesis is true, the chi-square statistic follows a chi-square distribution with

df=(number of rows−1)(number of columns−1)df = (\text{number of rows} - 1)(\text{number of columns} - 1)

For the transport example, df=(2−1)(3−1)=2df = (2-1)(3-1) = 2.

Shape of the family

FeatureWhat to know
ValuesAlways positive (a sum of squares divided by positive counts)
ShapeSkewed right
Effect of dfdfThe skew becomes less pronounced as dfdf increases

Why the p-value is a right-tail area

Only large values of χ2\chi^2 are evidence against H0H_0: they mean the observed counts sit far from what H0H_0 predicts. So the p-value is always the area to the right of the observed χ2\chi^2 under the chi-square curve with the correct dfdf.

For the example, χ2≈5.30\chi^2 \approx 5.30 with df=2df = 2 gives a right-tail area of about 0.07 (from a table or technology). Parts 4 and 5 show how to read the table.

Distribution Check 📈

Chi-Square Calculation 🧮

A two-way table has row totals 60 and 90, column totals 50, 70 and 30, and a table total of 150.

1) Expected count for row 1, column 2 = ?

2) The observed count in that cell is 35. What is its contribution (O−E)2/E(O-E)^2/E to χ2\chi^2?

3) Degrees of freedom for this table = ?

Part 2: Chi-Square Test for Independence

📊 Chi-Square Test for Independence

Part 2 of 7 — Are Two Categorical Variables Related?


Topics in This Part

Section
📐 When to Use It
📊 Two-Way Tables & Expected Counts
🧮 The Test Statistic
📝 Full Worked Example

🔑 Key Concept: The chi-square test for independence uses data from one sample to determine whether two categorical variables are associated (related) or independent.


When to Use the Test for Independence

FeatureDetail
Data sourceOne sample or one group of subjects
VariablesTwo categorical variables measured on each subject
H0H_0The two variables are independent (not associated)
HaH_aThe two variables are associated (dependent)

Example: Survey 300 students and record both grade level (freshman, sophomore, junior, senior) and preferred lunch (pizza, salad, sandwich). Is there an association between grade and lunch preference?


Expected Counts

For each cell in a two-way table:

E=row total×column totalgrand total\boxed{E = \frac{\text{row total} \times \text{column total}}{\text{grand total}}}

This gives the count you would expect if the two variables were truly independent.


Worked Example

Data: A random sample of 200 adults:

FavorOpposeTotal
Male6040100
Female4555100
Total10595200

H0H_0: Gender and opinion are independent.
HaH_a: Gender and opinion are associated.

Expected counts:

FavorOppose
Male100×105200=52.5\frac{100 \times 105}{200} = 52.5100×95200=47.5\frac{100 \times 95}{200} = 47.5
Female100×105200=52.5\frac{100 \times 105}{200} = 52.5100×95200=47.5\frac{100 \times 95}{200} = 47.5

χ2\chi^2 calculation:

χ2=(60−52.5)252.5+(40−47.5)247.5+(45−52.5)252.5+(55−47.5)247.5\chi^2 = \frac{(60-52.5)^2}{52.5} + \frac{(40-47.5)^2}{47.5} + \frac{(45-52.5)^2}{52.5} + \frac{(55-47.5)^2}{47.5}

=56.2552.5+56.2547.5+56.2552.5+56.2547.5= \frac{56.25}{52.5} + \frac{56.25}{47.5} + \frac{56.25}{52.5} + \frac{56.25}{47.5}

=1.071+1.184+1.071+1.184=4.510= 1.071 + 1.184 + 1.071 + 1.184 = 4.510

df=(r−1)(c−1)=(2−1)(2−1)=1df = (r-1)(c-1) = (2-1)(2-1) = 1

Using a χ2\chi^2 table: p≈0.034p \approx 0.034

Conclusion: Since p=0.034<0.05p = 0.034 < 0.05, we reject H0H_0. There is convincing evidence of an association between gender and opinion on this issue.

Independence Test Concepts 🎯

Expected Count Practice 🧮

A two-way table has row totals of 80 and 120, column totals of 90 and 110, and a grand total of 200.

1) Expected count for the top-left cell (row 1, column 1)?

2) Expected count for the bottom-right cell (row 2, column 2)?

3) Degrees of freedom for this 2×22 \times 2 table?

Independence Test Decisions 🔍

Exit Quiz — Test for Independence ✅

Part 3: Chi-Square Test for Homogeneity

📊 Chi-Square Test for Homogeneity

Part 3 of 7 — Comparing Distributions Across Populations


Topics in This Part

Section
📐 Independence vs. Homogeneity
📊 Setting Up the Test
🧮 Worked Example
📝 AP Exam Distinction

🔑 Key Concept: The test for homogeneity uses data from two or more independent samples (or treatment groups) to determine whether the distribution of a single categorical variable is the same across all populations.


Independence vs. Homogeneity

FeatureIndependenceHomogeneity
SamplesOne sampleTwo or more independent samples
VariablesTwo categorical variablesOne categorical variable across groups
H0H_0Variables are independentDistribution is the same across populations
CalculationIdentical formula: χ2=∑(O−E)2/E\chi^2 = \sum (O-E)^2/ESame formula
dfdf(r−1)(c−1)(r-1)(c-1)(r−1)(c−1)(r-1)(c-1)

⚠️ AP Exam: The math is identical. The difference is in the hypotheses and context. Read the problem carefully to determine which test is appropriate.


Hypotheses for Homogeneity

H0:The distribution of [variable] is the same for all [groups].H_0: \text{The distribution of [variable] is the same for all [groups].} Ha:The distribution of [variable] is NOT the same for all [groups].H_a: \text{The distribution of [variable] is NOT the same for all [groups].}


Worked Example

Problem: Two schools were surveyed about favorite subject. Is the distribution of preferences the same?

MathEnglishScienceTotal
School A453025100
School B354025100
Total807050200

H0H_0: The distribution of favorite subject is the same for School A and School B.

Expected counts: (each row total = 100, grand total = 200)

MathEnglishScience
School A100×80200=40\frac{100 \times 80}{200} = 40100×70200=35\frac{100 \times 70}{200} = 35100×50200=25\frac{100 \times 50}{200} = 25
School B404035352525

χ2\chi^2:

χ2=(45−40)240+(30−35)235+(25−25)225+(35−40)240+(40−35)235+(25−25)225\chi^2 = \frac{(45-40)^2}{40} + \frac{(30-35)^2}{35} + \frac{(25-25)^2}{25} + \frac{(35-40)^2}{40} + \frac{(40-35)^2}{35} + \frac{(25-25)^2}{25}

=0.625+0.714+0+0.625+0.714+0=2.678= 0.625 + 0.714 + 0 + 0.625 + 0.714 + 0 = 2.678

df=(2−1)(3−1)=2df = (2-1)(3-1) = 2

Using a χ2\chi^2 table with df=2df = 2: p≈0.262p \approx 0.262

Conclusion: Since p=0.262>0.05p = 0.262 > 0.05, we fail to reject H0H_0. There is not convincing evidence that the distribution of favorite subject differs between the two schools.

Homogeneity Concepts 🎯

Independence or Homogeneity? 🔍

Identify the correct test for each scenario.

Homogeneity Calculation 🧮

Three brands of cereal are compared on sugar level (Low, Medium, High). Samples: Brand A: 50, Brand B: 60, Brand C: 40. Grand total: 150. Column totals: Low = 60, Medium = 50, High = 40.

1) Expected count for Brand A, Low sugar?

2) Expected count for Brand C, High sugar?

3) dfdf for this 3×33 \times 3 table?

Exit Quiz — Test for Homogeneity ✅

Part 4: Conditions and Degrees of Freedom

📊 Conditions and Degrees of Freedom

Part 4 of 7 — When Can You Use the χ2\chi^2 Test?


Topics in This Part

Section
✅ Three Conditions
📐 Degrees of Freedom
📈 How dfdf Changes the Distribution
⚠️ What to Do When a Condition Fails

🔑 Key Concept: Both chi-square tests (homogeneity and independence) require the same three conditions: Random, 10%, and Expected Counts.


The Three Conditions

ConditionRequirementAP Language
RandomIndependence test: a random sample. Homogeneity test: independent random samples or a randomized experiment"The problem states..." or "We are told..."
10%When sampling without replacement, n≤10%n \leq 10\% of the population (not needed for a randomized experiment)"nn is less than 10% of all [population]"
Expected CountsAll expected counts are greater than 5"All expected counts are greater than 5" ✓

⚠️ Critical AP Detail: For chi-square, the expected counts condition uses expected counts, NOT observed counts. This is different from the Large Counts condition for proportions (np≥10np \geq 10 and n(1−p)≥10n(1-p) \geq 10).


Degrees of Freedom

Both tests use the same formula:

df=(number of rows−1)(number of columns−1)df = (\text{number of rows} - 1)(\text{number of columns} - 1)

Tabledfdf
2×22 \times 211
2×32 \times 322
3×43 \times 466

Count only the rows and columns of categories; the total row and total column are not part of the table's dimensions.


Why Degrees of Freedom Matter

The χ2\chi^2 distribution changes shape with dfdf:

dfdfShape
11Strongly right-skewed
55Moderately right-skewed
15+15+Much less skewed

As dfdf increases, the skew becomes less pronounced and the curve spreads to the right, so the same χ2\chi^2 value gives a larger p-value when dfdf is larger.


What If a Condition Fails?

ConditionIf It Fails
RandomResults may not generalize to the population; state the limitation
10%Observations are not independent enough; the p-value is questionable
Expected CountsThe chi-square distribution may not describe the statistic well, so the p-value may be inaccurate

🔑 AP Tip: If an expected count is 5 or less, say that the condition is not met. If the problem asks you to proceed anyway, state the concern and continue with caution.

Conditions & df Concepts 🎯

Degrees of Freedom Practice 🧮

1) A two-way table has 2 rows and 6 columns. df=df =

2) Independence test with a 5×35 \times 3 table: df=df =

3) Homogeneity test comparing 4 groups on a categorical variable with 3 levels: Table is 4×34 \times 3. df=df =

Condition Checking 🔍

Exit Quiz — Conditions & Degrees of Freedom ✅

Part 5: Interpreting Results

📊 Interpreting Results

Part 5 of 7 — Reading χ2\chi^2 Output and Drawing Conclusions


Topics in This Part

Section
📐 Interpreting the χ2\chi^2 Statistic
📊 Using the χ2\chi^2 Table
📝 Writing AP Conclusions
🔍 Follow-Up Analysis

🔑 Key Concept: A large χ2\chi^2 value means the observed data differ substantially from what is expected under H0H_0. The p-value tells you how surprising your χ2\chi^2 would be if H0H_0 were true.


What the χ2\chi^2 Value Tells You

χ2\chi^2 ValueInterpretation
Near 0Observed counts closely match expected → little evidence against H0H_0
ModerateSome discrepancy → may or may not be significant
LargeBig differences → strong evidence against H0H_0

The p-value makes this precise: it gives the probability of getting a χ2\chi^2 as large or larger than yours, assuming H0H_0 is true.


Reading the χ2\chi^2 Table

The table gives right-tail areas for the χ2\chi^2 distribution:

dfdfα=0.10\alpha = 0.10α=0.05\alpha = 0.05α=0.025\alpha = 0.025α=0.01\alpha = 0.01
12.7063.8415.0246.635
24.6055.9917.3789.210
36.2517.8159.34811.345
47.7799.48811.14313.277
59.23611.07012.83315.086

How to use: If χ2=8.5\chi^2 = 8.5 with df=3df = 3: 7.815<8.5<9.3487.815 < 8.5 < 9.348, so 0.025<p<0.050.025 < p < 0.05.


AP Conclusion Template

If p≤αp \leq \alpha: "Since the p-value (p=valuep = \text{value}) is less than α=0.05\alpha = 0.05, we reject H0H_0. There is convincing evidence that [state HaH_a in context]."

If p>αp > \alpha: "Since the p-value (p=valuep = \text{value}) is greater than α=0.05\alpha = 0.05, we fail to reject H0H_0. There is not convincing evidence that [state HaH_a in context]."

⚠️ Never say "accept H0H_0" — say "fail to reject H0H_0."


Follow-Up: Which Cells Drive the Result?

After rejecting H0H_0, examine individual cell contributions (Oi−Ei)2/Ei(O_i - E_i)^2/E_i:

ContributionInterpretation
LargeThis category/cell is a major source of the discrepancy
SmallThis category/cell fits the model well

Also note the direction: Is O>EO > E (more than expected) or O<EO < E (fewer than expected)?

Interpretation Concepts 🎯

Using the χ2\chi^2 Table 🧮

Use the partial table above.

1) χ2=6.0\chi^2 = 6.0, df=2df = 2. Is pp less than or greater than 0.05? Enter "less" or "greater".

2) χ2=10.5\chi^2 = 10.5, df=5df = 5. The p-value is between which two table values? Enter the larger α\alpha boundary (e.g., "0.10").

3) For df=1df = 1, what χ2\chi^2 value gives p=0.05p = 0.05?

Conclusion Writing 🔍

Exit Quiz — Interpreting Results ✅

Part 6: Problem-Solving Workshop

📊 Problem-Solving Workshop

Part 6 of 7 — Full AP Free-Response Practice


Topics in This Part

Section
📝 Homogeneity Worked Example
📝 Independence Worked Example
⚠️ Common AP Mistakes

🔑 Key Concept: Chi-square FRQs follow the same 4-step framework: Hypotheses, Conditions, Calculate, Conclude. Practice writing each step clearly.


Worked Example 1: Test for Homogeneity

Problem: 150 volunteers were randomly assigned to one of three study methods (50 each) and then took the same exam:

PassFailTotal
Flashcards321850
Practice tests401050
Rereading272350
Total9951150

Step 1 — Hypotheses: H0H_0: There is no difference in the distribution of exam results (pass/fail) across the three study methods. HaH_a: There is a difference in the distribution of exam results across the three study methods.

Step 2 — Conditions:

  • Random: Volunteers were randomly assigned to methods ✓
  • 10%: Not needed, because the data come from a randomized experiment ✓
  • Expected Counts: Each row expects 50×99150=33\frac{50 \times 99}{150} = 33 passes and 50×51150=17\frac{50 \times 51}{150} = 17 failures. All expected counts are greater than 5 ✓

Step 3 — Calculate: χ2=(32−33)233+(18−17)217+(40−33)233+(10−17)217+(27−33)233+(23−17)217\chi^2 = \frac{(32-33)^2}{33} + \frac{(18-17)^2}{17} + \frac{(40-33)^2}{33} + \frac{(10-17)^2}{17} + \frac{(27-33)^2}{33} + \frac{(23-17)^2}{17}

=0.030+0.059+1.485+2.882+1.091+2.118=7.665,df=(3−1)(2−1)=2= 0.030 + 0.059 + 1.485 + 2.882 + 1.091 + 2.118 = 7.665, \quad df = (3-1)(2-1) = 2

From the table: 7.378<7.665<9.2107.378 < 7.665 < 9.210, so 0.01<p<0.0250.01 < p < 0.025 (technology: p≈0.022p \approx 0.022).

Step 4 — Conclude: Since the p-value is less than α=0.05\alpha = 0.05, we reject H0H_0. There is convincing evidence that the distribution of exam results differs across the three study methods. Because the methods were randomly assigned, we can conclude that the method affects the pass/fail distribution for volunteers like these.

🔍 Follow-up: The Practice tests / Fail cell had the largest contribution (2.882): far fewer failures than expected.


Worked Example 2: Test for Independence

Problem: A random sample of 400 adults records education level and exercise frequency:

≤ 3 days/week> 3 days/weekTotal
No degree12080200
College degree70130200
Total190210400

Step 1 — Hypotheses: H0H_0: Education level and exercise frequency are independent among adults. HaH_a: Education level and exercise frequency are associated among adults.

Step 2 — Conditions:

  • Random: Random sample stated ✓
  • 10%: 400<10%400 < 10\% of all adults ✓
  • Expected Counts: E11=200×190400=95E_{11} = \frac{200 \times 190}{400} = 95, E12=105E_{12} = 105, E21=95E_{21} = 95, E22=105E_{22} = 105. All greater than 5 ✓

Step 3 — Calculate: χ2=(120−95)295+(80−105)2105+(70−95)295+(130−105)2105\chi^2 = \frac{(120-95)^2}{95} + \frac{(80-105)^2}{105} + \frac{(70-95)^2}{95} + \frac{(130-105)^2}{105}

=62595+625105+62595+625105=6.579+5.952+6.579+5.952=25.06= \frac{625}{95} + \frac{625}{105} + \frac{625}{95} + \frac{625}{105} = 6.579 + 5.952 + 6.579 + 5.952 = 25.06

df=(2−1)(2−1)=1df = (2-1)(2-1) = 1. From the table: χ2=25.06>6.635\chi^2 = 25.06 > 6.635 so p<0.01p < 0.01.

Step 4 — Conclude: Since the p-value is less than α=0.05\alpha = 0.05 (in fact less than 0.01), we reject H0H_0. There is convincing evidence of an association between education level and exercise frequency among adults. This is an observational study, so it does not show that education causes more exercise.

⚠️ Common AP Mistakes on Chi-Square FRQs

MistakeFix
Using observed counts for the expected counts checkMust use expected counts, all greater than 5
Forgetting dfdfAlways state dfdf with the formula
Not stating hypotheses in contextName the variable(s) and the population(s), not just "H0H_0: independent"
Saying "accept H0H_0"Say "fail to reject H0H_0"
Confusing independence and homogeneityOne sample with two variables → independence; several samples or groups with one variable → homogeneity
Not showing the χ2\chi^2 formula with substitutionShow ∑(O−E)2/E\sum (O-E)^2/E with at least some terms
Claiming causation from an independence testAssociation ≠ causation (unless randomized experiment)

Workshop Concept Check 🎯

Quick Calculations 🧮

A random sample of 120 adults is classified by age group (row totals: under 40 = 70, 40 and over = 50) and favorite drink (column totals: coffee = 60, tea = 36, neither = 24). The observed count for under 40 / coffee is 42.

1) Expected count for under 40 / coffee?

2) Contribution of that cell, (O−E)2/E(O-E)^2/E?

3) dfdf for this table?

Which Test? 🔍

Exit Quiz — Problem-Solving Workshop ✅

Part 7: Review & Applications

📊 Review & Applications

Part 7 of 7 — Comprehensive Chi-Square Review


Topics in This Part

Section
📋 Both Tests Side-by-Side
📐 Formula & Condition Summary
📝 Mixed Practice

🔑 Key Concept: This review covers the two chi-square tests on the AP exam. Know when to use each, how to check conditions, and how to write full AP-quality solutions.


The Two Chi-Square Tests Compared

FeatureHomogeneityIndependence
SamplesTwo or more independent samples, or treatment groupsOne sample
VariablesOne categorical variableTwo categorical variables
H0H_0No difference in the distribution across populations or treatmentsNo association between the variables in the population
Data formatTwo-way tableTwo-way table
dfdf(r−1)(c−1)(r-1)(c-1)(r−1)(c−1)(r-1)(c-1)

Universal Formula

χ2=∑(observed−expected)2expected\chi^2 = \sum \frac{(\text{observed} - \text{expected})^2}{\text{expected}}

Universal Conditions

ConditionRequirement
RandomRandom sample (independence); independent random samples or randomized experiment (homogeneity)
10%n≤10%n \leq 10\% of the population when sampling without replacement
Expected CountsAll expected counts greater than 5

Expected Counts

E=row total×column totaltable totalE = \frac{\text{row total} \times \text{column total}}{\text{table total}}


Decision Guide: Which Test?

QuestionAnswer
Are two categorical variables related in one population (one sample)?Independence
Is one categorical variable distributed the same way across several groups?Homogeneity
One proportion against a claimed value?One-proportion zz test (not chi-square)
Two groups, a yes/no variable?Two-proportion zz test (a 2×22 \times 2 homogeneity test gives the same conclusion)

Key AP Reminders

  • χ2\chi^2 is always ≥0\geq 0 and the p-value is always a right-tail area
  • The count condition uses expected counts, not observed
  • Never say "accept H0H_0"
  • Association ≠ causation (unless randomized experiment)
  • Show the formula with substitution on FRQs
  • State dfdf explicitly

Comprehensive Concept Check 🎯

Mixed Practice 🧮

1) A two-way table has row total 50, column total 40 and table total 200. Expected count for that cell?

2) Independence test, 3×53 \times 5 table. df=df =

3) χ2=7.5\chi^2 = 7.5, df=2df = 2. From the table (α=0.05\alpha = 0.05: 5.991; α=0.025\alpha = 0.025: 7.378). Is pp less than 0.025? Enter "yes" or "no".

Quick Decisions 🔍

Final Exam — Chi-Square Unit ✅