Educerie

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

  1. Calculate the expected counts for a two-way table
  2. Calculate the chi-square statistic and the degrees of freedom
  3. Find a p-value or a bracket for it from Table C
  4. Interpret the p-value in context
  5. Make a decision with alpha and write a conclusion in context
  6. 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:

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}}

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).

SinglePassStudentTotal
Red523830120
Blue414930120
Green274350120
Total120130110360

Red, single:

E=(120)(120)360=40.0E = \frac{(120)(120)}{360} = 40.0

Red, pass:

E=(120)(130)360=43.3E = \frac{(120)(130)}{360} = 43.3

Red, student:

E=(120)(110)360=36.7E = \frac{(120)(110)}{360} = 36.7

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 (O−E)2/E(O - E)^2/E over every cell.

CellObservedExpected(O−E)2/E(O - E)^2/E
Red, single5240.03.600
Red, pass3843.30.656
Red, student3036.71.212
Blue, single4140.00.025
Blue, pass4943.30.741
Blue, student3036.71.212
Green, single2740.04.225
Green, pass4343.30.003
Green, student5036.74.848
χ2=3.600+0.656+1.212+0.025+0.741+1.212+4.225+0.003+4.848=16.52the sum over all 9 cells\begin{aligned}\chi^{2} &= 3.600 + 0.656 + 1.212 + 0.025 + 0.741 + 1.212 + 4.225 + 0.003 + 4.848 \\[6pt] &= 16.52 && \textcolor{#838c91}{\text{the sum over all 9 cells}}\end{aligned}

(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 H0H_0 is true. Its degrees of freedom depend on the size of the table:

df=(number of rows−1)(number of columns−1)not on the sheet: learn it\text{df} = (\text{number of rows} - 1)(\text{number of columns} - 1) \qquad \textcolor{#838c91}{\text{not on the sheet: learn it}}

Here the table has 3 rows and 3 columns: df = (3−1)(3−1)=4(3 - 1)(3 - 1) = 4.

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 χ2\chi^2 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. The chi-square distribution with 4 degrees of freedom when H0 is true. The observed statistic 16.52 lies far in the right tail; the area to its right, the p-value, is about 0.0024. The dashed line marks 9.49, the cut-off for alpha = 0.05 5 10 15 20 0 chi-square statistic 16.52 α = 0.05 cut-off 9.49 p-value 0.0024
Figure 1 · The chi-square distribution with 4 degrees of freedom: the observed statistic 16.52 lies far in the right tail, with area 0.0024 beyond it

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 area0.050.0250.00250.001
Critical value (df = 4)9.4911.1416.4218.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 α\alpha. Take α=0.05\alpha = 0.05.

Decision. Since the p-value of 0.0024 is less than 0.05, we reject H0H_0.

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–3435–5455+Total
Online725538165
Television484542135
Total12010080300

Setup (from 3.14). Chi-square test for independence. H0H_0: age group and main source of news are independent for adults in the town. HaH_a: 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: 165×120/300=66.0165 \times 120/300 = 66.0, 165×100/300=55.0165 \times 100/300 = 55.0, 165×80/300=44.0165 \times 80/300 = 44.0.
  • Television: 135×120/300=54.0135 \times 120/300 = 54.0, 135×100/300=45.0135 \times 100/300 = 45.0, 135×80/300=36.0135 \times 80/300 = 36.0.

Statistic.

χ2=(72−66)266+(55−55)255+(38−44)244+(48−54)254+(45−45)245+(42−36)236=0.545+0+0.818+0.667+0+1.000=3.03\begin{aligned}\chi^{2} &= \frac{(72-66)^{2}}{66} + \frac{(55-55)^{2}}{55} + \frac{(38-44)^{2}}{44} + \frac{(48-54)^{2}}{54} + \frac{(45-45)^{2}}{45} + \frac{(42-36)^{2}}{36} \\[6pt] &= 0.545 + 0 + 0.818 + 0.667 + 0 + 1.000 \\[6pt] &= 3.03\end{aligned}

Degrees of freedom. (2−1)(3−1)=2(2 - 1)(3 - 1) = 2.

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 α=0.05\alpha = 0.05, we fail to reject H0H_0.

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 "χ2\chi^2-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 χ2\chi^2, 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: "χ2=16.52\chi^2 = 16.52, 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.