Back to the Introduction to Statistics outline The Course Maker
Introduction to Statistics outline
Week 16 · Lecture outline

Week 16 — Lecture Outline · Chi-Square Tests for Categorical Data

Introduction to Statistics Generic evergreen edition

Course: Introduction to Statistics (18-week generic edition)
Objectives covered: Objective 9 — Use chi-square procedures to test claims about categorical data: goodness-of-fit and independence.
SLOs touched: A (reason quantitatively from data) · B (communicate results to a non-technical audience)
Meeting pattern: planned as 2 sessions × ~75 min = ~150 min. Segment minutes below total ~150; scale them to your own pattern.


Week at a Glance

The week's big question "A company claims a mix; your counts don't quite match it. Is the drift ordinary luck — or is the claim wrong? And when two category tables tangle, are the variables actually linked?"
By the end of the week, students can… (1) build a table of expected counts from a claimed distribution (or from independence); (2) compute the chi-square statistic χ² = Σ (O − E)² ⁄ E and its degrees of freedom; (3) run a full goodness-of-fit test by hand and a test of independence with technology assist, checking the conditions first; (4) read the contributions to χ² to say where a table went off-script; (5) state conclusions in careful language ("fail to reject" ≠ "the claim is proven").
Key vocabulary observed count, expected count, chi-square statistic (χ²), contribution to chi-square, goodness-of-fit test, test of independence, degrees of freedom (k − 1 and (r − 1)(c − 1)), critical value, expected-count condition (all expected ≥ 5)
Materials slides (Deck 16), the Week 16 chapter (with the chi-square critical-value mini table), the week's readings + video links, a spreadsheet (Google Sheets or Excel), the student's chatbot for the AI-critique moment and the tutorial
Timing note 8 segments, ~150 min total. Session 1 = Segments 1–4 (~75). Session 2 = Segments 5–8 (~75).

Segment 1 — Hook & the Promise (8 min) · Session 1 opens

Hook (callback to Week 15). "For three weeks we've tested claims about means and proportions — one number at a time. But look at what you actually meet in the wild: a candy company's claimed color mix. A stock plan for T-shirt sizes. A whole table of categories. Open a bag of candy and count the colors — the counts never exactly match the claim. Ever. So when do mismatched counts mean 'ordinary luck,' and when do they mean 'the claim is wrong'?"

  • Hold up the idea: every count-versus-claim argument you've ever had — "this mix is rigged," "this schedule is unbalanced" — is secretly a hypothesis test. This week it gets a machine.
  • One tool handles the whole table at once: the chi-square test (χ², "kai-square" — the Greek letter chi).

The promise (write it on the board): "By the end of this week you can take any table of category counts — colors, sizes, weekdays, pets — measure how far it drifted from a claim with one number, and say whether that drift is luck or evidence."

Why it matters line (memory hook): "One number for the whole table's drift."


Segment 2 — Observed vs. Expected + the Chi-Square Statistic (20 min)

Plain language first. Every chi-square test compares two tables:

  • The observed counts (O) — what you actually counted.
  • The expected counts (E) — what the claim predicts you'd count, on average, in a sample your size.

For a goodness-of-fit setting (one categorical variable vs. a claimed distribution): expected count = n × claimed proportion. Expected counts are long-run averages, so decimals are fine — 22.5 expected is not an error.

The statistic (build it slowly, cell by cell):

χ² = Σ (O − E)² ⁄ E — "for every category: gap, squared, divided by expected — then add them all up."

Why each piece is there (say this out loud):
- O − E: the gap. Positive and negative gaps both matter, and they always sum to zero — which is why we can't just add gaps.
- Squared: kills the canceling, and (like the SD in Week 3) makes big gaps count extra.
- ÷ E: scales the surprise. Being 5 off when you expected 10 is shocking; 5 off when you expected 1,000 is nothing.
- The sum is one number for the whole table — 0 means a perfect match; bigger means more total drift. χ² can never be negative.

One fully worked example (do every step out loud).

A candy company claims its fruit-drop mix is 25% each of red, orange, green, and purple. A quality check counts a 100-candy sample: 30 red, 25 orange, 25 green, 20 purple.
- Expected counts: 100 × 0.25 = 25 of each color.
- Contributions: red (30 − 25)² ⁄ 25 = 25 ⁄ 25 = 1.0 · orange (25 − 25)² ⁄ 25 = 0 · green = 0 · purple (20 − 25)² ⁄ 25 = 25 ⁄ 25 = 1.0.
- χ² = 1.0 + 0 + 0 + 1.0 = 2.0.
So the whole bag's drift from the claim measures 2.0. Big or small? That's the next segment's job — a statistic means nothing until you know what luck alone typically produces.


Segment 3 — Degrees of Freedom, Critical Values & the Verdict (22 min)

Plain language first. Even when the claim is true, random sampling makes χ² bounce above 0. The chi-square distribution describes that luck-only bounce, and it depends on one knob: degrees of freedom — for goodness-of-fit, df = k − 1 (k = number of categories; the last count isn't free once n is fixed).

The course's critical-value mini table (embedded in the chapter, the tutorial, and the assignment coach — any value beyond it, technology supplies):

The table below gives the chi-square critical values used all week: reject H₀ when χ² exceeds the entry.

df Critical value, 5% level Critical value, 1% level
1 3.841 6.635
2 5.991 9.210
3 7.815 11.345
4 9.488 13.277

The test, assembled (the full recipe): ① hypotheses — H₀: the claimed distribution is right; Hₐ: it isn't (some category's true proportion differs) → ② expected counts → ③ check conditions → ④ χ² → ⑤ df → ⑥ compare to the critical value (or read the p-value from technology) → ⑦ conclude in context.

Finish the candy example:

df = 4 − 1 = 3 → 5% critical value 7.815. Our χ² = 2.0 < 7.815fail to reject H₀. The 30/25/25/20 bag is squarely inside ordinary luck — a sample like ours is unsurprising if the mix really is 25/25/25/25. (Technology's p-value: ≈ 0.57 — more than half of honest samples drift at least this much.)
Say the careful sentence: the data are consistent with the claimed mix. We did not prove the mix is 25/25/25/25 — Week 13's rule still runs: fail to reject ≠ accept.

Conditions (check before you trust the verdict):
- Random (or representative) data — Week 1 never stops mattering.
- Counts, not percentages or averages — χ² eats raw counts only.
- Every expected count ≥ 5. Expected, not observed — an observed 0 is legal; an expected 2 is not. Small expected counts make the luck-only distribution misbehave. (Cure: bigger sample, or merge sparse categories.)

Misconception + cure:
- ❌ "χ² = 2.0 on a 10-point scale? Sounds smallish, probably fine" — treating the statistic like a universal score.
Cure: χ² has no fixed scale — what's "big" depends entirely on df. 2.0 is ordinary at df 3; the table (or a p-value) is the only legitimate referee.


Segment 4 — Misconceptions + Think-Pair-Share (25 min) · Session 1 closes (~75)

Name the misconceptions out loud, then cure each:

  • "We failed to reject, so the claimed mix is correct."
    Cure: the test only says the data are compatible with the claim — plenty of other mixes would also survive. Court language helps: not guilty ≠ proven innocent. (Week 13's law, back for its encore.)
  • "My percentages are 30%, 25%, 25%, 20% — I'll run chi-square on 30, 25, 25, 20 as if any sample size works."
    Cure: χ² runs on raw counts; the same percentages from n = 40 and n = 4,000 give wildly different evidence. Percent-washing throws away the sample size — the very thing that powers the test.
  • "Some observed counts are below 5 (even 0), so the test is invalid."
    Cure: the ≥ 5 condition is about expected counts. Observed zeros are data; expected counts are the requirement.
  • "A significant chi-square tells us which category is wrong — or what caused it."
    Cure: χ² is an omnibus alarm: it says the table drifted, not which cell is the culprit (that's what reading contributions is for, next segment) — and never why.
  • "I got χ² = −4; the claim must be extra right."
    Cure: impossible — every term is a square divided by a positive number. A negative χ² means an arithmetic slip, full stop.

Interaction — Think-Pair-Share (rapid-fire, ~12 min). Six quick items on a slide; solo 30 sec, pair 1 min, fingers vote:
1. A goodness-of-fit test has 6 categories. df? → 5
2. n = 120, claimed proportion 25%. Expected count? → 30
3. Can χ² ever be negative? → never (squares)
4. If every observed count equals its expected count, χ² = ? → 0
5. Which counts must all be at least 5 — observed or expected? → expected
6. A 2 × 5 table of two categorical variables: which test, and what df? → independence; df = (2 − 1)(5 − 1) = 4


Segment 5 — Reading the Contributions: Where Did the Table Go Off-Script? (25 min) · Session 2 opens

Hook back in: "Last session the verdict was one number. Today: when the alarm does ring, χ² also tells you where to look — if you read its parts."

Plain language first. Each category's term (O − E)² ⁄ E is its contribution to chi-square. The statistic is their sum, so the biggest contributions are the categories doing the most to set off the alarm. Reading them is how a test becomes a diagnosis.

One fully worked example (do every step out loud).

A hardware store owner claims weekday customer traffic is even across Mon–Fri, and staffs the register identically each day. A 200-receipt sample: Mon 28, Tue 34, Wed 38, Thu 44, Fri 56.
- Expected: 200 ÷ 5 = 40 per day. Conditions: random receipts, counts, all E = 40 ≥ 5. ✓
- Contributions: Mon (28−40)²⁄40 = 144⁄40 = 3.6 · Tue 36⁄40 = 0.9 · Wed 4⁄40 = 0.1 · Thu 16⁄40 = 0.4 · Fri 256⁄40 = 6.4.
- χ² = 3.6 + 0.9 + 0.1 + 0.4 + 6.4 = 11.4, df = 5 − 1 = 4.
- Verdict: 11.4 > 9.488reject at the 5% level. (But 11.4 < 13.277 — at the strict 1% bar this evidence wouldn't clear. Technology's p ≈ 0.022: significance lives on a dial, not a switch — Week 13's α conversation, still alive.)
- Now read the contributions: Fri (6.4) and Mon (3.6) carry 10 of the 11.4 — Fri runs hot, Mon runs quiet, midweek is on-script. The action isn't "panic about every day"; it's "re-staff Fri and Mon."

Misconception + cure:
- ❌ "Fri had the biggest count, so it's automatically the biggest problem."
Cure: contributions rank surprise, not size — a big count near its expected value contributes almost nothing, and a modest count far from expectation can top the list. Rank by (O − E)² ⁄ E, never by O.


Segment 6 — The Test of Independence: Two Variables, One Table (25 min)

Plain language first (callback to Week 4). Week 4 taught you to describe a two-way table — marginal and conditional distributions, "is there an association?" by eye. Today the eyeball question grows up: test of independence — H₀: the two categorical variables are independent (no association); Hₐ: they are associated.

Where do expected counts come from with no claimed mix? From independence itself: if the variables were unrelated, each cell should hold its row's share of its column:

Expected cell count = (row total × column total) ⁄ grand total

One fully worked example (do every step out loud).

A city survey of 200 residents records pet type and housing type:

The two-way table below shows the observed counts (row totals at right).

Observed House Apartment Total
Dog 72 48 120
Cat 28 52 80
Total 100 100 200
  • Expected, dog–house: (120 × 100) ⁄ 200 = 60. Same machinery fills the rest: dog–apartment 60, cat–house 40, cat–apartment 40. (All ≥ 5 ✓.) In practice software builds this table — your job is to know where one cell comes from and to read the result.
  • Contributions: dog–house (72−60)²⁄60 = 144⁄60 = 2.4 · dog–apt 2.4 · cat–house (28−40)²⁄40 = 144⁄40 = 3.6 · cat–apt 3.6.
  • χ² = 2.4 + 2.4 + 3.6 + 3.6 = 12.0 · df = (r − 1)(c − 1) = (2 − 1)(2 − 1) = 1.
  • Verdict: 12.0 > 3.841 (5%) and > 6.635 (1%) → reject H₀ emphatically (technology's p ≈ 0.0005). Pet type and housing type are associated: dog owners tilt toward houses, cat owners toward apartments.

The guardrail (louder than the result): associated, not caused. This is a survey — nobody assigned pets or housing. A confounder (yard space, building rules, household size) can drive both. Chi-square inherits every Week 1 warning about observational data. Memory hook: "χ² can convict the table, never the cause."

df intuition (one line): in an r × c table with margins fixed, only (r − 1)(c − 1) cells are free — fill those and the margins dictate the rest.


Segment 7 — Which Chi-Square Is It? (Choosing the Right Test) (13 min)

Plain language first. Both tests share the same engine — expected counts, Σ (O − E)² ⁄ E, a df, a critical value. They differ only in the question:

  • One categorical variable vs. a claimed distributiongoodness-of-fit, df = k − 1. ("Does this candy mix match the label?" "Are visits even across weekdays?")
  • Two categorical variables, one sample, "are they linked?" → independence, df = (r − 1)(c − 1). ("Is pet type associated with housing type?")

The updated which-tool ladder (build it with the class — Weeks 11–16 in one breath):
- Question about a mean → t procedures (Weeks 11, 14).
- Question about a proportion (one or two) → z procedures (Weeks 12, 15).
- Question about counts across categories — one variable vs. a claim, or two variables linked → chi-square (this week).

Quick mini-drill (call-and-response): "Counts of 4 T-shirt sizes vs. the warehouse's stock plan?" → GoF, df 3. "Pet type × housing type from one survey?" → independence. "Mean delivery time vs. a promised 30 minutes?" → one-sample t — not everything is chi-square; if it's an average, the counts machine doesn't apply.


Segment 8 — Technology Workflow + AI-Critique, Callback & Hand-off (12 min) · Session 2 closes (~75)

Technology workflow (exact steps, live in a spreadsheet):
1. Observed counts from raw category data: =COUNTIFS(A:A,"Dog",B:B,"House") counts the rows in that cell of the table — four formulas build the whole 2 × 2. (Google Sheets and Excel are identical here; a pivot table does the same job.)
2. Expected counts by formula: for the top-left cell, =(row total × column total)/grand total with cell references — then fill across the table.
3. The p-value in one cell: =CHISQ.TEST(observed_range, expected_range) returns the p-value directly — for the pet table it displays ≈ 0.0005, matching our by-hand reject.
4. Beyond the mini table: =CHISQ.DIST.RT(11.4, 4)≈ 0.022 (the right-tail p-value for the hardware-store test) and =CHISQ.INV.RT(0.05, 4)9.488 — the software regenerates our critical-value table on demand.

AI-critique moment (students verify, not consume):

Paste this to your chatbot: "For a chi-square test on a 3 × 3 two-way table, what are the degrees of freedom, and what is the 5% critical value?"
Then check it against the mini table: df = (3 − 1)(3 − 1) = 4 and the critical value is 9.488. Chatbots regularly answer df = 8 (counting 9 cells minus 1) and mis-quote table values from memory. The tool drafts, you judge — and this exact check is your first move in Data Lab 16.

Callback + tease:
- Callback: "Week 4 taught you to describe a two-way table; Week 13 taught you what a verdict means; this week the two finally met — the describing table got its own test."
- Tease next week: "One tool left: Week 17 puts a line through a scatterplot and tests its slope — regression with inference, the last piece of the toolkit — and then the cumulative final caps the story. (The final's study guide, practice exam, and exam-prep tutorial live in the Week 18 module.)"

Hand-off (the week's work):
- Chapter 16 (primary reading, with the critical-value mini table) — then Lecture Tutorial 16 (AI tutor; share link + summary).
- Data Lab 16 (penguins: species × island, one giant chi-square) · Quiz 16 (end of week) · Discussion 16 ("Rigged, or Random?") · Assignment 16 (AI-coached).


Instructor FAQ — Common Stumbles

Student says / does Quick cure
"We failed to reject — so the company's mix is confirmed." The test says consistent with, never confirmed — many other mixes would also survive. Not guilty ≠ innocent.
Runs χ² on percentages ("30, 25, 25, 20 — done"). χ² eats raw counts; percents amputate the sample size. 30% of 40 and 30% of 4,000 are different amounts of evidence.
"There's a 0 in my observed table — test's broken." Zeros are legal observed values. The ≥ 5 condition polices expected counts only.
Uses df = number of cells − 1 for a two-way table. GoF: df = k − 1. Independence: df = (r − 1)(c − 1) — a 3 × 3 has df 4, not 8. Fix the margins and count the free cells.
Reports a negative χ². Impossible — squares over positive E. Hunt the arithmetic slip (usually a subtraction typed backwards or a missing square).
"The biggest observed count is the problem category." Rank by contribution (O − E)² ⁄ E, not by O — surprise, not size.
"Significant association, so X causes Y." Chi-square on survey data inherits every observational-study warning: association, confounders possible, no causal arrow. (Week 1 never left.)
"My χ² = 6 — is that big?" No universal scale: 6 rejects at df 1 (3.841) and doesn't at df 3 (7.815). The df + table (or p-value) is the only referee.

Scope flag

This outline stays within Objective 9 (goodness-of-fit fully by hand; independence at technology-assist depth, per the course profile). The df intuition ("free cells with fixed margins"), the p-values quoted beside table verdicts, and the which-tool ladder consolidation are added context (not strictly required by the objective) — kept because they cure this week's misconceptions and set up the Week 17 synthesis; cut them for a leaner session. The chi-square test of homogeneity and tests for variance are deliberately out of scope.