Skip to content
Family Table Math
Auto

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.

Both tests use a two-way table of counts and exactly the same arithmetic. Choose between them by looking at the design:

Test for homogeneityTest for independence
How the data were collectedSeparate random samples from two or more populations, or a randomized experiment with two or more treatmentsOne random sample, with each individual classified on two categorical variables
QuestionIs the distribution of one categorical variable the same in every population (or treatment)?Is there an association between two categorical variables in one population?
H0H_0There is no difference in the distributions of [variable] across [populations or treatments].There is no association between [variable 1] and [variable 2] in [population].
HaH_aThere 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”: H0H_0 says the populations are alike in this variable.

If H0H_0 is true, every population has the same distribution, so each group should follow the overall (combined) distribution. That gives

expected count=row total×column totaltable total\text{expected count} = \frac{\text{row total} \times \text{column total}}{\text{table total}}

For example, if 175175 of all 450450 students sampled use transit, and a university contributed 150150 students, you’d expect 150×175450=58.33150 \times \dfrac{175}{450} = 58.33 of them to use transit. Don’t round expected counts to whole numbers; they are averages, not actual students.

The chi-square statistic measures how far the observed counts are from the expected counts, relative to the expected counts:

χ2=∑(observed−expected)2expected\chi^2 = \sum \frac{(\text{observed} - \text{expected})^2}{\text{expected}}

The sum is over every cell of the table (not the totals). Each term is that cell’s component. A big χ2\chi^2 means the observed counts are far from what H0H_0 predicts.

When H0H_0 is true (and the conditions hold), χ2\chi^2 has approximately a chi-square distribution with

df=(number of rows−1)(number of columns−1)\text{df} = (\text{number of rows} - 1)(\text{number of columns} - 1)

(count rows and columns of categories, not the total row or column).

Chi-square density curves for 2, 4 and 8 degrees of freedom. All take only positive values and are skewed right; the curve for 2 degrees of freedom starts at its highest point at 0, and the curves for 4 and 8 degrees of freedom peak at 2 and 6 and are less skewed. 0 2 4 6 8 10 12 14 16 18 20 df = 2 df = 4 df = 8 χ² value
Chi-square distributions take only positive values and are skewed right. With more degrees of freedom, the curve shifts right and becomes less skewed.

The p-value is the area to the right of the observed χ2\chi^2: only a large χ2\chi^2 is evidence against H0H_0. 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.

ConditionWhat to check
RandomIndependent random samples from each population, or treatments randomly assigned.
10%For sampling, each sample is at most 10%10\% of its population. Not needed for an experiment.
Large CountsAll expected counts are greater than 55.

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.

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.

For a 2×22 \times 2 table, the chi-square test for homogeneity is equivalent to the two-sided two-sample z-test for p1−p2p_1 - p_2: χ2=z2\chi^2 = z^2, 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.

The formula sheet gives χ2=∑(Observed Count−Expected Count)2Expected Count\chi^2 = \sum \dfrac{(\text{Observed Count} - \text{Expected Count})^2}{\text{Expected Count}}. 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 55, give χ2\chi^2, df, and the p-value, then conclude in context. Use counts, never percentages, in the table.

Say whether a chi-square test for homogeneity or for independence fits each study.

  • (a) A random sample of 600600 Canadian adults is classified by age group and by main news source.
  • (b) Separate random samples of 200200 adults from each of four provinces are asked their main news source.
  • (c) 150150 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.

A researcher takes independent random samples of 150150 students from each of three large universities and asks how they usually get to campus.

TransitCarWalk or bikeTotal
University 1707035354545150150
University 2555560603535150150
University 3505045455555150150
Total175175140140135135450450
  • (a) State the hypotheses.
  • (b) Find the expected counts and check the conditions.

Solution.

(a) H0H_0: there is no difference in the distributions of how students get to campus at the three universities. HaH_a: there is a difference in the distributions.

(b) Each university has row total 150150, so every row has the same expected counts:

Transit: 150×175450=58.33Car: 150×140450=46.67Walk or bike: 150×135450=45\begin{aligned} \text{Transit: } &\frac{150 \times 175}{450} = 58.33 \\ \text{Car: } &\frac{150 \times 140}{450} = 46.67 \\ \text{Walk or bike: } &\frac{150 \times 135}{450} = 45 \end{aligned}
  • Random: independent random samples from the three universities.
  • 10%: each university has more than 10(150)=150010(150) = 1500 students.
  • Large Counts: the smallest expected count is 4545, so all expected counts are greater than 55.

Complete the test from Example 2 at α=0.05\alpha = 0.05, and describe how the distributions differ.

Solution.

Do. There are 99 components, one per cell:

TransitCarWalk or bike
University 1(70−58.33)258.33=2.333\dfrac{(70 - 58.33)^2}{58.33} = 2.333(35−46.67)246.67=2.917\dfrac{(35 - 46.67)^2}{46.67} = 2.917(45−45)245=0\dfrac{(45 - 45)^2}{45} = 0
University 20.1900.1903.8103.8102.2222.222
University 31.1901.1900.0600.0602.2222.222
χ2=2.333+2.917+0+0.190+3.810+2.222+1.190+0.060+2.222=14.94\chi^2 = 2.333 + 2.917 + 0 + 0.190 + 3.810 + 2.222 + 1.190 + 0.060 + 2.222 = 14.94

df=(3−1)(3−1)=4\text{df} = (3 - 1)(3 - 1) = 4, and the p-value is P(χ2≥14.94)=0.0048P(\chi^2 \ge 14.94) = 0.0048.

Conclude. Because 0.0048<0.050.0048 \lt 0.05, we reject H0H_0. 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 (3.8103.810): 6060 students drove, compared with 46.746.7 expected. University 1 had fewer car users than expected (3535 versus 46.746.7) and more transit users (7070 versus 58.358.3), and University 3 had more students walking or biking (5555 versus 4545).

In the retrieval-practice experiment on the two-proportion z-test page, 4747 of 6060 students using retrieval practice passed, and 3636 of 6060 rereading students passed. Carry out a chi-square test for homogeneity, and compare it with the z-test, which gave z=2.17z = 2.17.

Solution.

PassFailTotal
Retrieval474713136060
Rereading363624246060
Total83833737120120

Expected counts: pass 60×83120=41.5\dfrac{60 \times 83}{120} = 41.5 and fail 60×37120=18.5\dfrac{60 \times 37}{120} = 18.5 in each row, all greater than 55. The study methods were randomly assigned.

χ2=(47−41.5)241.5+(13−18.5)218.5+(36−41.5)241.5+(24−18.5)218.5=4.73\chi^2 = \frac{(47 - 41.5)^2}{41.5} + \frac{(13 - 18.5)^2}{18.5} + \frac{(36 - 41.5)^2}{41.5} + \frac{(24 - 18.5)^2}{18.5} = 4.73

With df=(2−1)(2−1)=1\text{df} = (2 - 1)(2 - 1) = 1, the p-value is P(χ2≥4.73)=0.0297P(\chi^2 \ge 4.73) = 0.0297.

Compare. z2=2.17442=4.73z^2 = 2.1744^2 = 4.73, so χ2=z2\chi^2 = z^2. The chi-square p-value, 0.02970.0297, equals the two-sided z-test p-value (twice the one-sided 0.01480.0148, up to rounding). The one-sided question “does retrieval practice give a higher pass rate?” needs the z-test, whose p-value is 0.01480.0148.

Using percentages or proportions instead of counts. The chi-square statistic only works on counts. Turning 6060 out of 150150 into 40%40\% changes the value of χ2\chi^2 completely.

Checking Large Counts with the observed counts. The condition is about the expected counts, all greater than 55. An observed count of 33 is fine if its expected count is 88.

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 33 universities and 33 categories, df=(3−1)(3−1)=4\text{df} = (3 - 1)(3 - 1) = 4. 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.

1. (Warm-up) Say whether each study calls for a chi-square test for homogeneity or for independence.

  • (a) A random sample of 400400 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 4×34 \times 3 table (four populations, three categories) has a row total of 8080, a column total of 120120, and a table total of 400400 for one cell. Find that cell’s expected count and the degrees of freedom.

Solutionexpected=80×120400=24df=(4−1)(3−1)=6\text{expected} = \frac{80 \times 120}{400} = 24 \qquad \text{df} = (4 - 1)(3 - 1) = 6

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

H0H_0: 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.

HaH_a: 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 300300 participants, randomly assigning 100100 to each of three reminder methods. The numbers who return the survey are shown.

ReturnedNot returnedTotal
No reminder42425858100100
Email reminder55554545100100
Text reminder61613939100100
Total158158142142300300

Do the data give convincing evidence at α=0.05\alpha = 0.05 that the distribution of returns differs among the three reminder methods?

Solution

State. H0H_0: there is no difference in the distributions of survey returns for the three reminder methods. HaH_a: there is a difference. α=0.05\alpha = 0.05.

Plan. Chi-square test for homogeneity. Random: methods were randomly assigned. Expected counts: returned 100×158300=52.67\dfrac{100 \times 158}{300} = 52.67 and not returned 100×142300=47.33\dfrac{100 \times 142}{300} = 47.33 in each row, all greater than 55.

Do.

χ2=(42−52.67)252.67+(58−47.33)247.33+⋯+(39−47.33)247.33=7.57\chi^2 = \frac{(42 - 52.67)^2}{52.67} + \frac{(58 - 47.33)^2}{47.33} + \cdots + \frac{(39 - 47.33)^2}{47.33} = 7.57

df=(3−1)(2−1)=2\text{df} = (3 - 1)(2 - 1) = 2; p-value =P(χ2≥7.57)=0.0227= P(\chi^2 \ge 7.57) = 0.0227.

Conclude. Because 0.0227<0.050.0227 \lt 0.05, reject H0H_0. 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 0.02270.0227 probability of getting a chi-square statistic of 7.577.57 or larger by the random assignment alone.

6. (Core) A table comparing four age groups on five music genres has expected counts between 6.56.5 and 4141, except for the “jazz” column in the youngest age group, whose expected count is 3.23.2. 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 55, and 3.23.2 is not. The researcher could combine “jazz” with a similar genre (or into an “other” category) so that every expected count is greater than 55, then redo the test with fewer columns, or collect larger samples.

7. (Core) For Question 4, the components are:

ReturnedNot returned
No reminder2.1602.1602.4042.404
Email reminder0.1030.1030.1150.115
Text reminder1.3191.3191.4671.467

Describe how the distributions differ.

Solution

The largest components are in the “no reminder” row: those participants returned fewer surveys than expected (4242 observed, 52.752.7 expected). Next is “text reminder”, whose participants returned more than expected (6161 versus 52.752.7). The email group is close to what H0H_0 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, 117117 of 300300 adults supported an arena tax; in Edmonton, 141141 of 300300 did (independent random samples). The two-sample z-test for these data gives z=−1.979z = -1.979 and a two-sided p-value of 0.04780.0478.

  • (a) Carry out a chi-square test for homogeneity.
  • (b) Verify that χ2=z2\chi^2 = z^2 and that the p-values match.
Solution

(a) Totals: 258258 support and 342342 don’t, out of 600600. Expected counts are 300×258600=129\dfrac{300 \times 258}{600} = 129 (support) and 171171 (don’t) in each row, all greater than 55.

χ2=(117−129)2129+(183−171)2171+(141−129)2129+(159−171)2171=3.917\chi^2 = \frac{(117 - 129)^2}{129} + \frac{(183 - 171)^2}{171} + \frac{(141 - 129)^2}{129} + \frac{(159 - 171)^2}{171} = 3.917

df=1\text{df} = 1; p-value =P(χ2≥3.917)=0.0478= P(\chi^2 \ge 3.917) = 0.0478. Reject H0H_0 at α=0.05\alpha = 0.05: there is convincing evidence that the distribution of support for the tax differs between Calgary and Edmonton.

(b) z2=(−1.979)2=3.917=χ2z^2 = (-1.979)^2 = 3.917 = \chi^2, and both p-values are 0.04780.0478.

9. (Challenge) Two samples of 5050 give the table on the left. Two samples of 100100 with exactly the same percentages give the table on the right.

YesNo
Group A30302020
Group B20203030
YesNo
Group A60604040
Group B40406060
  • (a) Find χ2\chi^2 and the p-value for each table.
  • (b) Explain why the same percentages give different conclusions at α=0.01\alpha = 0.01.
Solution

(a) Left: every expected count is 2525, and each component is 5225=1\dfrac{5^2}{25} = 1, so χ2=4\chi^2 = 4, df =1= 1, p-value =0.0455= 0.0455.

Right: every expected count is 5050, and each component is 10250=2\dfrac{10^2}{50} = 2, so χ2=8\chi^2 = 8, p-value =0.0047= 0.0047.

(b) Doubling every count doubles χ2\chi^2 (each component is (2d)22E=2⋅d2E\dfrac{(2d)^2}{2E} = 2 \cdot \dfrac{d^2}{E}). At α=0.01\alpha = 0.01, the left table isn’t significant (0.0455>0.010.0455 \gt 0.01) but the right one is (0.0047<0.010.0047 \lt 0.01). The same difference in percentages is stronger evidence when it comes from more data. This is why the test needs counts, not percentages.

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.

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 500500 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 100100 customers from each of two coffee shops are asked their usual order size.

SmallMediumLargeTotal
Shop A343446462020100100
Shop B262634344040100100
Total606080806060200200

Find all the expected counts and the degrees of freedom.

H3. (Core) Independent random samples of 120120 high school students from each of four provinces are asked their favourite winter activity.

Skiing or snowboardingSkatingNeitherTotal
BC525230303838120120
Alberta444441413535120120
Ontario313150503939120120
Quebec373747473636120120
Total164164168168148148480480

Do the data give convincing evidence at α=0.05\alpha = 0.05 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 χ2=9.53\chi^2 = 9.53.

  • (a) Find the p-value and write a conclusion at α=0.05\alpha = 0.05.
  • (b) Which cells contribute most to χ2\chi^2? Describe how the two shops differ.

H5. (Core) A gardener randomly assigns 180180 tomato seedlings to three fertilizers, 6060 each, and rates each plant’s growth after a month.

PoorFairGoodTotal
Fertilizer A1818272715156060
Fertilizer B1212252523236060
Fertilizer C99212130306060
Total393973736868180180

Carry out a chi-square test for homogeneity at α=0.05\alpha = 0.05.

H6. (Core) A student analyzed the table in H2 like this:

I converted the counts to percentages: Shop A is 34%34\%, 46%46\%, 20%20\% and Shop B is 26%26\%, 34%34\%, 40%40\%. Then I used df=3×4−1=11\text{df} = 3 \times 4 - 1 = 11.

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.

H7. (Challenge) In independent random samples, 118118 of 200200 Vancouver households and 9090 of 180180 Victoria households own a car.

  • (a) Carry out a chi-square test for homogeneity at α=0.05\alpha = 0.05.
  • (b) Carry out a two-sample z-test of whether a higher proportion of Vancouver households own a car, at α=0.05\alpha = 0.05.
  • (c) Explain why the conclusions differ, and which test answers the one-sided question.

H8. (Challenge) A two-way table has the counts 3030 and 2020 (Group A: yes, no) and 2424 and 2626 (Group B: yes, no).

  • (a) Show that a chi-square test is not significant at α=0.05\alpha = 0.05.
  • (b) Suppose every count is multiplied by a whole number kk (bigger samples, same percentages). Find the smallest kk that makes the result significant at α=0.05\alpha = 0.05. (The 5%5\% critical value for df =1= 1 is 3.8413.841.)

H9. (Challenge) A researcher wants to study whether preferred news source (TV, online, print) differs by age group (under 3535, 3535 to 5959, 6060 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 5050 residents from each of three towns are asked how they heat their homes.

GasElectricWoodHeat pumpTotal
Town 12828151555225050
Town 22222202066225050
Town 32525141488335050
Total75754949191977150150
  • (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 α=0.05\alpha = 0.05.