The z tests of the last few topics compare one or two proportions. Many questions are bigger than that. Is age related to where people get their news, with three age groups and three news sources? Do three high schools differ in how students get to school? A two-way table holds these data, and a chi-square test asks whether the pattern in the table is more than chance. This topic sets the test up; the next one carries it out.
Two tests, two designs
There are two chi-square tests for two-way tables. The arithmetic is identical; what differs is how the data were collected, and so how the hypotheses read.
| Test for independence | Test for homogeneity | |
|---|---|---|
| Design | one random sample, each person classified by two categorical variables | separate random samples from several populations, or several randomly assigned treatment groups |
| Question | Are the two variables associated in the population? | Is the distribution of one variable the same in every population? |
| There is no association between the variables. | The distribution is the same in every population. | |
| There is an association. | At least one distribution is different. | |
| Example | 400 adults, each asked age group and news source | separate samples at three schools, each asked travel mode |
A quick test: did the researcher decide how many people to take from each group? If so (or if the groups were made by random assignment), it is homogeneity. If one sample was taken and both variables were recorded afterward, it is independence. Either way, the alternative hypothesis has no direction: it says only that an association, or a difference, exists.
Expected counts
Both tests compare the observed counts in the table with the expected counts: the counts we would expect, on average, if were true.
Here is the idea. In the news poll, 130 of the 400 adults (32.5%) use TV most. If age and news source were unrelated, TV would claim 32.5% of every age group. There are 140 adults aged 55 and older, so we would expect of them to use TV most. That is the general rule:
Worked example. Use the news poll in the figure to find two expected counts.
18 to 34, news websites: . The observed count is 40, close to it.
55 and older, TV: . The observed count is 72, far above it: older adults use TV more than "no association" predicts.
Expected counts need not be whole numbers, and you should not round them. In each row they add up to the row total, and in each column to the column total.
The chi-square statistic
To measure how far the whole table is from , compare every observed count with its expected count :
Squaring makes every gap count, whether the observed count is above or below; dividing by puts gaps on a fair scale, since a gap of 10 matters more when 20 were expected than when 200 were. If the table matched exactly, would be 0. The farther the observed counts sit from the expected counts, the larger gets, and the stronger the evidence against . The next topic shows how large is large.
Conditions
- Random: one random sample (independence), or separate random samples or random assignment (homogeneity), in the words of the problem.
- 10%: when sampling without replacement, each sample is less than 10% of its population.
- Large counts: every expected count is at least 5. Not the observed counts, and not 10.
In the news poll, the smallest expected count is 39, so the condition is met easily. If one expected count were 3.2, a chi-square test would not be reliable, no matter how large the other cells are.
Writing it up
For the news poll: a chi-square test for independence. : there is no association between age group and main news source among adults in the city. : there is an association between age group and main news source among adults in the city. Random: a random sample of 400 adults. 10%: 400 is less than 10% of the city's adults. Large counts: every expected count is at least 39, so at least 5.