Welcome, Rookie Detective!
You've just joined the Chi-Square Detective Agency. Every case that lands on your desk involves categories — colors, opinions, schools, sports — and your job is to figure out whether what you observed matches what you expected. Your mentor, Detective M, has three tools in the agency toolkit. Master all three, and you'll earn your badge!
Goodness of Fit
One variable, one sample. Does it match the claimed shape?
Independence
One sample, two variables. Are they connected?
Homogeneity
Several samples, one variable. Are the groups alike?
🧭 Before you start: the shared toolkit
All three tests in this unit use the same weapon: the chi-square statistic. It measures how far your observed counts (O) stray from your expected counts (E). Big difference → big χ² → something suspicious is going on. Small difference → small χ² → the evidence fits the story.
You'll always compare your calculated χ² to a critical value from the chi-square table (based on degrees of freedom and significance level α), or compare the P-value to α. If χ² is bigger than the critical value (or P-value < α), you have enough evidence to reject H₀.
The Candy Bag Caper
A candy factory claims their bags always follow one fixed recipe of colors. A customer suspects the recipe has changed. Only one sample, only one categorical variable — colors. This is a job for the Goodness of Fit test.
🟢 Concept — What are we testing?
Goodness of Fit checks whether one categorical variable from one sample follows a claimed distribution (a set of percentages). Think: "Does reality match the company's recipe card?"
📐 Formula & Degrees of Freedom
🍬 Worked Example
The factory claims a 200-candy bag should be 20% Red, 30% Blue, 25% Green, 25% Yellow. A customer opens a 200-candy bag and counts: Red 30, Blue 50, Green 60, Yellow 60. At α = 0.05, has the recipe changed?
| Color | Claimed % | Expected E | Observed O |
|---|---|---|---|
| Red | 20% | 40 | 30 |
| Blue | 30% | 60 | 50 |
| Green | 25% | 50 | 60 |
| Yellow | 25% | 50 | 60 |
- Hypotheses: H₀: the true color proportions are 20/30/25/25%. Hₛ: at least one proportion differs.
- Compute each term: Red (30−40)²/40 = 2.5 | Blue (50−60)²/60 = 1.667 | Green (60−50)²/50 = 2.0 | Yellow (60−50)²/50 = 2.0
- Sum: χ² = 2.5 + 1.667 + 2.0 + 2.0 = 8.167
- df = 4 categories − 1 = 3
- Critical value at df=3, α=0.05 is 7.815 (from the table)
💡 Plain-English Explanation
Don't panic over the formula — just think of it as a "surprise score." For each color, we ask: "How surprised are we by what we counted, compared to what was promised?" We square the gap so negatives don't cancel positives, then divide by what we expected so a surprise in a small category counts more than the same-size surprise in a big category. Add up all the surprise scores — that's your χ². If the total surprise is bigger than the table's threshold, the claim doesn't hold up.
The Two-Variable Mystery
A school survey collects gender and favorite subject from the same 300 students in one single sample. Detective M asks: "Are these two variables connected, or totally unrelated?" Time for the Test for Independence.
🟢 Concept — What are we testing?
Independence checks whether two categorical variables, measured on one sample, are related to each other or not. Think: "Does knowing someone's gender change your guess about their favorite subject?"
📐 Formula & Degrees of Freedom
🎒 Worked Example
300 students were asked their gender and favorite subject. At α = 0.05, is subject preference independent of gender?
| Math | Art | Science | Total | |
|---|---|---|---|---|
| Male | 40 | 20 | 40 | 100 |
| Female | 30 | 60 | 110 | 200 |
| Total | 70 | 80 | 150 | 300 |
- Hypotheses: H₀: gender and subject preference are independent. Hₛ: they are associated.
- Expected counts (row total × column total ÷ 300):
Male-Math = 23.33, Male-Art = 26.67, Male-Science = 50
Female-Math = 46.67, Female-Art = 53.33, Female-Science = 100 - Terms: 11.91 + 1.67 + 2.00 + 5.95 + 0.83 + 1.00
- Sum: χ² = 23.37
- df = (2−1)(3−1) = 2, critical value at α=0.05 is 5.991
💡 Plain-English Explanation
Imagine gender and subject were totally unrelated — you'd expect the subject percentages to look the same for males and females. The "expected" table shows exactly that imaginary world. Then we compare it to what we actually saw. A big gap means gender and subject really do travel together in real life.
The Triplet Schools Case
Three separate schools each pick their own independent sample of students and ask the same single question: "What's your favorite sport?" Detective M leans in: "Same question, different populations — are they all alike?" This is the Test for Homogeneity.
🟢 Concept — What are we testing?
Homogeneity checks whether several different populations (or groups) share the same distribution of one categorical variable. Think: "Do School A, School B, and School C all like sports in the same proportions?"
Detective's tip: Homogeneity and Independence use the exact same math (same formula, same table layout). The only difference is the story behind the data: Independence = one sample sliced two ways; Homogeneity = several separate samples compared on one variable.
📐 Formula & Degrees of Freedom
⚽ Worked Example
100 students were independently sampled from each of 3 schools and asked their favorite sport. At α = 0.05, do the three schools share the same sport preferences?
| Soccer | Basketball | Baseball | Total | |
|---|---|---|---|---|
| School A | 50 | 30 | 20 | 100 |
| School B | 40 | 40 | 20 | 100 |
| School C | 30 | 50 | 20 | 100 |
| Total | 120 | 120 | 60 | 300 |
- Hypotheses: H₀: all three schools have the same sport-preference distribution. Hₛ: at least one school differs.
- Expected counts (every cell): Soccer = 40, Basketball = 40, Baseball = 20 — same for every school, since each row total is 100.
- Terms: A: 2.5 + 2.5 + 0 | B: 0 + 0 + 0 | C: 2.5 + 2.5 + 0
- Sum: χ² = 10.0
- df = (3−1)(3−1) = 4, critical value at α=0.05 is 9.488
💡 Plain-English Explanation
Picture stacking all 300 students together and pretending school doesn't matter — that gives one "average" sport pattern (40/40/20 per hundred). Then check each school against that average. School B matched perfectly. Schools A and C both leaned Soccer or Basketball more strongly, pulling the total χ² just over the line.
Agency Summary Board
You've cracked all three cases, Detective! Before you collect your badge, review the master comparison board — the exact difference between the three chi-square tools.
📋 The Three Tests, Side by Side
| Feature | Goodness of Fit | Independence | Homogeneity |
|---|---|---|---|
| How many samples? | 1 sample | 1 sample | 2+ separate samples |
| How many variables? | 1 categorical variable | 2 categorical variables | 1 categorical variable |
| Key question | Does it match a claimed model? | Are the two variables related? | Are the groups' distributions the same? |
| Table shape | One row of categories | Two-way (r × c) | Two-way (r × c) |
| df formula | k − 1 | (r−1)(c−1) | (r−1)(c−1) |
| Expected count E | proportion × n | (row total × col total) / grand total | (row total × col total) / grand total |
🧮 The One Formula You Always Need
Big χ² = the data is far from what was expected = reject H₀. Small χ² = the data roughly matches what was expected = fail to reject H₀. Always check conditions first: random sample, independence (10% condition), and every expected count ≥ 5 (Large Counts / Large Sample condition).
🕵️ Detective's Quick-Decision Guide
- One variable + comparing to a claimed percentage breakdown → Goodness of Fit
- Two variables collected from one group of people → Independence
- The same one variable collected from several different groups/populations → Homogeneity
🏅 Case Closed — Badge Earned!
You now hold all three tools of the Chi-Square Detective Agency. Go forth and solve categorical mysteries with confidence!