In Lesson 24 you ran a chi-square test for homogeneity: you took several separate samples — one from each of several populations — and asked whether one categorical variable was distributed the same way across all of them.
Now picture a different study. A researcher takes one random sample of 350 college students and, for each student, records two things: how much caffeine they consume (None, Moderate, High) and the quality of their sleep (Good, Poor). Nobody was sorted into groups in advance — every student is just one dot, tagged on two variables at once.
The question changes too. It is no longer "are these groups the same?" It is "are these two variables associated?" Does caffeine level go with sleep quality, or are they unrelated?
Here is the beautiful part: the arithmetic is identical to homogeneity. Same expected counts, same χ² formula, same degrees of freedom, same calculator routine. What changes is the design, the hypotheses, and the conclusion. Let's see exactly how.
Use the chi-square (χ²) test for independence when:
Contrast that with last lesson: homogeneity used several samples (several populations) and one categorical variable. Same math, different design — we'll nail this down in a comparison box below.
The data live in a two-way table (also called a contingency table). Here is our caffeine-and-sleep sample of 350 students:
| Good sleep | Poor sleep | **Row total** | |
|---|---|---|---|
| No caffeine | 60 | 40 | 100 |
| Moderate | 90 | 60 | 150 |
| High caffeine | 30 | 70 | 100 |
| Column total | 180 | 170 | 350 |
Notice there is just one grand total (350) — one sample, split two ways. That single-sample structure is the fingerprint of an independence test.
The hypotheses are stated in terms of association, not proportions:
There is always exactly one χ² alternative, and it is always two-sided in spirit — "associated" — never "greater than."
If the two variables were truly independent, the proportion with poor sleep should be the same regardless of caffeine level. We turn that idea into expected counts with the same formula from Lesson 24:
E = (row total × column total) / grand total
Let's fully work the cell for No caffeine + Good sleep:
E = (row total × column total) / grand total
E = (100 × 180) / 350
E = 18000 / 350
E = 51.43
So if caffeine and sleep were unrelated, we'd expect about 51.43 of these students to be no-caffeine/good-sleep. We actually observed 60. Filling in every cell:
| Good sleep (E) | Poor sleep (E) | |
|---|---|---|
| No caffeine | 51.43 | 48.57 |
| Moderate | 77.14 | 72.86 |
| High caffeine | 51.43 | 48.57 |
The test statistic measures how far the observed counts (O) stray from the expected counts (E):
χ² = Σ (O − E)² / E
Compute the contribution of a few cells so you see the machinery:
No caffeine / Good: (60 − 51.43)² / 51.43 = (8.57)²/51.43 = 1.43
High caffeine / Poor: (70 − 48.57)² / 48.57 = (21.43)²/48.57 = 9.45
That High/Poor cell contributes a huge 9.45 — heavy caffeine users had far more poor sleep than independence predicts. Adding all six contributions:
1.43 + 1.51 + 2.14 + 2.27 + 8.93 + 9.45 = 25.74
χ² = 25.74
Degrees of freedom depend only on the shape of the table:
df = (r − 1)(c − 1) = (3 − 1)(2 − 1) = 2
The p-value is the upper-tail area of the χ² distribution — large χ² means strong evidence, so we always look to the right:
TI-84: χ²cdf(25.74, 1E99, 2) = 0.0000026 (≈ 2.6 × 10⁻⁶)
p ≈ 0.0000026 is far below α = 0.05, so we reject H₀. There is very strong evidence of an association between caffeine consumption and sleep quality among college students.
Crucial wording: we found an association, not a cause. This was observational data — we cannot conclude that caffeine causes poor sleep. Poor sleepers might reach for more caffeine, or a lurking variable (stress, late-night study) could drive both.
SAME ARITHMETIC. DIFFERENT DESIGN.
| | Homogeneity (L24) | Independence (L25) |
|---|---|---|
| How many samples? | Several samples / several populations | ONE sample / one population |
| How many variables? | ONE categorical variable | TWO categorical variables |
| The question | Is the distribution the same across groups? | Are the two variables associated? |
| H₀ | Distributions are the same across populations | The two variables are independent |
| Hₐ | At least one distribution differs | The two variables are associated |
| Margins fixed? | Row (or column) totals fixed by the researcher | Only the grand total is fixed |
| Expected counts |
(row × col)/grand|(row × col)/grand← identical || Statistic / df / p |
χ²=Σ(O−E)²/E,(r−1)(c−1), χ²cdf | identical |Decision rule: Did the researcher take one sample and measure two things (independence), or take several separate samples and measure one thing (homogeneity)?
On the TI-84 both tests use the same χ²-Test command — the calculator does not know or care which design you have. The distinction lives entirely in your hypotheses and conclusion.
[B], never the observed counts.)Problem. A campus survey randomly samples 250 students and classifies each by pet ownership (Dog, Cat, None) and whether they exercise regularly (Yes, No). Find the expected count for Dog owners who exercise, and verify all conditions for the large-counts requirement.
| Exercise: Yes | Exercise: No | Row total | |
|---|---|---|---|
| Dog | 45 | 55 | 100 |
| Cat | 30 | 20 | 50 |
| None | 25 | 75 | 100 |
| Col total | 100 | 150 | 250 |
Solution.
E(Dog, Yes) = (100 × 100) / 250 = 10000/250 = 40
Full expected-count table:
| Yes (E) | No (E) | |
|---|---|---|
| Dog | 40 | 60 |
| Cat | 20 | 30 |
| None | 40 | 60 |
Interpretation. Every expected count (40, 60, 20, 30, 40, 60) is ≥ 5, so the Large Counts condition is satisfied. We could proceed to compute χ² with df = (3−1)(2−1) = 2.
Problem. A media company takes a random sample of 600 social-media users and records each user's preferred platform (Instagram, TikTok, YouTube) and age group (Teen, Adult). Is there an association between platform preference and age group? Test at α = 0.05.
| Teen | Adult | Row total | |
|---|---|---|---|
| 120 | 80 | 200 | |
| TikTok | 150 | 50 | 200 |
| YouTube | 80 | 120 | 200 |
| Col total | 350 | 250 | 600 |
P — Parameter / hypotheses.
A — Assumptions / conditions.
Expected counts E = (row × col)/grand, e.g. E(Instagram, Teen) = (200×350)/600 = 116.67:
| Teen (E) | Adult (E) | |
|---|---|---|
| 116.67 | 83.33 | |
| TikTok | 116.67 | 83.33 |
| YouTube | 116.67 | 83.33 |
N — Name the procedure. Chi-square (χ²) test for independence.
I — Inference (compute).
A couple of contributions:
TikTok / Teen: (150 − 116.67)² / 116.67 = (33.33)²/116.67 = 9.52
YouTube/ Adult: (120 − 83.33)² / 83.33 = (36.67)²/ 83.33 = 16.13
Summing all six contributions:
χ² = 0.10 + 0.13 + 9.52 + 13.33 + 11.52 + 16.13 = 50.74
df = (3 − 1)(2 − 1) = 2
p-value = χ²cdf(50.74, 1E99, 2) ≈ 9.6 × 10⁻¹²
TI-84: [A] = 3×2 matrix of counts → STAT → TESTS → χ²-Test
Output: χ² = 50.743, p = 9.58E-12, df = 2 (expected counts stored in [B])
C — Conclusion in context. Because p ≈ 9.6 × 10⁻¹² < 0.05, we reject H₀. There is very strong evidence of an association between preferred platform and age group among social-media users. (Because this is observational, we do not claim age causes platform choice.)
Problem. A small study randomly samples 80 gamers and classifies each by favorite genre (Action, Strategy) and primary device (Console, PC). Confirm the conditions, find df, and identify which cell contributes most to χ².
| Console | PC | Row total | |
|---|---|---|---|
| Action | 25 | 15 | 40 |
| Strategy | 10 | 30 | 40 |
| Col total | 35 | 45 | 80 |
Solution. Expected counts (e.g. E(Action,Console) = (40×35)/80 = 17.5):
| Console (E) | PC (E) | |
|---|---|---|
| Action | 17.5 | 22.5 |
| Strategy | 17.5 | 22.5 |
All expected counts (17.5, 22.5, 17.5, 22.5) ≥ 5 ✓; one random sample ✓; 80 ≤ 10% of all gamers ✓.
Cell contributions (O−E)²/E:
Action/Console: (25−17.5)²/17.5 = 3.21
Action/PC: (15−22.5)²/22.5 = 2.50
Strategy/Console: (10−17.5)²/17.5 = 3.21
Strategy/PC: (30−22.5)²/22.5 = 2.50
χ² = 3.21 + 2.50 + 3.21 + 2.50 = 11.43
df = (2−1)(2−1) = 1
p-value = χ²cdf(11.43, 1E99, 1) ≈ 0.0007
Interpretation. The two Console cells (each 3.21) contribute most, signaling that the genre–device mismatch is biggest there: Action players gravitate to Console more, Strategy players to PC, more than independence would predict. With p ≈ 0.0007 < 0.05, reject H₀ — genre and device are associated.
Problem. For each scenario, decide whether a χ² test for independence or homogeneity is appropriate.
Solution.
Interpretation. The tell is always: one sample with two variables → independence; several preset samples with one variable → homogeneity. The χ² arithmetic is the same either way.
1. Confusing the independence setup with homogeneity.
Wrong: writing H₀ as "the distributions are the same across groups" for a one-sample, two-variable study.
Right: an independence test has one sample classified on two variables. State H₀ as "the two variables are independent (not associated) in the population." If you see several preset sample sizes, it's homogeneity instead.
2. Using percentages or proportions instead of raw counts.
Wrong: entering 0.60, 0.40, … into matrix [A], or computing expected counts from percentages.
Right: χ² procedures require raw frequency counts. Convert any percentages back to counts first; expected counts ≥ 5 is a count condition.
3. Getting degrees of freedom wrong.
Wrong: df = n − 1, or df = (number of cells) − 1.
Right: df = (r − 1)(c − 1) using the number of rows and columns of the table, not the sample size. A 3×2 table gives df = 2, every time, regardless of n.
4. Claiming causation from an association.
Wrong: "Caffeine causes poor sleep." A significant χ² in observational data shows the variables are associated, not that one causes the other.
Right: "There is an association between caffeine consumption and sleep quality." Reserve causal language for randomized experiments.
5. Checking the observed counts instead of the expected counts.
Wrong: declaring the Large Counts condition met because all observed counts ≥ 5.
Right: the condition is on expected counts (matrix [B] on the TI-84). Observed counts can be small as long as every expected count is ≥ 5.
MC = 4 choices. Answers and full work in section (g).
1 (MC). A χ² test for independence requires:
A. Several independent random samples, one categorical variable
B. One random sample, two categorical variables
C. Two quantitative variables from one sample
D. A randomized experiment with two treatment groups
2 (MC). A two-way table has 4 rows and 3 columns. The degrees of freedom are:
A. 12 B. 11 C. 7 D. 6
3 (MC). In a 2×2 table, a row total is 80, a column total is 120, and the grand total is 200. The expected count for that cell is:
A. 32 B. 40 C. 48 D. 60
4 (MC). For a χ² test for independence, the p-value is found with:
A. χ²cdf(0, χ², df)
B. χ²pdf(χ², df)
C. χ²cdf(χ², 1E99, df)
D. 2 × χ²cdf(χ², 1E99, df)
5 (MC). A χ² test for independence on observational data yields p = 0.003. The best conclusion is:
A. One variable causes a change in the other
B. The variables are associated; no causal claim is justified
C. The variables are independent
D. The sample was too small to conclude anything
6 (MC). Which is the correct H₀ for a χ² test for independence?
A. The proportions are equal across all populations
B. The two variables are independent in the population
C. The two variables are associated in the population
D. The mean is the same in each group
7 (MC). Which study calls for a χ² test for independence (not homogeneity)?
A. Separate samples of 100 men and 100 women, each asked their favorite sport
B. One random sample of 250 people, each classified by region and vote choice
C. Comparing the mean income of three cities
D. A single proportion compared to 0.5
8 (MC). All of a table's observed counts exceed 5, but one expected count is 3.8. The Large Counts condition is:
A. Met, because observed counts matter
B. Met, because 3.8 rounds to 4
C. Not met, because all expected counts must be ≥ 5
D. Irrelevant for χ² tests
9 (Short answer). A random sample of 400 employees is classified by department (Sales, Engineering, Support) and whether they work remotely (Yes, No). Researchers want to know if department and remote-work status are associated. State H₀, Hₐ, the name of the procedure, and the degrees of freedom.
10 (Short answer · in context). A χ² test for independence on a random sample of patients gives χ² = 14.2, df = 3, p = 0.0027. The two variables are diet type and presence of a certain health condition. Write a complete conclusion in context at α = 0.05, and explain why a doctor should not tell patients that one diet "causes" the condition.
11 (Short answer · in context). A school randomly samples 300 students and records each student's grade level (9, 10, 11, 12) and primary mode of getting to school (Bus, Car, Walk). For the cell "Grade 9 / Bus," the row total is 90, the column total is 100, and the grand total is 300. Compute the expected count and state what it represents.
12 (Short answer). Explain in one or two sentences how you decide, just from a study's design, whether to run a test for independence or a test for homogeneity.
Statistical Practices 3 (Analyze Data) & 4 (Interpret Results)
A public-health researcher takes a single random sample of 350 adults from a large city. Each adult is classified by whether they regularly drink coffee (Yes, No) and how often they report headaches (Rare, Occasional, Frequent). The results:
| Rare | Occasional | Frequent | Row total | |
|---|---|---|---|---|
| Coffee: Yes | 50 | 90 | 60 | 200 |
| Coffee: No | 70 | 50 | 30 | 150 |
| Col total | 120 | 140 | 90 | 350 |
Do these data provide convincing evidence of an association between coffee drinking and headache frequency among adults in this city? Conduct an appropriate test at the α = 0.05 level. (10 points)
P — Parameter / Hypotheses (in context).
A — Assumptions / Conditions.
Expected counts, E = (row × col)/grand:
E(Yes, Rare) = (200 × 120)/350 = 68.57
E(Yes, Occasional) = (200 × 140)/350 = 80.00
E(Yes, Frequent) = (200 × 90)/350 = 51.43
E(No, Rare) = (150 × 120)/350 = 51.43
E(No, Occasional) = (150 × 140)/350 = 60.00
E(No, Frequent) = (150 × 90)/350 = 38.57
All six are ≥ 5. ✓
N — Name the procedure. Chi-square (χ²) test for independence.
I — Inference (test statistic, df, p-value).
χ² = Σ(O − E)²/E
= (50−68.57)²/68.57 + (90−80)²/80 + (60−51.43)²/51.43
+ (70−51.43)²/51.43 + (50−60)²/60 + (30−38.57)²/38.57
= 5.03 + 1.25 + 1.43 + 6.71 + 1.67 + 1.90
= 17.99
df = (2 − 1)(3 − 1) = 2
p-value = χ²cdf(17.99, 1E99, 2) ≈ 0.00012
TI-84: [A] = 2×3 matrix → STAT → TESTS → χ²-Test
Output: χ² = 17.986, p = 1.243E-4, df = 2
C — Conclusion in context. Because p ≈ 0.00012 < α = 0.05, we reject H₀. There is convincing evidence of an association between coffee-drinking status and headache frequency among adults in this city. Because the data are observational, we cannot conclude that coffee drinking causes a change in headache frequency.
| Pts | Component | Earned for… |
|---|---|---|
| 1 | Hypotheses stated correctly | H₀ = independent / Hₐ = associated (not "proportions equal") |
| 1 | Hypotheses in context | references coffee & headaches for this city's adults |
| 1 | Procedure named | "χ² test for independence" (not homogeneity, not GOF) |
| 1 | Random condition | identifies one random sample of 350 adults |
| 1 | 10% + Large Counts conditions | states n ≤ 10% and all expected counts ≥ 5 |
| 1 | Expected counts | at least one expected count correctly computed (or all shown) |
| 1 | χ² statistic | χ² ≈ 17.99 (consistent with their expected counts) |
| 1 | Degrees of freedom | df = (2−1)(3−1) = 2 |
| 1 | p-value | p ≈ 0.00012 from χ²cdf(17.99, 1E99, 2) |
| 1 | Conclusion in context | reject H₀ and "evidence of association … in this city," linked to p < α |
Where students lose points.
df = n − 1 = 349 or df = 5 (cells − 1) instead of (r−1)(c−1) = 2.p < α.1. B. An independence test = one sample, two categorical variables.
- A: that describes homogeneity. C: χ² is for categorical, not quantitative variables. D: a two-group experiment with one categorical response is a homogeneity-style setup, not independence.
2. D — 6. df = (r−1)(c−1) = (4−1)(3−1) = 3 × 2 = 6.
- A (12) = r×c. B (11) = rc − 1. C (7) = (r−1)(c−1)+1, a slip.
3. C — 48. E = (row × col)/grand = (80 × 120)/200 = 9600/200 = 48.
- A (32) divides by the wrong total. B (40), D (60) = arithmetic slips.
4. C. χ² is always upper-tail: χ²cdf(χ², 1E99, df).
- A finds the lower tail. B gives a density height, not an area. D double-counts — χ² is not symmetric and is not doubled.
5. B. A significant result on observational data shows association, never causation.
- A claims causation. C contradicts a small p-value. D is wrong — a small p-value did let us conclude.
6. B. H₀ for independence: the two variables are independent.
- A is homogeneity's H₀. C is the alternative Hₐ, not H₀. D is a means test.
7. B. One random sample (250), two variables (region, vote) → independence.
- A: two separate samples, one variable → homogeneity. C: comparing means → ANOVA-style, not χ². D: one proportion → z-test.
8. C. The Large Counts condition is on expected counts; 3.8 < 5 fails it.
- A, B, D all misstate or dismiss the actual condition.
9. H₀: department and remote-work status are independent among the company's employees. Hₐ: they are associated. Procedure: χ² test for independence. df = (3 − 1)(2 − 1) = 2.
10. Because p = 0.0027 < 0.05, reject H₀: there is convincing evidence of an association between diet type and the presence of the health condition among patients like those sampled. Because the data are observational (patients were not randomly assigned a diet), a lurking variable could explain the link, so we cannot conclude that any diet causes the condition — only that the two are associated.
11. E = (90 × 100)/300 = 9000/300 = 30. If grade level and mode of transportation were independent, we would expect about 30 of the 300 students to be Grade 9 bus-riders.
12. Look at how the data were collected: if the researcher took one sample and recorded two categorical variables on each individual, use a test for independence; if the researcher took several separate samples (preset group sizes) and recorded one categorical variable, use a test for homogeneity. The χ² arithmetic is identical; only the design, hypotheses, and conclusion differ.
StatsIQ · Lesson 25 of 30 · Unit 3: Inference for Categorical Data — Proportions · Phase 5: Chi-Square & Inference for Means
This material is independent study content and is not endorsed by or affiliated with the College Board, which administers the AP® Statistics exam. AP® is a registered trademark of the College Board.
Content pending statistical-accuracy review (Isaac).