Educerie

Educerie · AP · Statistics

AP Statistics 3.14

Setting Up a Chi-Square Test for Homogeneity or Independence

Are the distributions of various types of wild birds different in urban areas than in rural areas?

What you will learn

  • Understand that the chi-square statistic measures the distance between observed and expected counts relative to the expected counts
  • Know that chi-square distributions are positive and skewed right, with less skew as the degrees of freedom rise
  • Understand that homogeneity compares distributions across populations and independence tests association in one population
  • Know how to write the hypotheses in words and verify randomization, 10% and expected counts

You must be able to

  1. Choose homogeneity or independence from how the data were collected
  2. Name the procedure in full
  3. Write the null and alternative hypotheses in words, in context
  4. Verify randomization, the 10% condition and the expected counts
  5. Describe a chi-square distribution
  6. Compare conditional distributions in a two-way table or segmented bar graph

In the exam. Section I multiple choice: choose the correct test from a description of how the data were collected (homogeneity or independence), pick the hypotheses, or identify the condition that must be checked on expected counts. Section II: a table of counts in an inference question. The procedure, the hypotheses in words, and the conditions are each a separate point. Skills: identify the method (2.C), identify the hypotheses (2.E), describe distributions (4.C), verify conditions (4.E).

1A two-way table and its distributions

Example (invented). A transit agency takes an independent random sample of 120 riders from each of three routes, Red, Blue and Green. Each rider reports the fare type they use: a single ticket, a monthly pass or a student pass.

SinglePassStudentTotal
Red523830120
Blue414930120
Green274350120
Total120130110360

The distribution of fare type on each route is the set of percentages across a row.

Figure 1. Segmented bar graph of fare type within each route, from random samples of 120 riders per route. Red: 43% single, 32% pass, 25% student. Blue: 34%, 41%, 25%. Green: 23%, 36%, 42%. The three bars differ, mainly in the single and student shares 25 50 75 100 0 percent of riders in the sample Red Blue Green single 43% pass 32% student 25% single 34% pass 41% student 25% single 22% pass 36% student 42%
Figure 1 · Segmented bar graph of fare type within each route: the three bars differ, mainly in the single and student shares

Figure 1 shows those distributions as segmented bars. Each bar is one route, and its segments add to 100%.

  • Red: 43% single, 32% pass, 25% student.
  • Blue: 34% single, 41% pass, 25% student.
  • Green: about 22% single, 36% pass, 42% student.

If the three routes had the same distribution of fare type, the three bars would look alike. They do not. Green has far more student fares than Red. The question is whether the differences are bigger than random sampling would produce. The chi-square test answers it.

2What the chi-square statistic measures

The test compares each observed count with the expected count the null hypothesis predicts. For each cell, find the gap, square it so that gaps in both directions count, and divide by the expected count, so that a gap of 10 matters more when 20 were expected than when 200 were.

χ2=∑(Observed−Expected)2Expectedthe sum is over every cell of the table\chi^{2} = \sum \frac{(\text{Observed} - \text{Expected})^{2}}{\text{Expected}} \qquad \textcolor{#838c91}{\text{the sum is over every cell of the table}}

This is on the formula sheet. In words, the statistic measures the distance between the observed counts and the expected counts, relative to the expected counts. It is zero only when every observed count equals its expected count. The larger it is, the worse the fit with the null.

3What chi-square distributions look like

When H0H_0 is true, the statistic follows a chi-square distribution. It depends on its degrees of freedom (df).

Figure 2. Chi-square density curves for 2, 5 and 10 degrees of freedom. Each takes only positive values and is skewed right; the skew is less pronounced as the degrees of freedom increase, and the peak moves right 5 10 15 20 0 chi-square statistic df = 2 df = 5 df = 10
Figure 2 · Chi-square density curves for 2, 5 and 10 degrees of freedom: all positive and skewed right, less skewed as the degrees of freedom increase

Three facts to read from Figure 2:

  • Chi-square values are never negative, because squares are not negative.
  • Every chi-square curve is skewed right. A few large values stretch out the right tail.
  • As the degrees of freedom increase, the skew becomes less pronounced and the peak moves to the right.

The test is always upper-tailed. Large values of χ2\chi^2 are evidence against H0H_0. There is no two-sided version, and a small χ2\chi^2 is not evidence for anything but a good fit.

4Homogeneity or independence?

Both tests use the same table, the same statistic and the same conditions. They differ in how the data were collected and in what the hypotheses say. Ask one question: how was the sample chosen?

Chi-square test for homogeneityChi-square test for independence
QuestionAre the distributions of one categorical variable the same in two or more populations or treatments?Are two categorical variables associated in one population?
Data collectionA separate random sample from each population (independent random samples), or a randomized experiment with several treatmentsOne random sample from one population, each individual classified on both variables
Row totalsSet by the researcher (the sample sizes)Not set: they result from the sample

The transit survey above is homogeneity. The researcher chose 120 riders from each route. The variable is fare type, and the populations are the three routes.

Now a second study.

Example (invented). A news organization takes one random sample of 300 adults in a town. Each adult is asked for an age group (18 to 34, 35 to 54, 55 and over) and for the main source of news (online or television).

18–3435–5455+Total
Online725538165
Television484542135
Total12010080300

This is independence. One sample of 300 adults from one population was classified on two variables. Nobody chose how many would be in each age group.

A tip. Look for the words "independent random samples from each", "each group", or "randomly assigned to treatments". Those mean homogeneity. Look for "a random sample of nn people, each asked about both" for independence.

If the study is a randomized experiment, the treatments are the "populations", and the test is for homogeneity.

5The hypotheses, in words

Chi-square hypotheses are written in words, in context, because there is no single parameter. No symbols are needed. Mention the variable and the populations.

Homogeneity.

  • H0H_0: There is no difference in the distributions of fare type among riders on the Red, Blue and Green routes.
  • HaH_a: There is a difference in the distributions of fare type among riders on the three routes.

Independence.

  • H0H_0: Age group and main source of news are independent (not associated) for adults in the town.
  • HaH_a: Age group and main source of news are not independent (are associated) for adults in the town.

Notes on wording:

  • Say "difference in the distributions", not "the proportions are all equal" or "the means differ". The alternative does not say which groups differ or how.
  • For independence, "independent" and "not associated" mean the same thing. Use the word the question uses.
  • Name the populations: "riders on the three routes", "adults in the town".
  • Do not write "HaH_a: all the distributions are different". The alternative is that at least one is.
  • "Associated" does not mean "causes". Association from a sample survey is not causation.

6The conditions

A chi-square test needs three conditions.

  1. Randomization. For independence: the data come from a random sample. For homogeneity: the data come from independent random samples (one per population) or from a randomized experiment.
  2. 10% condition. When sampling without replacement, each sample is at most 10% of its population. This is unnecessary for a randomized experiment.
  3. Expected counts. All expected counts are at least 5.

The third condition is about expected counts, not the counts you observed. Expected counts are what the null predicts. Topic 3.15 shows how to calculate them:

expected count=(row total)(column total)table totalnot on the sheet: learn it\text{expected count} = \frac{(\text{row total})(\text{column total})}{\text{table total}} \qquad \textcolor{#838c91}{\text{not on the sheet: learn it}}

For the transit table, the expected counts are 40.0, 43.3 and 36.7 in every row. For the news table they are 66.0, 55.0, 44.0 in the Online row and 54.0, 45.0, 36.0 in the Television row. All are well above 5, so the condition is met in both studies.

A note on the wording of the cut-off. The description writes it as "at least 5" in one place and "greater than 5" in another. A table in which every expected count is above 5, as these are, satisfies both. State your check with the numbers.

Check the conditions for the transit survey.

  • Randomization: independent random samples of riders, one from each route.
  • 10%: each route has many more than 1,200 riders (given in the question), so 120 is less than 10% of each.
  • Expected counts: the smallest, 36.7, is at least 5.

7Naming the procedure

Write the full name.

  • "Chi-square test for homogeneity" (for the transit survey).
  • "Chi-square test for independence" (for the news survey).

"Chi-square test" alone is incomplete. So is "χ2\chi^2 test". The name tells the reader that you understood how the data were collected.

8The setup in order

For each version, write:

  1. The procedure, named in full, with a reason (how the data were collected).
  2. The hypotheses in words, in context.
  3. The conditions, each with its check and its numbers.

Then Topic 3.15: the expected counts, the statistic, the degrees of freedom, the p-value and the conclusion.

Practice questions

30 questions on this note, from easy to hard. Each one you get right lights a star of this topic's constellation.