AP Statistics · Unit 3 · Inference for Categorical Data: Proportions
3.15 Carrying out a chi-square test for two-way tables
Calculate the chi-square statistic and degrees of freedom for a two-way table, find the p-value, and interpret the decision in context.
1/5The chi-square statistic adds up squared gaps from expected counts
- The chi-square statistic adds up squared gaps from expected counts
- Each cell adds one term to the chi-square total
- Degrees of freedom depend on the table's rows and columns
- The p-value is the area to the right of the statistic
- The decision and conclusion refer to the distributions in context
- Check your recall
- Practice: 10 questions
Part 1 of 5: The chi-square statistic adds up squared gaps from expected counts
After finding the expected counts, we measure how far the observed table sits from them. Large gaps are evidence against . The chi-square statistic adds the scaled gaps from every cell into one number.
The formula is , where is the observed count and is the expected count. Squaring keeps gaps from canceling. Dividing by makes a gap of 5 count for more in a small cell than in a large one.
The statistic is never negative. It equals 0 only when every observed count matches its expected count. When is true, observed counts should sit close to expected counts, so should be small.
Key term
chi-square statistic
The chi-square statistic, , is the sum over all cells of , where is the observed and the expected count.
Part 2 of 5: Each cell adds one term to the chi-square total
Work through the table one cell at a time. For every cell, follow these steps:
- Subtract the expected count from the observed count
- Square the result
- Divide by the expected count
- Add the results from all cells
Larger terms mark cells where the observed and expected counts are far apart. Showing each term makes your work easy to check.
Worked example
Calculating the statistic
- Freshmen: , , .
- Seniors: , , .
- Add all six terms: .
Answer: .

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: D · Worked explanation
Part 3 of 5: Degrees of freedom depend on the table's rows and columns
The statistic alone does not give a p-value. We also need the degrees of freedom to pick the right curve.
The degrees of freedom for a two-way table are . Here is the number of rows, and is the number of columns. Count only the categories, not the row or column of totals.
The lunch table has 2 rows and 3 columns. So .
Key term
degrees of freedom
The degrees of freedom of a two-way table test is the number that selects the chi-square curve.
Part 4 of 5: The p-value is the area to the right of the statistic
Now we can judge how unusual a chi-square value of 6.55 is. The chi-square distribution is a family of right-skewed curves, one for each number of degrees of freedom. Larger gaps push upward, so only the right tail counts as evidence against . As the degrees of freedom increase, the curve shifts right and flattens.
The p-value is the area to the right of the statistic, assuming is true. Find it with a calculator function such as or a table. For with , the p-value is about 0.038.
Key term
chi-square distribution
The chi-square distribution is a right-skewed family of curves, indexed by degrees of freedom, that models when the null hypothesis is true.

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: D · Worked explanation
Part 5 of 5: The decision and conclusion refer to the distributions in context
The last step compares the p-value with and says what it means. Reject when the p-value is less than . Otherwise, fail to reject .
For the lunch survey with , we have , so we reject . There is convincing evidence that the distribution of favorite lunch is not the same for freshmen and seniors.
Always state the conclusion about the populations or treatments, using the variable names. A bare statement such as reject the null hypothesis is incomplete.
Check your recall[14 marks]
6 written questions. Answer each one in your head or on paper, then open the mark scheme.
- 1.Calculate[3 marks]
Calculate the chi-square statistic for observed counts 30, 20, 18, and 32 with expected counts 24, 26, 24, and 26.
Show mark schemeHide mark scheme
Model answer
.
- 1 mark for using for each cell
- 1 mark for calculating the four terms correctly
- 1 mark for adding them to get
- 2.Determine[2 marks]
Determine the degrees of freedom for a table with 4 rows and 3 columns of categories.
Show mark schemeHide mark scheme
Model answer
.
- 1 mark for using
- 1 mark for obtaining 6
- 3.Describe[2 marks]
Describe how the p-value is found in a chi-square test for a two-way table.
Show mark schemeHide mark scheme
Model answer
Use the chi-square curve with the correct degrees of freedom. The p-value is the area to the right of the observed statistic, assuming the null hypothesis is true.
- 1 mark for using the chi-square curve with the correct degrees of freedom
- 1 mark for identifying the area to the right of the statistic
- 4.Justify[3 marks]
Justify a conclusion in context for a test of homogeneity of preferred study method across three grade levels, with , , p-value 0.027, and .
Show mark schemeHide mark scheme
Model answer
Because , we reject . There is convincing evidence that the distribution of preferred study method is not the same for all three grade levels.
- 1 mark for comparing the p-value with
- 1 mark for rejecting the null hypothesis
- 1 mark for concluding in context that the distributions are not all the same
- 5.Explain[2 marks]
Explain why each squared gap in the chi-square statistic is divided by the expected count.
Show mark schemeHide mark scheme
Model answer
Dividing by the expected count scales each gap to the size of its cell. A gap of 5 matters more in a cell expecting 10 than in a cell expecting 100.
- 1 mark for stating that the gap is scaled to the cell size
- 1 mark for explaining that the same gap matters more in a small cell
- 6.Interpret[2 marks]
Interpret a p-value of 0.027 in the test of homogeneity of preferred study method across three grade levels.
Show mark schemeHide mark scheme
Model answer
If the distribution of preferred study method were the same for all three grade levels, there would be about a 2.7% chance of a chi-square statistic at least this large.
- 1 mark for assuming the distributions are the same
- 1 mark for stating a probability of about 0.027 of a statistic at least this large

Practice this topic
10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)
0 right0 of 10 answered
Includes the 2 quick checks in the note above.
EasyIdentify[1 mark]
Show answer and explanation
Answer: B · Worked explanation
MediumCalculate[2 marks]
Show answer and explanation
Answer: A · Worked explanation
MediumDetermine[2 marks]
Show answer and explanation
Answer: B · Worked explanation
MediumDetermine[2 marks]
Show answer and explanation
Answer: B · Worked explanation
MediumDetermine[2 marks]
Show answer and explanation
Answer: C · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: B · Worked explanation
HardPredict[2 marks]
Show answer and explanation
Answer: C · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: A · Worked explanation