Chi-Square Test for Homogeneity
A chi-square test for homogeneity checks whether a categorical variable has the same distribution in two or more populations. Take a separate random sample from each population. Find each expected count, E = (row total × column total) ÷ table total, then χ² = Σ (O − E)²/E. A small p-value means the distributions differ.
Before this lesson: Two-Way Tables, Chi-Square Goodness-of-Fit Test and Chi-Square Test for Independence
What the test for homogeneity asks
Homogeneous means “the same all the way through.” Suppose three colleges each survey a random sample of their students about how they get to campus. The question is not whether two variables are linked in one group. It is whether the three colleges share the same mix of car, bus and walk-or-bike riders.
If H₀ is true, every college has the same distribution. Then each college’s expected counts follow the overall mix for all the samples combined. The χ² statistic adds up how far each observed count is from its expected count.
The math is the same as the chi-square test for independence. What changes is how the data were collected and how you write the hypotheses and conclusion.
Chi-square test for homogeneity formula
E = \dfrac{(\text{row total})(\text{column total})}{\text{table total}}\chi^2 = \sum \dfrac{(O - E)^2}{E}, \qquad \text{df} = (r - 1)(c - 1)- Put each group (population or treatment) in its own row and each category in its own column. r and c count only the data rows and columns, not the totals.
- H₀: the distribution of the variable is the same for every population. Hₐ: the distributions are not all the same.
- The p-value is the right tail: χ²cdf(χ², 10^99, df).
- On a TI-84: enter the observed counts in matrix [A], then STAT, TESTS, C:χ²-Test with Observed: [A] and Expected: [B].
Conditions
- Random: independent random samples from each population, or groups formed by random assignment in an experiment.
- 10%: when sampling without replacement, each sample is at most 10% of its population.
- Large Counts: every expected count is at least 5.
Homogeneity or independence?
| Test for homogeneity | Test for independence | |
|---|---|---|
| Data collected | A separate random sample from each group (or a randomized experiment) | One random sample |
| Variables | One categorical variable, compared across groups | Two categorical variables measured on each person |
| Row totals | Set by the design (the sample sizes) | Not set ahead of time |
| H₀ | The distribution is the same for every group | There is no association between the variables |
| Calculations | Same expected counts, χ² and df | Same expected counts, χ² and df |
Chi-square test for homogeneity examples
Example 1: Write the hypotheses
A phone company takes a random sample of 200 teens, 200 adults ages 20–39 and 200 adults 40 and older. Each person names their main use of their phone: messaging, video, social media or calls. Write H₀ and Hₐ.
\text{3 samples, 1 variable}Three separate samples, one categorical variable (main use).
H_0\text{: same distribution in all 3 age groups}Write H₀: the distribution of main phone use is the same for teens, adults 20–39 and adults 40+.
H_a\text{: not all the same}Write Hₐ: the distributions of main phone use are not all the same.
Answer: this is a test for homogeneity. Hₐ does not say every group differs. It says at least one group’s distribution is different.
Example 2: Expected counts and Large Counts
Use the campus table in Example 3. Find all nine expected counts and check the Large Counts condition.
E = \dfrac{150 \cdot 215}{400} = 80.625Expected count, College A, car.
E = \dfrac{150 \cdot 115}{400} = 43.125Expected count, College A, bus.
E = \dfrac{150 \cdot 70}{400} = 26.25Expected count, College A, walk or bike.
E = \dfrac{120 \cdot 215}{400} = 64.5Expected count, College B, car.
E = \dfrac{120 \cdot 115}{400} = 34.5Expected count, College B, bus.
E = \dfrac{120 \cdot 70}{400} = 21Expected count, College B, walk or bike.
E = \dfrac{130 \cdot 215}{400} = 69.875Expected count, College C, car.
E = \dfrac{130 \cdot 115}{400} = 37.375Expected count, College C, bus.
E = \dfrac{130 \cdot 70}{400} = 22.75Expected count, College C, walk or bike.
Answer: the expected counts are 80.625, 43.125 and 26.25 for College A; 64.5, 34.5 and 21 for College B; and 69.875, 37.375 and 22.75 for College C. The smallest is 21, so every expected count is at least 5 and Large Counts is met.
Example 3: How students get to campus (word problem)
Three community colleges each take an independent random sample of students and ask how they usually get to campus. Do the data give convincing evidence that the distribution of travel method differs among the three colleges? Use α = 0.05.
| College | Car | Bus | Walk or bike | Total |
|---|---|---|---|---|
| A | 90 | 40 | 20 | 150 |
| B | 60 | 30 | 30 | 120 |
| C | 65 | 45 | 20 | 130 |
| Total | 215 | 115 | 70 | 400 |
State: H₀: the distribution of travel method is the same at all three colleges. Hₐ: the distributions are not all the same. Plan: chi-square test for homogeneity. The samples are independent and random, each is far less than 10% of its college, and the expected counts from Example 2 are all at least 5.
Do: find each cell’s term (O − E)²/E.
\dfrac{(90 - 80.625)^2}{80.625} = \dfrac{87.891}{80.625} \approx 1.090College A, car.
\dfrac{(40 - 43.125)^2}{43.125} = \dfrac{9.766}{43.125} \approx 0.226College A, bus.
\dfrac{(20 - 26.25)^2}{26.25} = \dfrac{39.062}{26.25} \approx 1.488College A, walk or bike.
\dfrac{(60 - 64.5)^2}{64.5} = \dfrac{20.25}{64.5} \approx 0.314College B, car.
\dfrac{(30 - 34.5)^2}{34.5} = \dfrac{20.25}{34.5} \approx 0.587College B, bus.
\dfrac{(30 - 21)^2}{21} = \dfrac{81}{21} \approx 3.857College B, walk or bike.
\dfrac{(65 - 69.875)^2}{69.875} = \dfrac{23.766}{69.875} \approx 0.340College C, car.
\dfrac{(45 - 37.375)^2}{37.375} = \dfrac{58.141}{37.375} \approx 1.556College C, bus.
\dfrac{(20 - 22.75)^2}{22.75} = \dfrac{7.562}{22.75} \approx 0.332College C, walk or bike.
1.090 + 0.226 + 1.488 + 0.314 + 0.587 + \dots
Add all nine terms.
\chi^2 \approx 9.79
The sum of the nine terms.
\text{df} = (3 - 1)(3 - 1) = 2 \cdot 2 = 4Three groups and three categories.
p = \chi^2\text{cdf}(9.79,\ 10^{99},\ 4) \approx 0.044Right-tail area (see p-values).
0.044 \lt 0.05
Compare the p-value with α.
Conclude: because the p-value of about 0.044 is less than α = 0.05, reject H₀. There is convincing evidence that the distribution of travel method is not the same at all three colleges. The largest term, 3.857, comes from College B’s walk-or-bike count: 30 students, compared with 21 expected.
Example 4: A randomized experiment
A teacher randomly assigns 100 students to two review methods, 50 each. After the unit test, each student rates the method as helpful, neutral or not helpful. Method 1: 28, 14, 8. Method 2: 24, 16, 10. Is there convincing evidence that the rating distributions differ? Use α = 0.05.
\text{row totals } 50, 50;\ \text{column totals } 52, 30, 18Find the totals. The table total is 100.
E = \dfrac{50 \cdot 52}{100} = 26Expected helpful count for each method.
E = \dfrac{50 \cdot 30}{100} = 15Expected neutral count for each method.
E = \dfrac{50 \cdot 18}{100} = 9Expected not-helpful count for each method.
\dfrac{(28 - 26)^2}{26} + \dfrac{(14 - 15)^2}{15} + \dfrac{(8 - 9)^2}{9} \approx 0.154 + 0.067 + 0.111Terms for Method 1.
\dfrac{(24 - 26)^2}{26} + \dfrac{(16 - 15)^2}{15} + \dfrac{(10 - 9)^2}{9} \approx 0.154 + 0.067 + 0.111Terms for Method 2.
\chi^2 \approx 0.663
Add all six terms.
\text{df} = (2 - 1)(3 - 1) = 2Two groups and three categories.
p = \chi^2\text{cdf}(0.663,\ 10^{99},\ 2) \approx 0.718Right-tail area.
0.718 \gt 0.05
Compare the p-value with α.
Answer: fail to reject H₀. The data do not give convincing evidence that the two methods produce different rating distributions. Random assignment met the Random condition, and the smallest expected count is 9.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Writing H₀ about an association | H₀: college and travel method are independent. | For separate samples, say the distribution is the same for every group. |
| Using percents as the observed counts | O = 60 for “60% drive” at College A | Use the counts. College A has 90 drivers. |
| Counting the Total row or column in df | df = (4 − 1)(4 − 1) = 9 | Count only the data rows and columns: df = (3 − 1)(3 − 1) = 4. |
| Saying “accept H₀” after a large p-value | “The two methods are the same.” | Say the data do not give convincing evidence of a difference. |
| Saying every group differs after rejecting H₀ | “All three colleges have different mixes.” | Rejecting H₀ means at least one distribution differs. Use the largest terms to see where. |
Related methods
Two groups and two categories
With two groups and a yes-or-no variable, the test for homogeneity gives the same p-value as a two-sided two-proportion z-test, because χ² = z².
One group and a claimed distribution
With one sample and a claimed set of percents, use the chi-square goodness-of-fit test instead.
Practice problems
- A cell has a row total of 80 and a column total of 45 in a table of 300. Find its expected count.
- Random samples from 4 dorms are each asked whether they recycle always, sometimes or never. Find df.
- Random samples of 150 ninth graders, 150 tenth graders and 150 eleventh graders name their favorite streaming service. Write H₀ and Hₐ.
- Homogeneity or independence? (a) Random samples of 100 students from each of 4 dorms are asked how often they recycle. (b) One random sample of 400 adults is classified by region and how often they recycle.
- A cell has O = 18 and E = 24. Find its term (O − E)²/E.
- Two stores each take a random sample of 100 customers and record how they pay. Store 1: card 55, cash 25, phone 20. Store 2: card 45, cash 15, phone 40. Test at α = 0.05 whether the payment distributions differ.
- A test for homogeneity gives χ² = 7.2 with df = 3. Find the p-value.
- A test for homogeneity of favorite sport across three schools gives a p-value of 0.31 with α = 0.05. Write the conclusion.
- The smallest expected count in a table is 3.8. Is the Large Counts condition met?
Show answers
1.
80 \cdot 45 = 3600
Multiply the row total by the column total.
\dfrac{3600}{300} = 12Divide by the table total.
Answer: E = 12
2.
(4 - 1)(3 - 1) = 3 \cdot 2 = 6
Multiply (rows − 1) by (columns − 1).
Answer: df = 6
3.
H_0\text{: same distribution for all 3 grades}H₀: the distribution of favorite streaming service is the same for 9th, 10th and 11th graders.
H_a\text{: not all the same}Hₐ: the distributions are not all the same.
Answer: see the hypotheses above
4.
Answer: (a) homogeneity, because there is a separate sample from each dorm. (b) independence, because there is one sample with two variables.
5.
18 - 24 = -6
Subtract E from O.
(-6)^2 = 36
Square the difference.
\dfrac{36}{24} = 1.5Divide by E.
Answer: 1.5
6.
\text{row totals } 100, 100;\ \text{column totals } 100, 40, 60Find the totals. The table total is 200.
E = \dfrac{100 \cdot 100}{200} = 50Expected card count for each store.
E = \dfrac{100 \cdot 40}{200} = 20Expected cash count for each store.
E = \dfrac{100 \cdot 60}{200} = 30Expected phone count for each store. All are at least 5.
\dfrac{(55 - 50)^2}{50} + \dfrac{(25 - 20)^2}{20} + \dfrac{(20 - 30)^2}{30} \approx 0.5 + 1.25 + 3.333Terms for Store 1.
\dfrac{(45 - 50)^2}{50} + \dfrac{(15 - 20)^2}{20} + \dfrac{(40 - 30)^2}{30} \approx 0.5 + 1.25 + 3.333Terms for Store 2.
\chi^2 \approx 10.167
Add all six terms.
\text{df} = (2 - 1)(3 - 1) = 2Two stores and three payment types.
p = \chi^2\text{cdf}(10.167,\ 10^{99},\ 2) \approx 0.0062Right-tail area.
0.0062 \lt 0.05
Compare the p-value with α.
Answer: reject H₀. There is convincing evidence that the payment distributions differ. The biggest terms come from phone payments.
7.
p = \chi^2\text{cdf}(7.2,\ 10^{99},\ 3) \approx 0.0658Find the right-tail area with df = 3.
Answer: p ≈ 0.066
8.
0.31 \gt 0.05
Compare the p-value with α.
Answer: fail to reject H₀. The data do not give convincing evidence that the distribution of favorite sport differs among the three schools.
9.
3.8 \lt 5
Compare the smallest expected count with 5.
Answer: no. At least one expected count is below 5, so the χ² p-value may not be reliable.
Chi-square test for homogeneity FAQ
What is a chi-square test for homogeneity used for?
It tests whether two or more populations or treatment groups have the same distribution of one categorical variable, using a separate random sample or random assignment for each group.
What is the null hypothesis for a test of homogeneity?
H₀ says the distribution of the variable is the same in every population. Hₐ says the distributions are not all the same.
How is a test for homogeneity different from a test for independence?
A test for homogeneity compares one variable across separate samples. A test for independence uses one sample and asks whether two variables are related. The calculations are the same.
What are the degrees of freedom for a chi-square test for homogeneity?
df = (number of groups − 1)(number of categories − 1). Three groups and four categories give df = 6.
Summary
- Use a chi-square test for homogeneity to compare one categorical variable across two or more groups.
- The data come from separate random samples or from random assignment.
- E = (row total × column total) ÷ table total, χ² = Σ (O − E)²/E and df = (r − 1)(c − 1).
- Check Random, 10% and Large Counts. The p-value is the right tail.
- Rejecting H₀ means at least one group’s distribution differs. The largest terms show where.
Previous lesson: Chi-Square Test for Independence
Next lesson: Inference for Regression Slope
Back to the Statistics Index