Chi-Square Tests for Independence and Homogeneity - Complete Interactive Lesson
Part 1: Chi-Square Goodness-of-Fit
๐ Chi-Square Goodness-of-Fit Test
Part 1 of 7 โ Testing Categorical Distributions
When to Use Chi-Square Goodness-of-Fit
Use when you want to test whether observed frequencies match expected frequencies for a categorical variable.
Example: A die is rolled 60 times. Do the results suggest it is fair?
Outcome
1
2
3
4
5
6
Observed
8
12
7
15
9
9
Expected
10
10
10
10
10
10
The Chi-Square Statistic
ฯ2=โEiโ
where Oiโ = observed count and Eiโ = expected count.
For the die example:ฯ2=10(8
Hypotheses
H0โ: The observed distribution matches the expected distribution
Haโ: The observed distribution does NOT match the expected
Conditions
Random sample or random assignment
Expected counts โฅ 5 for all categories
Independence โ observations are independent
๐ Chi-square tests are always right-tailed โ larger ฯ2 values provide more evidence against H0โ.
Goodness-of-Fit Check ๐ฏ
Chi-Square Calculation ๐งฎ
A bag should contain equal numbers of 4 colors. From 80 candies: Red=24, Blue=18, Green=22, Yellow=16.
1) Expected count for each color = 80/4 = ?
2) Compute ฯ2=
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
Feature
Detail
Data source
One sample or one group of subjects
Variables
Two categorical variables measured on each subject
H
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
Feature
Independence
Homogeneity
Samples
One sample
Two or more independent samples
Variables
Two categorical variables
One categorical variable across groups
Part 4: Conditions and Degrees of Freedom
๐ Conditions and Degrees of Freedom
Part 4 of 7 โ When Can You Use the ฯ2 Test?
Topics in This Part
Section
โ Three Conditions
๐ Degrees of Freedom for Each Test
โ ๏ธ What to Do When Conditions Fail
๐ AP Exam Condition-Checking
๐ Key Concept: All three chi-square tests (GoF, Independence, Homogeneity) require the same three conditions: Random, 10%, and Large Counts.
The Three Conditions
Condition
Requirement
AP Language
Random
Data from random sample or randomized experiment
Part 5: Interpreting Results
๐ Interpreting Results
Part 5 of 7 โ Reading ฯ2 Output and Drawing Conclusions
Topics in This Part
Section
๐ Interpreting the ฯ2 Statistic
๐ Using the Table
Part 6: Problem-Solving Workshop
๐ Problem-Solving Workshop
Part 6 of 7 โ Full AP Free-Response Practice
Topics in This Part
Section
๐ GoF 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: Goodness-of-Fit
Problem: A company claims its candy mix is 30% red, 20% blue, 20% green, 15% yellow, 15% orange. A random sample of 200 candies yields:
Color
Red
Blue
Green
Yellow
Orange
Observed
75
35
32
28
30
Expected
60
40
40
30
30
Part 7: Review & Applications
๐ Review & Applications
Part 7 of 7 โ Comprehensive Chi-Square Review
Topics in This Part
Section
๐ All Three Tests Side-by-Side
๐ Formula & Condition Summary
๐ Mixed Practice
๐ Key Concept: This review covers all three chi-square tests. Know when to use each, how to check conditions, and how to write full AP-quality solutions.
Three Chi-Square Tests Compared
Feature
Goodness of Fit
Independence
Homogeneity
Samples
One
One
Two or more
Variables
One categorical
Two categorical
One categorical
(OiโโEiโ)2
โ
โ
10
)2
โ
+
10(12โ10)2โ+
โฏ=
104+4+9+25+1+1โ=
4.4
20
(24โ20)2
โ
+
20(18โ20)2โ+
20(22โ20)2โ+
20(16โ20)2โ
3) Degrees of freedom = kโ1 = ?
0โ
The two variables are independent (not associated)
Haโ
The 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=grandย totalrowย totalรcolumnย totalโโ
This gives the count you would expect if the two variables were truly independent.
Worked Example
Data: A random sample of 200 adults:
Favor
Oppose
Total
Male
60
40
100
Female
45
55
100
Total
105
95
200
H0โ: Gender and opinion are independent. Haโ: Gender and opinion are associated.
Conclusion: Since p=0.034<0.05, we reject H0โ. 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ร2 table?
Independence Test Decisions ๐
Exit Quiz โ Test for Independence โ
H0โ
Variables are independent
Distribution is the same across populations
Calculation
Identical formula: ฯ2=โ(OโE)2/E
Same formula
df
(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.
Conclusion: Since p=0.262>0.05, we fail to reject H0โ. 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)df for this 3ร3 table?
Exit Quiz โ Test for Homogeneity โ
"The problem states..." or "We are told..."
10%
n<10% of the population (if sampling without replacement)
"n is less than 10% of all [population]"
Large Counts
All expected counts โฅ5
"All expected counts are at least 5" โ
โ ๏ธ Critical AP Detail: For chi-square, the Large Counts condition uses expected counts, NOT observed counts. This is different from the Large Counts condition for proportions (np^โโฅ10).
Degrees of Freedom Summary
Test
df Formula
Example
Goodness of Fit
kโ1 (where k = number of categories)
6 sides of a die โ df=5
Independence
(rโ1)(cโ1)
3ร4 table โ df=
Homogeneity
(rโ1)(cโ1)
2ร3 table โ df=
Why Degrees of Freedom Matter
The ฯ2 distribution changes shape with df:
df
Shape
1
Strongly right-skewed
5
Moderately right-skewed
15+
More symmetric
Higher df shifts the distribution to the right and increases the mean (ฮผ=df).
What If Conditions Fail?
Condition
If It Fails
Random
Results may not generalize โ state the limitation
10%
Standard errors may be wrong โ results are questionable
Large Counts
Combine categories or use Fisher exact test (not on AP exam)
๐ AP Tip: On the AP exam, if an expected count is below 5, you should note this but may still be asked to proceed with the test. State the concern and continue.
Conditions & df Concepts ๐ฏ
Degrees of Freedom Practice ๐งฎ
1) GoF test with 8 categories: df=
2) Independence test with a 5ร3 table: df=
3) Homogeneity test comparing 4 groups on a categorical variable with 3 levels: Table is 4ร3. df=
Condition Checking ๐
Exit Quiz โ Conditions & Degrees of Freedom โ
ฯ2
๐ Writing AP Conclusions
๐ Follow-Up Analysis
๐ Key Concept: A large ฯ2 value means the observed data differ substantially from what is expected under H0โ. The p-value tells you how surprising your ฯ2 would be if H0โ were true.
What the ฯ2 Value Tells You
ฯ2 Value
Interpretation
Near 0
Observed counts closely match expected โ little evidence against H0โ
Moderate
Some discrepancy โ may or may not be significant
Large
Big differences โ strong evidence against H0โ
The p-value makes this precise: it gives the probability of getting a ฯ2 as large or larger than yours, assuming H0โ is true.
Reading the ฯ2 Table
The table gives right-tail areas for the ฯ2 distribution:
df
ฮฑ=0.10
ฮฑ=0.05
ฮฑ=0.025
ฮฑ=0.01
1
2.706
3.841
5.024
6.635
2
4.605
5.991
7.378
9.210
3
6.251
7.815
9.348
11.345
4
7.779
9.488
11.143
13.277
5
9.236
11.070
12.833
15.086
How to use: If ฯ2=8.5 with df=3: 7.815<8.5<9.348, so 0.025<p<0.05.
AP Conclusion Template
If pโคฮฑ:
"Since the p-value (p=value) is less than ฮฑ=0.05, we reject H0โ. There is convincing evidence that [state Haโ in context]."
If p>ฮฑ:
"Since the p-value (p=value) is greater than ฮฑ=0.05, we fail to reject H0โ. There is not convincing evidence that [state Haโ in context]."
โ ๏ธ Never say "accept H0โ" โ say "fail to reject H0โ."
Follow-Up: Which Cells Drive the Result?
After rejecting H0โ, examine individual cell contributions (OiโโEiโ)2/Eiโ:
Contribution
Interpretation
Large
This category/cell is a major source of the discrepancy
Small
This category/cell fits the model well
Also note the direction: Is O>E (more than expected) or O<E (fewer than expected)?
Interpretation Concepts ๐ฏ
Using the ฯ2 Table ๐งฎ
Use the partial table above.
1)ฯ2=6.0, df=2. Is p less than or greater than 0.05? Enter "less" or "greater".
2)ฯ2=10.5, df=5. The p-value is between which two table values? Enter the larger ฮฑ boundary (e.g., "0.10").
3) For df=1, what ฯ2 value gives p=0.05?
Conclusion Writing ๐
Exit Quiz โ Interpreting Results โ
Step 1 โ Hypotheses:H0โ: The distribution of colors matches the company claim.
Haโ: The distribution of colors does not match the company claim.
Step 2 โ Conditions:
Random: Random sample stated โ
10%:200<10% of all candies produced โ
Large Counts: All expected counts โฅ5 (smallest is 30) โ
From the table: p is between 0.10 and 0.25 (since 6.108<7.779).
Step 4 โ Conclude:
Since the p-value is greater than ฮฑ=0.05, we fail to reject H0โ. There is not convincing evidence that the distribution of candy colors differs from the company claim.
๐ Follow-up: The red category had the largest contribution (3.75), suggesting there may be more red candies than claimed.
Worked Example 2: Test for Independence
Problem: A random sample of 400 adults records education level and exercise frequency:
โค 3 days/week
> 3 days/week
Total
No degree
120
80
200
College degree
70
130
200
Total
190
210
400
Step 1 โ Hypotheses:H0โ: Education level and exercise frequency are independent.
Haโ: Education level and exercise frequency are associated.
Step 2 โ Conditions:
Random: Random sample stated โ
10%:400<10% of all adults โ
Large Counts: Expected counts: E11โ=400200ร190โ=95, E12โ=105, E21โ=95, E22โ=105. All โฅ5 โ
df=(2โ1)(2โ1)=1. From the table: ฯ2=25.06>6.635 so p<0.01.
Step 4 โ Conclude:
Since the p-value is less than ฮฑ=0.05 (in fact less than 0.01), we reject H0โ. There is convincing evidence of an association between education level and exercise frequency.
โ ๏ธ Common AP Mistakes on Chi-Square FRQs
Mistake
Fix
Using observed counts for the Large Counts check
Must use expected counts
Forgetting df
Always state df with the formula
Not stating hypotheses in context
"H0โ: Color distribution matches claim" not just "H0โ: fit"
Saying "accept H0โ"
Say "fail to reject H0โ"
Confusing independence, homogeneity, and GoF
Read the study design carefully
Not showing the ฯ2 formula with substitution
Show โ(OโE)2/E with at least some terms
Claiming causation from an independence test
Association โ causation (unless randomized experiment)
Workshop Concept Check ๐ฏ
Quick Calculations ๐งฎ
A GoF test: categories A, B, C with observed = 30, 25, 45 and expected = 33.3, 33.3, 33.3 (total = 100, equal proportions).
1) Contribution from category A: (OโE)2/E (round to 2 decimal places)
2) Contribution from category C: (OโE)2/E (round to 2 decimal places)
3)df for this test?
Which Test? ๐
Exit Quiz โ Problem-Solving Workshop โ
H
0โ
Distribution matches model
Variables are independent
Same distribution across groups
Data Format
One-way table
Two-way table
Two-way table
df
kโ1
(rโ1)(cโ1)
(rโ1)(cโ1)
Universal Formula
ฯ2=โEiโ(OiโโEiโ)2โ
Universal Conditions
Condition
Requirement
Random
Random sample or randomized experiment
10%
n<10% of population
Large Counts
All expected counts โฅ5
Expected Counts
Test
How to Calculate E
GoF
Eiโ=nรpiโ (hypothesized proportion)
Independence/Homogeneity
E=grandย totalrowย totalรcolumnย totalโ
Decision Guide: Which Test?
Question
Answer
Does the data fit a specific model?
GoF
Are two variables related (one sample)?
Independence
Same distribution across groups (multiple samples)?
Homogeneity
Key AP Reminders
ฯ2 is always โฅ0 and always right-tailed
Large Counts uses expected counts, not observed
Never say "accept H0โ"
Association โ causation (unless randomized experiment)