AP Statistics · Study guide

Add the squared gaps.

AP® Statistics · Unit 3 · Inference for Categorical Data: Proportions

Carrying Out a Chi-Square Test

How to compute expected counts, the chi-square statistic and its degrees of freedom, find and interpret the p-value, and write a conclusion for a test of homogeneity or independence.

The idea in one paragraph

Find what H₀ predicts for every cell (the expected counts), then add up how far each observed count is from its prediction: \(\chi^2 = \sum (O - E)^2/E\). If H₀ is true, \(\chi^2\) follows a chi-square distribution with \((r - 1)(c - 1)\) degrees of freedom. The p-value is the area to the right of the observed \(\chi^2\).

1Expected counts and the chi-square statistic

\[ \text{expected count} = \frac{(\text{row total})(\text{column total})}{\text{table total}} \qquad \chi^2 = \sum \frac{(\text{observed count} - \text{expected count})^2}{\text{expected count}} \]

The sum is taken over every cell of the table, not the totals. When H₀ is true, the statistic has a chi-square distribution with

\[ df = (\text{number of rows} - 1)(\text{number of columns} - 1) \]
Worked Example 1 Expected counts and the statistic

Getting to school

Independent random samples of students at three schools gave the observed counts below (conditions were checked earlier). Compute the chi-square statistic and its degrees of freedom.

BusCarWalk or bikeTotal
School A605436150
School B304822100
School C604842150
Total150150100400
  1. 1Expected count = (row total)(column total) / table total. School A, Bus: \(150 \times 150/400 = 56.25\).
  2. 2Each cell: \((O - E)^2/E\). School A, Bus: \((60 - 56.25)^2/56.25 = 0.25\). School B, Car: \((48 - 37.5)^2/37.5 = 2.94\).
  3. 3Add all nine pieces (Figure 1): \(\chi^2 = 7.20\).
  4. 4\(df = (\text{rows} - 1)(\text{columns} - 1) = (3 - 1)(3 - 1) = 4\).
Answer: χ² = 7.20 with df = 4.
Figure 1. Each cell compares its observed and expected counts. Squaring makes every piece positive, and dividing by the expected count judges each gap against the size of the cell. School B’s car cell (48 observed, 37.5 expected) contributes the most.
Common Mistake 1 · Counting degrees of freedom from the cells

A 3 by 3 table has 9 cells but only \((3 - 1)(3 - 1) = 4\) degrees of freedom. Use the numbers of rows and columns of categories, leaving out the totals.

Common Mistake 2 · Including the total row or column in the sum

Totals are not cells. Adding a “piece” for the total row double counts the data and inflates \(\chi^2\).

2The p-value

The p-value comes from the chi-square distribution with the right degrees of freedom, using a table or technology. Large values of \(\chi^2\) are the evidence against H₀, so the p-value is always the area in the right tail.

Figure 2. The p-value is the area to the right of the observed statistic under the chi-square curve with (3 − 1)(3 − 1) = 4 degrees of freedom. A value of 7.20 or larger happens about 12.6% of the time when H₀ is true.
Worked Example 2 Interpret the p-value

Getting to school

Interpret the p-value of 0.126.

  1. 1State the assumption: H₀ in context.
  2. 2Then the result: a chi-square statistic of 7.20 or more, and the sample sizes.
Answer: Assuming that there is no difference in the distributions of how students usually get to school at the three schools, there is a 0.126 probability of getting a chi-square statistic of 7.20 or more in random samples of 150, 100, and 150 students.
Say it like this

“Assuming that there is no difference in the distributions of how students usually get to school at the three schools, there is a 0.126 probability of getting a chi-square statistic of 7.20 or more in random samples of 150, 100, and 150 students.”

On the calculator

Enter the observed counts (no totals) into matrix [A]. STAT, TESTS, χ²-Test, Observed: [A], Expected: [B], Calculate. The output shows χ² = 7.2, p = 0.1257, df = 4, and the calculator stores the expected counts in [B] so you can check the expected counts condition.

3The decision and the conclusion

Compare the p-value with α. If the p-value ≤ α, reject H₀; if the p-value \(\gt\) α, fail to reject H₀. State the conclusion in context, in terms of the alternative hypothesis, with non-definitive language, naming the population (independence) or populations (homogeneity).

Worked Example 3 p-value, decision and conclusion

Getting to school

Using \(\chi^2 = 7.20\) with df = 4, finish the test at \(\alpha = 0.05\).

  1. 1p-value \(= P(\chi^2_4 \ge 7.20) \approx 0.126\).
  2. 20.126 is greater than 0.05, so fail to reject \(H_0\).
Answer: Because the p-value of 0.126 is greater than α = 0.05, we fail to reject H₀. There is not convincing evidence that the distributions of how students usually get to school differ among all students at School A, School B, and School C.
Common Mistake 3 · Writing “the distributions are the same”

A p-value of 0.126 means the school data are consistent with matching distributions, not that the distributions match. Write “there is not convincing evidence that the distributions differ.”

4A test for independence, start to finish

Worked Example 4 A complete test for independence

Grade and part-time jobs

A random sample of 240 students at a high school with 2,600 students found that 12 of 80 tenth graders, 22 of 80 eleventh graders, and 34 of 80 twelfth graders have a part-time job. Is there convincing evidence at \(\alpha = 0.05\) of an association between grade level and having a part-time job?

  1. 1State. H₀: There is no association between grade level and having a part-time job among students at the school. Hₐ: There is an association. \(\alpha = 0.05\).
  2. 2Plan. Chi-square test for independence. Randomization: one random sample. 10% condition: 240 ≤ 260. Expected counts: 22.67 with a job and 57.33 without in each grade, all at least 5.
  3. 3Do. Pieces with a job: 5.02, 0.02, 5.67. Pieces without: 1.98, 0.01, 2.24. \(\chi^2 \approx 14.94\), \(df = (3 - 1)(2 - 1) = 2\), p-value \(\approx 0.0006\).
  4. 4Conclude. Because the p-value of 0.0006 is less than \(\alpha = 0.05\), we reject H₀. There is convincing evidence of an association between grade level and having a part-time job among students at the school.
Answer: Reject H₀. The largest pieces show where: fewer 10th graders and more 12th graders have jobs than independence would predict (Figure 3).
Figure 3. If grade and having a job were independent, each grade would have about 22.67 students with a job. Tenth graders have far fewer (12) and twelfth graders far more (34). Those two cells give the largest pieces of the chi-square statistic, 5.02 and 5.67.
Common Mistake 4 · Reading association as cause

A test for independence uses one random sample and no assigned treatments. Convincing evidence of an association between grade and having a job does not show that being in a higher grade causes students to get jobs. Only a randomized experiment, analyzed with a test for homogeneity across treatments, supports a cause and effect conclusion.

The conclusion, start to finish

“Because the p-value of 0.0006 is less than α = 0.05, we reject H₀. There is convincing evidence of an association between grade level and having a part-time job among students at the school.”

Quick reference

StepWhat to write
Expected counts(row total)(column total) ÷ table total, for every cell
Statistic\(\chi^2 = \sum (O - E)^2/E\) over all cells
Degrees of freedom\((r - 1)(c - 1)\)
p-valueRight-tail area under the chi-square curve: \(P(\chi^2 \ge \text{observed})\)
Decisionp-value ≤ α: reject H₀; p-value \(\gt\) α: fail to reject H₀
ConclusionConvincing evidence (or not) for Hₐ in context, naming the population(s)
Calculatorχ²-Test with the observed counts in a matrix