AP Statistics · Topic 3.15 · Unit 3

AP Stats 3.15: Carrying Out a Chi-Square Test

By Jude Wallis · Published

The chi-square statistic is the sum of (observed minus expected) squared divided by expected, over all cells. Degrees of freedom equal (rows minus 1) times (columns minus 1). Find the p-value from the chi-square distribution, then compare it to alpha.

AP Statistics: Unit 3 (topics 3.15). CED topic 3.15 (Carrying Out a Chi-Square Test for Homogeneity or Independence), skills 3.C, 3.E, 4.F, 4.G.

What topic 3.15 covers

Topic 3.15 carries out the chi-square test you set up in topic 3.14. You compute expected counts, the chi-square test statistic, the degrees of freedom, and the p-value, then state a conclusion in context. The same steps apply to both the test for homogeneity and the test for independence, which is why the two tests share one topic. Only the wording of the hypotheses and conclusion changes between them.

Expected counts and the statistic

For each cell of the two-way table, the expected count under the null hypothesis is

expected count=row total×column totaltable total.\text{expected count} = \dfrac{\text{row total} \times \text{column total}}{\text{table total}}.

The test statistic sums a contribution from every cell:

χ2=(observedexpected)2expected.\chi^2 = \sum \dfrac{(\text{observed} - \text{expected})^2}{\text{expected}}.

Each term measures how far an observed count sits from what the null predicts, scaled by the expected count, so cells with small expected counts can contribute large amounts to the total.

Degrees of freedom, p-value, and conclusion

The statistic follows a chi-square distribution with

df=(number of rows1)(number of columns1)df = (\text{number of rows} - 1)(\text{number of columns} - 1)

when the null is true. Find the p-value as the area to the right of your χ2\chi^2 value from a chi-square table or technology, because larger values give stronger evidence against the null. Compare it to α\alpha: reject H0H_0 if the p-value is at most α\alpha, otherwise fail to reject. State the conclusion in context with non-definitive language, referencing the population for independence or the populations for homogeneity.

Following up a significant result

A chi-square test only tells you that the observed counts differ from the null model somewhere in the table; it does not say which cells drive the difference. To describe where the association lives, compare the observed and expected counts cell by cell and note which cells have the largest contributions to the chi-square total. Those cells show where one category appears more or less often than the null predicts.

This follow-up turns a yes-or-no test result into a specific statement about the categorical variables in context. On the exam, a full response names the test, verifies the conditions, shows the statistic and degrees of freedom, states the p-value, and links the decision to the significance level, all in the context of the question.

Chi-square test for a 2 by 2 table

Two treatments each have 50 subjects. Treatment A has 30 successes and 20 failures; treatment B has 20 successes and 30 failures. Test for a difference at α=0.05\alpha = 0.05.

  1. Totals: each row totals 50, each column totals 50, and the table totals 100.

  2. Expected count for every cell: 50×50100=25\dfrac{50 \times 50}{100} = 25.

  3. Cell contributions: (3025)225=2525=1\dfrac{(30-25)^2}{25} = \dfrac{25}{25} = 1, and the same value 1 for each of the four cells.

  4. Statistic: χ2=1+1+1+1=4\chi^2 = 1 + 1 + 1 + 1 = 4.

  5. Degrees of freedom: (21)(21)=1(2-1)(2-1) = 1.

  6. p-value: the area to the right of 4 for df=1df = 1 is about 0.0455.

With χ2=4\chi^2 = 4 and df=1df = 1, the p-value is about 0.0455. Since 0.0455<0.050.0455 < 0.05, reject H0H_0 and conclude there is convincing evidence of a difference in success rates between the treatments.

Frequently asked questions

Why square the difference between observed and expected counts?

Squaring makes every difference positive so overshoots and undershoots both add to the statistic instead of canceling. Dividing by the expected count then scales each term, so a gap counts more when fewer observations were expected.