Unit 3 · Topic 3.14 · about 25 minutes

Setting Up a Chi-Square Test for Homogeneity or Independence

Decide whether a two-way table calls for a test of homogeneity or independence, then write the hypotheses and check the conditions in context.

Predict first

Two studies end up with two-way tables holding exactly the same counts. Study 1 took one random sample of 300 students at a school and recorded each student's grade (10th, 11th or 12th) and whether the student plays a school sport. Study 2 took a separate random sample of 100 students from each of the three grades and recorded whether each plays a school sport. Do the two studies call for the same chi-square test?

What the chi-square statistic measures

Both tests compare the counts you observed in a two-way table with the counts you would expect if the null hypothesis were true. An expected count is the count H0 predicts for one cell. For a two-way table it equals (row total)(column total)/(table total), and the next lesson shows where that comes from.

The chi-square statistic measures the distance between the observed and expected counts, relative to the expected counts:

χ2=∑(observed−expected)2expected

Each cell adds a squared difference divided by a positive expected count, so no cell can pull the total below 0. A χ2 of 0 would mean every observed count matched its expected count exactly, and the farther the data sit from what H0 predicts, the larger χ2 gets. Dividing by the expected count keeps the comparison fair. Missing by 6 when you expected 10 adds 6210=3.6; missing by 6 when you expected 300 adds only 0.12.

Chi-square distributions

When H0 is true, the chi-square statistic follows a chi-square distribution. There is a whole family of these density curves, one for each number of degrees of freedom. For a two-way table, the degrees of freedom are (number of rows minus 1) times (number of columns minus 1), so a 2 by 3 table has 2. The next lesson uses this number to find the p-value. Every one of them takes only positive values and is skewed right. As the degrees of freedom increase, the skew becomes less pronounced.

Chi-square distribution with 2 degrees of freedom

00.10.20.30.4Probability0 to 1: 0.39351 to 2: 0.23872 to 3: 0.14473 to 4: 0.08784 to 5: 0.05335 to 6: 0.03236 to 7: 0.01967 to 8: 0.01198 to 9: 0.00729 to 10: 0.004410 to 11: 0.002711 to 12: 0.001612 to 13: 0.00113 to 14: 0.000614 to 15: 0.000415 to 16: 0.000216 to 17: 0.000117 to 18: 0.000118 to 19: 019 to 20: 020 to 21: 021 to 22: 022 to 23: 023 to 24: 005101520Value of the chi-square statistic

Each bar is the probability that the statistic lands in that interval of width 1. Values pile up near 0 and trail far off to the right.

Chi-square distribution with 10 degrees of freedom

00.050.1Probability0 to 1: 0.00021 to 2: 0.00352 to 3: 0.01493 to 4: 0.03414 to 5: 0.05625 to 6: 0.07596 to 7: 0.08987 to 8: 0.09668 to 9: 0.09679 to 10: 0.091610 to 11: 0.08311 to 12: 0.072512 to 13: 0.061413 to 14: 0.050714 to 15: 0.040915 to 16: 0.032416 to 17: 0.025317 to 18: 0.019418 to 19: 0.014719 to 20: 0.01120 to 21: 0.008221 to 22: 0.00622 to 23: 0.004423 to 24: 0.003105101520Value of the chi-square statistic

Same horizontal axis as the chart above. The distribution is still skewed right, but far less than with 2 degrees of freedom.

Homogeneity or independence?

The arithmetic for the two tests is identical, from the expected counts to the p-value. What separates them is the design of the study, because the design decides which question the data can answer.

  • A chi-square test for homogeneity compares the distribution of one categorical variable across two or more populations or treatments. The data come from independent random samples, one from each population, or from a randomized experiment.
  • A chi-square test for independence asks whether two categorical variables are associated in a single population. The data come from one random sample, with both variables recorded for each individual.

A quick way to tell: count the samples. Several samples, or several treatment groups, set up by the researcher means homogeneity. One sample, split up afterward by a second variable, means independence.

Sort it

Which chi-square test fits each study? Tap a card, then tap its bin.

Homogeneity

Independence

Hypotheses for the two tests, before you put them in context
HypothesisHomogeneityIndependence
H0There is no difference in the distribution of the categorical variable across the populations or treatments.There is no association between the two categorical variables in the population; they are independent.
HaThere is a difference in the distribution of the categorical variable across the populations or treatments.There is an association between the two categorical variables in the population; they are not independent.

Always fill these in with the actual variables and populations. For Study 1 in the opening question, H0 is that there is no association between grade level and playing a school sport among students at the school. For Study 2, H0 is that the distribution of sport participation is the same for the school's 10th, 11th and 12th graders.

Conditions for a chi-square test
ConditionHomogeneityIndependence
RandomizationIndependent random samples, one from each population, or a randomized experimentOne random sample from the population
10%When sampling without replacement, each sample is no more than 10% of its population; not needed for a randomized experimentWhen sampling without replacement, n≤0.10N
Expected countsAll expected counts are greater than 5All expected counts are greater than 5
Transit study: observed counts of ratings by response
ResponseSatisfiedNeutralDissatisfiedTotal
Apology email21241560
Email plus free ride pass3422460
Phone call from a supervisor29211060
Total846729180

Worked exampleSetting up a test for three complaint responses

A transit agency randomly assigns 180 riders who complained about late buses to receive one of three responses, 60 riders each: an apology email, an apology email with a free ride pass, or a phone call from a supervisor. A month later, each rider rates the agency as Satisfied, Neutral or Dissatisfied. The results are in the table above. The agency wants to know whether the distribution of ratings differs among the three responses. Identify the test, state the hypotheses and check the conditions.

  1. Identify the test. Riders were randomly assigned to three treatments, and one categorical variable, the rating, was recorded. That calls for a chi-square test for homogeneity.

  2. State the hypotheses. H0: there is no difference in the distribution of ratings (satisfied, neutral, dissatisfied) among riders like these who receive the apology email, the email with a ride pass, or the phone call. Ha: there is a difference in the distribution of ratings among the three responses.

  3. Check randomization and 10%. The responses were randomly assigned to riders, which meets the randomization condition. This is a randomized experiment, so the 10% condition does not apply.

  4. Check expected counts. Every row has 60 riders, so every row has the same expected counts: 60(84)180=28 satisfied, 60(67)180≈22.33 neutral and 60(29)180≈9.67 dissatisfied. The smallest is 9.67, so all expected counts are greater than 5.

Answer.

A chi-square test for homogeneity is appropriate. Notice the observed count of 4 in the ride pass row. It is below 5, and that does not matter, because the condition is about expected counts.

Check your understanding

1

A researcher selects a random sample of 400 residents of a city and records each person's favorite season and whether the person has seasonal allergies. She wants to know whether favorite season and allergy status are related. Which test is appropriate?

2

A travel company takes independent random samples of 100 adults from each of three age groups (18 to 34, 35 to 54, and 55 or older) and asks each adult to choose a favorite type of vacation: beach, city or outdoors. Which is the correct null hypothesis for a chi-square test for homogeneity?

3

Which statement about chi-square distributions is true?

4

A chi-square test for independence uses a two-way table with 3 rows and 4 columns. The smallest observed count in the table is 3, and the smallest expected count is 6.2. Is the expected counts condition met?

5

A high school with 2,800 students wants to test whether grade level and preferred lunch option are associated among its students. Which plan for collecting data meets the randomization condition for a chi-square test for independence?

Practice

Practice until it is automatic

Each problem gives a fresh table and asks for an expected count or the degrees of freedom. The next lesson computes the statistic and the p-value.

Chi-square tests for two-way tables practice page

Course alignment, for teachers

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

  • Skill 2.C: Identify appropriate statistical inference methods.
  • Skill 2.E: Identify the null and alternative hypotheses.
  • Skill 4.C: Describe distributions and compare relative positions of points within a distribution.
  • Skill 4.E: Justify the use of a chosen statistical inference method by verifying conditions.