Lesson 8.2 · Inference for Categorical Data: Chi-Square
Chi-square tests for homogeneity and independence
In Unit 2 you described association in a two-way table by comparing conditional distributions. But a sample can show differences just by chance. The chi-square tests for homogeneity and independence use the same statistic you met in the goodness-of-fit test to decide whether the pattern in a two-way table is strong enough to be real.
Two questions, one table
Two-way tables arise from two different study designs, and each design asks its own question.
Definition
Homogeneity versus independence
- A chi-square test for homogeneity compares the distribution of one categorical variable across two or more populations or treatments. The data come from separate random samples (or from groups in a randomized experiment).
- A chi-square test for independence checks whether two categorical variables are associated in one population. The data come from a single random sample, with each individual classified on both variables.
The quickest way to tell them apart is to ask: how many samples were taken? Several samples (or treatment groups), one variable measured: homogeneity. One sample, two variables measured: independence.
The hypotheses follow the design.
| Test | ||
|---|---|---|
| Homogeneity | The distribution of the variable is the same for every population. | The distribution is not the same for all populations. |
| Independence | There is no association between the two variables (they are independent). | There is an association between the two variables. |
The mechanics that follow are identical for both tests.
Expected counts in a two-way table
A school district randomly samples students from three high schools and asks how they usually get to school.
| Bus | Car | Walk/Bike | Total | |
|---|---|---|---|---|
| School A | ||||
| School B | ||||
| School C | ||||
| Total |
If is true and the commute distribution is the same at all three schools, then each school should match the overall distribution. Overall, of students ride the bus, so School A, with students, should have about bus riders. That reasoning gives a general formula.
Expected counts and degrees of freedom
For each cell of a two-way table,
The statistic is over every cell, and
Expected counts don't have to be whole numbers; keep a few decimal places. For the commute data, df .
Conditions
The conditions match the goodness-of-fit test, adjusted for the design:
- Random: separate random samples from each population, or groups formed by random assignment (homogeneity); a single random sample (independence).
- 10%: each sample is at most of its population when sampling without replacement.
- Large counts: all expected counts are at least .
Worked example: Test for homogeneity: commuting at three schools
Use the commute table. Do the data give convincing evidence at that the distribution of commute method differs among the three schools?
State. : the distribution of commute method is the same at all three schools. : the distribution is not the same at all three schools.
Plan. Chi-square test for homogeneity. Random: separate random samples from each school. : assume each sample is less than of its school's enrollment (a high school with at least students). Large counts: the expected counts are
| Bus | Car | Walk/Bike | |
|---|---|---|---|
| School A | |||
| School B | |||
| School C |
All are at least .
Do. The nine contributions are
| Bus | Car | Walk/Bike | |
|---|---|---|---|
| School A | |||
| School B | |||
| School C |
Summing, with df . In the df row of the table, is between () and (). Technology gives .
Conclude. Because , fail to reject . There is not convincing evidence that the distribution of commute method differs among the three schools.
Common mistake
Use counts, never row or column percents, in the table you analyze. Also, don't mix up the two tests in your conclusion. A homogeneity conclusion talks about whether distributions differ among populations; an independence conclusion talks about whether two variables are associated. And neither test shows causation unless the data came from a randomized experiment.
Worked example: Test for independence: age and texting
A random sample of adults in a city was asked their age group and whether they prefer to reach friends by texting or calling.
| Text | Call | Total | |
|---|---|---|---|
| 18–29 | |||
| 30–49 | |||
| 50+ | |||
| Total |
Is there convincing evidence at of an association between age group and communication preference in this city? Which cells contribute most?
State. : there is no association between age group and preference. : there is an association.
Plan. Chi-square test for independence. One random sample of adults; is less than of the city's adults. Expected counts: , ; , ; , . All are at least .
Do.
| Text | Call | |
|---|---|---|
| 18–29 | ||
| 30–49 | ||
| 50+ |
with df . In the table, is between () and (). Technology: .
Conclude. Because , reject . There is convincing evidence of an association between age group and communication preference among adults in this city.
The largest contributions come from the youngest group, who texted more than expected ( versus ), and the oldest group, who texted less than expected ( versus ).
A 2-by-2 table and the two-proportion z test
When the table has just two rows and two columns, a chi-square test for homogeneity asks the same question as a two-sided two-proportion test from Unit 6, and the two tests always agree: , and the P-values are equal.
Worked example: Two ways to test the same 2-by-2 table
In a randomized experiment, students received a reminder text about a scholarship deadline and did not. Of those reminded, applied early; of those not reminded, applied early. Compare the chi-square statistic with the two-proportion statistic.
The table is
| Applied early | Did not | Total | |
|---|---|---|---|
| Reminder | |||
| No reminder | |||
| Total |
Expected counts: and in each row. So
with df and .
For the test, the pooled proportion is , and
Indeed , and the two-sided P-value is also . Because the reminders were randomly assigned, this result supports a cause-and-effect conclusion.
Tip
When a test is significant, compare the observed and expected counts in the cells with the largest contributions. That turns "there is an association" into a specific, useful statement about how the groups differ.
Practice
Problems 1, 4, 5 and 8 use this table. A random sample of ninth graders and a separate random sample of twelfth graders at a large school were asked what setting they prefer while studying.
| Silence | Music | Background noise | Total | |
|---|---|---|---|---|
| 9th grade | ||||
| 12th grade | ||||
| Total |
What is the expected count of ninth graders who prefer silence, assuming the distribution of study setting is the same for both grades?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
A researcher builds a two-way table with rows and columns. How many degrees of freedom does the chi-square test have?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
A polling group selects one random sample of adults and records each person's region of the country and their preferred type of news source. Which test is appropriate for determining whether region and news source are related?
For the study-setting table, calculate the chi-square statistic. Round to two decimal places.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Continue the study-setting problem (). Find the P-value using technology. Round to four decimal places.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Which pair of hypotheses is correct for a chi-square test for independence between pet ownership (dog, cat, none) and housing type (house, apartment) among adults in a city?
A two-way table with rows and columns gives in a chi-square test for independence. Which conclusion is correct at ?
The study-setting test is significant. Which statement best describes the cell with the largest contribution to ?