Carrying Out a Two-Way Chi-Square Test
Introduced
7:48
Inference for Categorical Data: Chi-Square
Roll a fair die sixty times. Every face should come up ten times. But it never does — eight here, thirteen there. The gaps are always there. So roll another…
English narration · English and 中文 subtitles you can switch
In this lesson
| English | Meaning |
|---|---|
| chi-square test for a two-way table | |
| test for homogeneity/test fɔː ˈhɒməʊdʒneɪti/ | A chi-square test of whether several populations share one distribution. |
| test for independence/test fɔː ˌɪndɪˈpendəns/ | A chi-square test of whether two variables are associated in one population. |
Do younger and older adults get news differently?
- A media company takes independent random samples of 100 adults under 40 and 100 adults aged 40 or older in a city, and asks each person's main news source:
| TV | Online | Total | ||
|---|---|---|---|---|
| Under 40 | 20 | 70 | 10 | 100 |
| Aged 40+ | 40 | 45 | 15 | 100 |
| Total | 60 | 115 | 25 | 200 |
- The two groups look different, but could a gap this large happen by chance? A chi-square test for a two-way table 双向表卡方检验 answers this.

Homogeneity or independence?
- Two or more separate samples, one variable compared → test for homogeneity 同质性检验. $H_0$: the distribution of the variable is the same for every population. Our news survey is homogeneity: two age-group samples, one variable (news source).
- One sample, two variables recorded for each person → test for independence 独立性检验. $H_0$: there is no association between the two variables. The mechanics (expected counts, $\chi^2$, df) are identical; only the hypotheses and conclusion wording change.
A school surveys one random sample of 300 students and records each student's year group and favourite sport. Which test fits?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
One sample with two categorical variables per student → independence. Separate samples from each year group would be homogeneity.
Worked test: State and Plan
State. $H_0$: the distribution of main news source is the same for adults under 40 and adults aged 40 or older in this city. $H_a$: the distributions differ. $\alpha=0.05$.
Plan. Chi-square test for homogeneity.
- Random: independent random samples from each age group.
- 10%: 100 is less than 10% of each age group in the city.
- Large counts: expected count $=\dfrac{\text{row total}\times\text{column total}}{\text{table total}}$. Each row total is 100, so the expected counts are $\frac{100\times60}{200}=30$, $\frac{100\times115}{200}=57.5$, $\frac{100\times25}{200}=12.5$ in each row; all at least 5.
In a two-way table with total 400, a row total is 160 and a column total is 90. Find the expected count for that cell.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
(row total × column total) ÷ table total = 160 × 90 ÷ 400 = 36.
Worked test: Do and Conclude
Do. For each of the six cells, work out $\frac{(\text{O}-\text{E})^2}{\text{E}}$. For example, under 40 and TV: $\frac{(20-30)^2}{30}=3.33$.
| TV | Online | ||
|---|---|---|---|
| Under 40 | 3.33 | 2.72 | 0.50 |
| Aged 40+ | 3.33 | 2.72 | 0.50 |
$\chi^2\approx13.10$, $df=(2-1)(3-1)=2$, p-value $=P(\chi^2_2\ge13.10)\approx0.0014$.
Conclude. Because $0.0014<0.05$, we reject $H_0$. There is convincing evidence that the distribution of main news source differs between adults under 40 and adults aged 40 or older in this city.
With χ² = 6.0 at df = 1, the p-value ≈ 0.014. At α = 0.05, the decision is...
Difficulty 1/5 · 100 coins + a small bonus on first completion today
0.014 ≤ 0.05 → reject H0.
The p-value for a two-way chi-square test is a right-tail area.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Chi-square is always right-tailed.
For a 3×4 two-way table, find the degrees of freedom (r−1)(c−1).
Difficulty 2/5 · 140 coins + a small bonus on first completion today
(3−1)(4−1) = 2×3 = 6.
Follow-up: where is the difference?
- The largest terms are the TV cells (3.33 each): adults 40+ chose TV more than expected (40 vs 30), and younger adults less (20 vs 30). Online is next.
- Say this with observed vs expected counts, in context. The chi-square test itself says only that the distributions differ, not how.
In the news-source test, which statement best describes the difference between the age groups?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The TV cells give the largest terms (3.33 each). Observational data show a difference, not a cause.
Wording the conclusion
- Homogeneity, reject: "convincing evidence that the distribution of [variable] differs between [populations]". Independence, reject: "convincing evidence of an association between [variable 1] and [variable 2] among [population]".
- Fail to reject: "not convincing evidence…". Never "the groups are the same" or "the variables are independent": failing to reject does not prove $H_0$.
Rejecting H0 in a test of INDEPENDENCE means...
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Independence: reject → the variables are associated.
Rejecting H0 in a test of HOMOGENEITY means...
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Homogeneity: reject → the group distributions differ.
A chi-square test for independence of "owns a pet" and "exercises daily" in a random sample of adults gives p = 0.31 (α = 0.05). Write the conclusion.
A large p-value means weak evidence, not proof of independence.
How an FRQ is scored
- Correct test named (homogeneity vs independence chosen from the design) and hypotheses in context.
- Conditions: random, 10%, and expected counts (shown, or "all expected counts at least 5" with the smallest one given).
- Mechanics: $\chi^2$, df $=(r-1)(c-1)$, p-value.
- Conclusion comparing p with $\alpha$, in context, with wording that matches the test.
- The design decides the test, not the table. The same table could come from one sample (independence) or several samples (homogeneity).
- df uses rows and columns of categories, not the totals row or column: a $2\times3$ table has $df=2$.
- Expected counts are usually not whole numbers (57.5 is fine). Never round them to make the check pass.
A two-way chi-square test compares observed and expected counts in every cell: $\chi^2=\sum\frac{(\text{O}-\text{E})^2}{\text{E}}$, with $\text{E}=\frac{\text{row total}\times\text{column total}}{\text{table total}}$ and $df=(r-1)(c-1)$; the p-value is the right-tail area. Several samples → homogeneity (distributions differ?); one sample, two variables → independence (association?). Conclude in context and use the largest terms to say where the difference lies.
What went wrong? Only the site team sees this.