All AP Courses AP StatisticsAP Stats

Unit 3 · Topic 3.15 · about 25 minutes

AP Statistics 3.15: Carrying Out a Chi-Square Test for Homogeneity or Independence

Complete a chi-square test on a two-way table, from expected counts to a conclusion about the population or populations in context.

Unit 3: 15 to 25% of the multiple-choice section

What you'll be able to do

  • Calculate expected counts for a two-way table of categorical data.
  • Calculate the chi-square statistic and p-value for a chi-square test for homogeneity or independence.
  • Interpret the p-value of a chi-square test for homogeneity or independence in context.
  • Use the result of a chi-square test to justify a claim about the population or populations.

Key vocabulary

TermWhat it meansThe exam trap
Expected countThe count H0 predicts for a cell: (row total)(column total)/(table total).Splitting a column total evenly between the rows only works for rows of equal size; the 120 therapy patients expect 54 improvements, not 67.5 or 60.
Chi-square statisticχ2=∑(O−E)2E, with O the observed count and E the expected count, summed over every cell of the table.The total row and total column never enter the sum; only the inner cells do.
Degrees of freedom(number of rows minus 1) times (number of columns minus 1) for a two-way table.Counting cells gives 15 for a 3 by 5 table, but the degrees of freedom are (3−1)(5−1)=8.
p-valueThe area to the right of the observed χ2 under the chi-square distribution with the right degrees of freedom, computed assuming H0 is true.Only the right tail counts: for χ2=9.21 with 2 degrees of freedom the p-value is about 0.0100, and 0.9900 is the left-tail area.

Predict first

In a randomized experiment, 300 adults with lower back pain are split into two groups: 120 get physical therapy and 180 get a home exercise sheet. After six weeks, 135 of the 300 adults report improvement. If the treatment made no difference, how many of the 120 physical therapy patients would you expect to improve?

Expected counts

The expected count for a cell is the count the null hypothesis predicts:

expected count=(row total)(column total)table total

The reasoning is the one you just used. If H0 is true, the overall split of the column variable should show up in every row, so each row gets its share of each column. Expected counts describe what happens on average, so they do not have to be whole numbers. Keep the decimals, because rounding expected counts changes the chi-square statistic.

The statistic, the degrees of freedom and the p-value

With the expected counts in hand, add up one piece per cell:

χ2=∑(observed count−expected count)2expected count

The sum runs over every cell of the table, and never over the totals. When H0 is true, χ2 has a chi-square distribution with

df=(number of rows−1)(number of columns−1)

The p-value is the area to the right of the observed χ2 under that distribution, found with a table or technology. Only the right tail counts, because only large values of χ2 mean the data sit far from what H0 predicts.

Back pain study: observed counts with expected counts in parentheses
TreatmentImprovedDid not improveTotal
Physical therapy63 (54)57 (66)120
Home exercise sheet72 (81)108 (99)180
Total135165300

Every cell misses its expected count by 9, but the cells with smaller expected counts contribute more: 9254=1.50, 9266≈1.23, 9281=1.00 and 9299≈0.82. That makes χ2≈4.55 with df=(2−1)(2−1)=1, and the p-value is P(χ2≥4.55)≈0.033. At α=0.05, that is convincing statistical evidence that the distribution of outcomes (improved or not) differs between the two treatments for adults like these.

City payment survey: how a random sample of 320 adults usually pays at a store
Age groupCardPhoneCashTotal
18 to 34533710100
35 to 54773013120
55 and older701317100
Total2008040320

Worked exampleIs payment method associated with age?

A city's consumer affairs office selects a random sample of 320 adults who live in the city and records each person's age group and usual way of paying at a store. The results are in the table above. Do the data provide convincing statistical evidence, at α=0.05, of an association between age group and usual payment method among adults in the city?

  1. Name the test and state hypotheses. One random sample with two categorical variables calls for a chi-square test for independence. H0: there is no association between age group and usual payment method among adults in the city. Ha: there is an association between age group and usual payment method among adults in the city.

  2. Check conditions. Randomization: one random sample of the city's adults. 10%: 320 is far less than 10% of the adults in the city. Expected counts: the 18 to 34 row and the 55 and older row each have expected counts of 62.5, 25 and 12.5, and the 35 to 54 row has 75, 30 and 15. For example, card for ages 18 to 34 is (100)(200)320=62.5. All expected counts are greater than 5.

  3. Calculate. χ2=(53−62.5)262.5+(37−25)225+⋯+(17−12.5)212.5≈16.30, with df=(3−1)(3−1)=4. The p-value is P(χ2≥16.30)≈0.0026.

  4. Conclude in context. Because 0.0026<0.05, reject H0. There is convincing statistical evidence of an association between age group and usual payment method among adults in the city.

Answer.

χ2≈16.30, df=4, p-value about 0.0026: convincing evidence that payment method and age group are associated in this city.

Percent of each age group who usually pay with a phone

010203040Percent who pay by phone18 to 34: 3718 to 3435 to 54: 2535 to 5455 and older: 1355 and olderAge group

The phone column is where observed and expected counts differ most: the youngest group pays by phone far more often than H0 predicts, and the oldest group far less.

What the p-value means, and what to say when it is large

The p-value is the probability of a chi-square statistic as large as the one observed, or larger, computed by assuming H0 is true. In context: assuming there is no association between age group and payment method among the city's adults, there is about a 0.0026 probability of getting a chi-square statistic of 16.30 or larger in a random sample of 320 adults.

As with every test, compare the p-value with α: reject H0 if the p-value is less than or equal to α, and fail to reject H0 if it is greater. Here 0.0026<0.05, and the result answers the question that started the study. Do payment habits differ by age in this city? The data give convincing evidence that they do.

A large p-value needs more careful wording. Suppose another city's survey gave a p-value of 0.31. Because 0.31>0.05, fail to reject H0: the data do not provide convincing statistical evidence of an association between age group and payment method among adults in that city. Saying the two variables are independent would be accepting H0, and a test can never establish that.

Check your understanding

1

A random sample of 250 students at a large high school was asked where they usually study.

HomeLibraryCoffee shopTotalGrades 9 to 10603525120Grades 11 to 12504535130Total1108060250

For a chi-square test for independence, what is the expected count of students in grades 11 to 12 who usually study at the library?

2

A chi-square test for homogeneity compares the distribution of favorite movie type (action, comedy, drama, horror or animated) across three age groups. How many degrees of freedom does the test have?

3

A chi-square test for independence on a two-way table with 2 rows and 3 columns gives χ2=9.21. What is the p-value?

4

Independent random samples of students at three high schools are asked their favorite of four music genres. A chi-square test for homogeneity gives χ2=14.2 with 6 degrees of freedom and a p-value of 0.027. Which is a correct interpretation of the p-value?

5

A random sample of 400 students at a university is classified by handedness and by preferred sport. A chi-square test for independence gives a p-value of 0.31. At α=0.05, which conclusion is correct?

Practice

Practice until it is automatic

New numbers every time. Each one is checked the moment you answer, with the full working shown.

Chi-square tests for two-way tables practice page

Exam strategy for this topic

  • Section I, Multiple Choice: 42 questions in 90 minutes.
  • Section II, Free Response: 4 questions in 90 minutes.
  • A graphing calculator with statistical capabilities is expected on both sections.

Questions students ask

Why keep the decimals in expected counts?

An expected count describes what happens on average, so it does not have to be a whole number. Rounding it changes the chi-square statistic.

Why do some cells add more to χ2 than others?

Each piece divides by the expected count. In the back pain study every cell misses by 9, yet the cell expecting 54 adds 1.50 while the cell expecting 99 adds about 0.82.

How can I see which cells drove a large χ2?

Compare observed and expected counts cell by cell. In the payment survey the phone column stands out: 37 adults ages 18 to 34 paid by phone where 25 were expected, and only 13 adults 55 and older did, also against 25 expected.

Is the conclusion about the people sampled or the whole population?

The whole population. The 320 adults in the payment survey are known exactly; the test supports a claim about all adults in the city.

Can I find the p-value without a calculator?

Yes. A chi-square table gives it, read at the right degrees of freedom. A table brackets the p-value between two columns instead of giving it exactly, which is still enough to compare with α.

Course alignment, for teachers

AP Statistics topic 3.15, Unit 3: Inference for Categorical Data: Proportions.

  • Skill 3.C: Calculate and estimate expected counts, percentages, probabilities, and intervals.
  • Skill 3.E: Calculate appropriate statistical inference method results.
  • Skill 4.F: Interpret results of statistical inference methods.
  • Skill 4.G: Justify a claim based on statistical inference method results.