Educerie · AP · Statistics
AP Statistics 3.15
Carrying Out 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
- Know that the expected count in a cell is the row total times the column total over the table total
- Understand that the statistic is the sum of (observed minus expected) squared over expected, with df (rows minus 1)(columns minus 1)
- Know that the p-value is the upper-tail area of the chi-square distribution
- Understand that a large p-value means no convincing evidence of a difference or association, never no association
You must be able to
- Calculate the expected counts for a two-way table
- Calculate the chi-square statistic and the degrees of freedom
- Find a p-value or a bracket for it from Table C
- Interpret the p-value in context
- Make a decision with alpha and write a conclusion in context
- Avoid the wording that accepts the null hypothesis
In the exam. Section I multiple choice: find an expected count, find the degrees of freedom, read a p-value from the chi-square table, or choose the correct conclusion. Section II: a chi-square test on a table can be the whole of Question 3, with the expected counts, the statistic, the degrees of freedom, the p-value and the conclusion scored. Skills: calculate (3.C, 3.E), interpret (4.F), justify a claim (4.G).
1Expected counts
The null hypothesis says the distribution of one variable is the same in every group (homogeneity), or that the two variables are independent (independence). Either way, the expected count in a cell comes from the totals:
Why it works: if the groups are alike, each group's row should divide up in the same proportions as the whole table. The column total divided by the table total is the overall proportion in that category. Multiply by the row total to get the number expected in the row.
Use the transit survey from 3.14 (three routes, 120 riders each, three fare types).
| Single | Pass | Student | Total | |
|---|---|---|---|---|
| Red | 52 | 38 | 30 | 120 |
| Blue | 41 | 49 | 30 | 120 |
| Green | 27 | 43 | 50 | 120 |
| Total | 120 | 130 | 110 | 360 |
Red, single:
Red, pass:
Red, student:
All three routes have the same row total, so the expected counts in every row are the same: 40.0, 43.3 and 36.7. Expected counts are usually not whole numbers. Do not round them to integers.
Check: the expected counts in a row add to the row total, and those in a column add to the column total.
2The statistic and the degrees of freedom
Add up over every cell.
| Cell | Observed | Expected | |
|---|---|---|---|
| Red, single | 52 | 40.0 | 3.600 |
| Red, pass | 38 | 43.3 | 0.656 |
| Red, student | 30 | 36.7 | 1.212 |
| Blue, single | 41 | 40.0 | 0.025 |
| Blue, pass | 49 | 43.3 | 0.741 |
| Blue, student | 30 | 36.7 | 1.212 |
| Green, single | 27 | 40.0 | 4.225 |
| Green, pass | 43 | 43.3 | 0.003 |
| Green, student | 50 | 36.7 | 4.848 |
(The expected counts above are shown to one decimal. The table uses the exact values, 43.33 and 36.67, so the sum is 16.52.)
The statistic has a chi-square distribution when is true. Its degrees of freedom depend on the size of the table:
Here the table has 3 rows and 3 columns: df = .
Count rows and columns of the table of categories, not the total row or column.
3The p-value
The p-value is the area to the right of the observed under the chi-square curve with the right df. Large values of the statistic are the unusual ones, so the test is always upper-tailed.
Figure 1 shows the curve, the 5% cut-off at 9.49 and the observed 16.52.
From Table C. Find the row for 4 df. The values in that row are
| Tail area | 0.05 | 0.025 | 0.0025 | 0.001 |
|---|---|---|---|---|
| Critical value (df = 4) | 9.49 | 11.14 | 16.42 | 18.47 |
The statistic 16.52 is just above 16.42 and below 18.47. So the p-value is between 0.001 and 0.0025.
From technology. The chi-square distribution function gives 0.0024. You can quote either: "the p-value is between 0.001 and 0.0025", or "0.0024".
4Decision and conclusion
Compare the p-value with . Take .
Decision. Since the p-value of 0.0024 is less than 0.05, we reject .
Conclusion. There is convincing evidence that the distribution of fare type differs among riders on the Red, Blue and Green routes.
Interpretation of the p-value. Assuming there is no difference in the distributions of fare type on the three routes, the probability of getting a chi-square statistic of 16.52 or larger, from independent random samples of 120 riders from each route, is 0.0024.
The test says that the distributions are not all the same. It does not say which route is different or how. To describe how, look at where the cells contribute most: Green single (4.225) and Green student (4.848). Green riders buy fewer single tickets and more student fares than expected. The percentages in Figure 1 of Topic 3.14 show the same.
5A second example, with a large p-value
Use the news survey from 3.14: one random sample of 300 adults, classified by age group and main source of news.
| 18–34 | 35–54 | 55+ | Total | |
|---|---|---|---|---|
| Online | 72 | 55 | 38 | 165 |
| Television | 48 | 45 | 42 | 135 |
| Total | 120 | 100 | 80 | 300 |
Setup (from 3.14). Chi-square test for independence. : age group and main source of news are independent for adults in the town. : they are not independent. The conditions are met (a random sample, under 10% of the town's adults, and all expected counts at least 5).
Expected counts.
- Online: , , .
- Television: , , .
Statistic.
Degrees of freedom. .
p-value. Table C, 2 df: 3.03 is between 2.77 (tail area 0.25) and 3.22 (tail area 0.20). So the p-value is between 0.20 and 0.25. Technology gives 0.22.
Decision. Since the p-value of about 0.22 is greater than , we fail to reject .
Conclusion. The data do not provide convincing evidence that age group and main source of news are associated for adults in the town.
Look at what that conclusion avoids. It does not say "there is no association", "the variables are independent" or "age has no effect". Failing to reject does not show that the null is true. It means the sample did not give strong enough evidence of an association.
6Technology, and what to show
A calculator or software can do all of this. In the "-Test" menu you enter the observed counts as a matrix and get the statistic, the p-value, the df and the matrix of expected counts.
On the exam, show enough to earn the marks:
- the expected counts (at least one worked cell, or the matrix);
- the expression for , or the statistic with its df;
- the p-value;
- the decision and conclusion.
Calculator syntax alone does not earn the calculation mark. Name the quantities: ", df = 4, p-value = 0.0024".
Practice questions
30 questions on this note, from easy to hard. Each one you get right lights a star of this topic's constellation.