Chi-Square Test for Homogeneity
A two-sample z-test compares one proportion across two groups. But what if you want to compare how students get to campus (transit, car, or walking and biking) at three different universities? A chi-square test for homogeneity compares the whole distribution of a categorical variable across two or more populations or treatments at once. It uses the same calculations as the chi-square test for independence; the difference is in how the data were collected, and so in what the hypotheses say.
Key ideas
Section titled “Key ideas”Homogeneity or independence?
Section titled “Homogeneity or independence?”Both tests use a two-way table of counts and exactly the same arithmetic. Choose between them by looking at the design:
| Test for homogeneity | Test for independence | |
|---|---|---|
| How the data were collected | Separate random samples from two or more populations, or a randomized experiment with two or more treatments | One random sample, with each individual classified on two categorical variables |
| Question | Is the distribution of one categorical variable the same in every population (or treatment)? | Is there an association between two categorical variables in one population? |
| There is no difference in the distributions of [variable] across [populations or treatments]. | There is no association between [variable 1] and [variable 2] in [population]. | |
| There is a difference in the distributions of [variable] across [populations or treatments]. | There is an association between [variable 1] and [variable 2] in [population]. |
“Homogeneous” means “the same throughout”: says the populations are alike in this variable.
Expected counts
Section titled “Expected counts”If is true, every population has the same distribution, so each group should follow the overall (combined) distribution. That gives
For example, if of all students sampled use transit, and a university contributed students, you’d expect of them to use transit. Don’t round expected counts to whole numbers; they are averages, not actual students.
The chi-square statistic and distribution
Section titled “The chi-square statistic and distribution”The chi-square statistic measures how far the observed counts are from the expected counts, relative to the expected counts:
The sum is over every cell of the table (not the totals). Each term is that cell’s component. A big means the observed counts are far from what predicts.
When is true (and the conditions hold), has approximately a chi-square distribution with
(count rows and columns of categories, not the total row or column).
The p-value is the area to the right of the observed : only a large is evidence against . On a TI-84, use χ²cdf(χ², 1E99, df), or enter the observed counts in a matrix and run χ²-Test, which also stores the expected counts.
The conditions
Section titled “The conditions”| Condition | What to check |
|---|---|
| Random | Independent random samples from each population, or treatments randomly assigned. |
| 10% | For sampling, each sample is at most of its population. Not needed for an experiment. |
| Large Counts | All expected counts are greater than . |
Check Large Counts with the expected counts, not the observed ones. If some expected counts are too small, you may be able to combine categories that make sense together.
After a significant result
Section titled “After a significant result”A significant chi-square test says the distributions differ somewhere, not where. To describe how they differ, look at the cells with the largest components and compare observed with expected: “University 2 had more car commuters than expected (60 observed, 46.7 expected)”. Conditional percentages and a segmented bar graph help too.
Connection to the two-sample z-test
Section titled “Connection to the two-sample z-test”For a table, the chi-square test for homogeneity is equivalent to the two-sided two-sample z-test for : , and the p-values are equal. A chi-square test can’t do a one-sided test; for “is group 1 higher?” use the z-test.
On the AP exam
Section titled “On the AP exam”The formula sheet gives . Name the test (homogeneity or independence, matching the design), state hypotheses in words in context, show at least one expected-count calculation and say that all expected counts are greater than , give , df, and the p-value, then conclude in context. Use counts, never percentages, in the table.
Worked examples
Section titled “Worked examples”Example 1: Which test?
Section titled “Example 1: Which test?”Say whether a chi-square test for homogeneity or for independence fits each study.
- (a) A random sample of Canadian adults is classified by age group and by main news source.
- (b) Separate random samples of adults from each of four provinces are asked their main news source.
- (c) volunteers are randomly assigned to three sleep programs, and each person’s sleep quality is rated poor, fair, or good.
Solution.
(a) Independence: one sample, classified on two variables (age group and news source).
(b) Homogeneity: separate samples from four populations, compared on one variable (news source).
(c) Homogeneity: a randomized experiment comparing the distribution of sleep quality across three treatments.
Example 2: Expected counts and conditions
Section titled “Example 2: Expected counts and conditions”A researcher takes independent random samples of students from each of three large universities and asks how they usually get to campus.
| Transit | Car | Walk or bike | Total | |
|---|---|---|---|---|
| University 1 | ||||
| University 2 | ||||
| University 3 | ||||
| Total |
- (a) State the hypotheses.
- (b) Find the expected counts and check the conditions.
Solution.
(a) : there is no difference in the distributions of how students get to campus at the three universities. : there is a difference in the distributions.
(b) Each university has row total , so every row has the same expected counts:
- Random: independent random samples from the three universities.
- 10%: each university has more than students.
- Large Counts: the smallest expected count is , so all expected counts are greater than .
Example 3: Carrying out the test
Section titled “Example 3: Carrying out the test”Complete the test from Example 2 at , and describe how the distributions differ.
Solution.
Do. There are components, one per cell:
| Transit | Car | Walk or bike | |
|---|---|---|---|
| University 1 | |||
| University 2 | |||
| University 3 |
, and the p-value is .
Conclude. Because , we reject . There is convincing evidence that the distribution of how students get to campus is different at the three universities.
Follow-up. The largest component is University 2, car (): students drove, compared with expected. University 1 had fewer car users than expected ( versus ) and more transit users ( versus ), and University 3 had more students walking or biking ( versus ).
Example 4: A 2 × 2 table
Section titled “Example 4: A 2 × 2 table”In the retrieval-practice experiment on the two-proportion z-test page, of students using retrieval practice passed, and of rereading students passed. Carry out a chi-square test for homogeneity, and compare it with the z-test, which gave .
Solution.
| Pass | Fail | Total | |
|---|---|---|---|
| Retrieval | |||
| Rereading | |||
| Total |
Expected counts: pass and fail in each row, all greater than . The study methods were randomly assigned.
With , the p-value is .
Compare. , so . The chi-square p-value, , equals the two-sided z-test p-value (twice the one-sided , up to rounding). The one-sided question “does retrieval practice give a higher pass rate?” needs the z-test, whose p-value is .
Common mistakes
Section titled “Common mistakes”Using percentages or proportions instead of counts. The chi-square statistic only works on counts. Turning out of into changes the value of completely.
Checking Large Counts with the observed counts. The condition is about the expected counts, all greater than . An observed count of is fine if its expected count is .
Choosing the test by the table instead of the design. Homogeneity and independence tables look identical. Ask: one sample classified two ways (independence), or separate samples or treatment groups (homogeneity)?
Counting the totals in the degrees of freedom. For a table with universities and categories, . The “Total” row and column don’t count.
Concluding which group is different from the test alone. A significant result means the distributions differ somewhere. Use the components (or conditional percentages) to describe where.
Saying the distributions are the same when you fail to reject. As with every test, a large p-value means there’s no convincing evidence of a difference, not proof that there’s none.
Practice
Section titled “Practice”1. (Warm-up) Say whether each study calls for a chi-square test for homogeneity or for independence.
- (a) A random sample of students at a school board is classified by grade and by favourite subject.
- (b) A store randomly assigns customers to three store layouts and records which department each customer visits first.
Solution
(a) Independence: one sample classified on two variables.
(b) Homogeneity: a randomized experiment comparing the distribution of first department across three treatments (layouts).
2. (Warm-up) A table (four populations, three categories) has a row total of , a column total of , and a table total of for one cell. Find that cell’s expected count and the degrees of freedom.
Solution
3. (Warm-up) Independent random samples of voters from Prince Edward Island, New Brunswick, and Nova Scotia are asked whether they support, oppose, or are undecided about a regional ferry plan. Write the hypotheses for a chi-square test for homogeneity.
Solution
: there is no difference in the distributions of opinion (support, oppose, undecided) about the ferry plan among voters in PEI, New Brunswick, and Nova Scotia.
: there is a difference in the distributions of opinion among voters in the three provinces.
4. (Core) A research team sends a follow-up survey to participants, randomly assigning to each of three reminder methods. The numbers who return the survey are shown.
| Returned | Not returned | Total | |
|---|---|---|---|
| No reminder | |||
| Email reminder | |||
| Text reminder | |||
| Total |
Do the data give convincing evidence at that the distribution of returns differs among the three reminder methods?
Solution
State. : there is no difference in the distributions of survey returns for the three reminder methods. : there is a difference. .
Plan. Chi-square test for homogeneity. Random: methods were randomly assigned. Expected counts: returned and not returned in each row, all greater than .
Do.
; p-value .
Conclude. Because , reject . There is convincing evidence that the distribution of survey returns differs among the three reminder methods for participants like these.
5. (Core) Interpret the p-value from Question 4 in context.
Solution
Assuming there is no difference in the distributions of survey returns for the three reminder methods, there is a probability of getting a chi-square statistic of or larger by the random assignment alone.
6. (Core) A table comparing four age groups on five music genres has expected counts between and , except for the “jazz” column in the youngest age group, whose expected count is . Can the chi-square test be carried out as planned? What could the researcher do?
Solution
No. The Large Counts condition requires all expected counts to be greater than , and is not. The researcher could combine “jazz” with a similar genre (or into an “other” category) so that every expected count is greater than , then redo the test with fewer columns, or collect larger samples.
7. (Core) For Question 4, the components are:
| Returned | Not returned | |
|---|---|---|
| No reminder | ||
| Email reminder | ||
| Text reminder |
Describe how the distributions differ.
Solution
The largest components are in the “no reminder” row: those participants returned fewer surveys than expected ( observed, expected). Next is “text reminder”, whose participants returned more than expected ( versus ). The email group is close to what predicts. So the main difference is that no reminder gives a lower return rate and a text reminder a higher one.
8. (Challenge) In Calgary, of adults supported an arena tax; in Edmonton, of did (independent random samples). The two-sample z-test for these data gives and a two-sided p-value of .
- (a) Carry out a chi-square test for homogeneity.
- (b) Verify that and that the p-values match.
Solution
(a) Totals: support and don’t, out of . Expected counts are (support) and (don’t) in each row, all greater than .
; p-value . Reject at : there is convincing evidence that the distribution of support for the tax differs between Calgary and Edmonton.
(b) , and both p-values are .
9. (Challenge) Two samples of give the table on the left. Two samples of with exactly the same percentages give the table on the right.
| Yes | No | |
|---|---|---|
| Group A | ||
| Group B |
| Yes | No | |
|---|---|---|
| Group A | ||
| Group B |
- (a) Find and the p-value for each table.
- (b) Explain why the same percentages give different conclusions at .
Solution
(a) Left: every expected count is , and each component is , so , df , p-value .
Right: every expected count is , and each component is , so , p-value .
(b) Doubling every count doubles (each component is ). At , the left table isn’t significant () but the right one is (). The same difference in percentages is stronger evidence when it comes from more data. This is why the test needs counts, not percentages.
Homework
Section titled “Homework”Try these independently after the practice questions. Show your setup and explain your reasoning. Check every condition (show at least one expected count), and write every conclusion in context. Homework solutions are not provided on the published site.
All data in these questions are hypothetical.
Foundations
Section titled “Foundations”H1. (Foundations) Say whether a chi-square test for homogeneity or for independence fits each study, and write the hypotheses in words.
- (a) Separate random samples of Grade 9, Grade 10, and Grade 11 students are asked whether they eat breakfast every day, sometimes, or never.
- (b) A random sample of Saskatoon residents is classified by whether they own a pet and by type of home (house, townhouse, or apartment).
H2. (Foundations) Independent random samples of customers from each of two coffee shops are asked their usual order size.
| Small | Medium | Large | Total | |
|---|---|---|---|---|
| Shop A | ||||
| Shop B | ||||
| Total |
Find all the expected counts and the degrees of freedom.
H3. (Core) Independent random samples of high school students from each of four provinces are asked their favourite winter activity.
| Skiing or snowboarding | Skating | Neither | Total | |
|---|---|---|---|---|
| BC | ||||
| Alberta | ||||
| Ontario | ||||
| Quebec | ||||
| Total |
Do the data give convincing evidence at that the distributions of favourite winter activity differ among the four provinces?
H4. (Core) For the coffee-shop table in H2, a chi-square test for homogeneity gives .
- (a) Find the p-value and write a conclusion at .
- (b) Which cells contribute most to ? Describe how the two shops differ.
H5. (Core) A gardener randomly assigns tomato seedlings to three fertilizers, each, and rates each plant’s growth after a month.
| Poor | Fair | Good | Total | |
|---|---|---|---|---|
| Fertilizer A | ||||
| Fertilizer B | ||||
| Fertilizer C | ||||
| Total |
Carry out a chi-square test for homogeneity at .
H6. (Core) A student analyzed the table in H2 like this:
I converted the counts to percentages: Shop A is , , and Shop B is , , . Then I used .
The p-value is large, so the two shops have the same distribution of order sizes.
Identify three errors and explain how to fix each.
Challenge
Section titled “Challenge”H7. (Challenge) In independent random samples, of Vancouver households and of Victoria households own a car.
- (a) Carry out a chi-square test for homogeneity at .
- (b) Carry out a two-sample z-test of whether a higher proportion of Vancouver households own a car, at .
- (c) Explain why the conclusions differ, and which test answers the one-sided question.
H8. (Challenge) A two-way table has the counts and (Group A: yes, no) and and (Group B: yes, no).
- (a) Show that a chi-square test is not significant at .
- (b) Suppose every count is multiplied by a whole number (bigger samples, same percentages). Find the smallest that makes the result significant at . (The critical value for df is .)
H9. (Challenge) A researcher wants to study whether preferred news source (TV, online, print) differs by age group (under , to , and over).
- (a) Describe a design that would lead to a chi-square test for homogeneity, and one that would lead to a test for independence.
- (b) Write the hypotheses for each design.
- (c) Explain how the wording of the conclusion would differ.
H10. (Challenge) Independent random samples of residents from each of three towns are asked how they heat their homes.
| Gas | Electric | Wood | Heat pump | Total | |
|---|---|---|---|---|---|
| Town 1 | |||||
| Town 2 | |||||
| Town 3 | |||||
| Total |
- (a) Show that the Large Counts condition fails.
- (b) Combine “Wood” and “Heat pump” into one category, “Other”, and check the condition again.
- (c) Carry out the test with the combined table at .