Scribe logoScribeNotes & practice
Sign inStart free
  1. Notes
  2. ›AP Statistics
  3. ›3 Inference for Categorical Data: Proportions
  4. ›3.15 Carrying out a chi-square test for two-way tables

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.

  • 4 min read
  • 5 parts
  • 10 questions
  • Draft
Start a Quick 5 on this topic→Jump to the 10 questions
1/5The chi-square statistic adds up squared gaps from expected counts
  1. 1The chi-square statistic adds up squared gaps from expected counts
  2. 2Each cell adds one term to the chi-square total
  3. 3Degrees of freedom depend on the table's rows and columns
  4. 4The p-value is the area to the right of the statistic
  5. 5The decision and conclusion refer to the distributions in context
  6. Check your recall
  7. Practice: 10 questions
1

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 H0H_0H0​. The chi-square statistic adds the scaled gaps from every cell into one number.

The formula is χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}χ2=∑E(O−E)2​, where OOO is the observed count and EEE is the expected count. Squaring keeps gaps from canceling. Dividing by EEE 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 H0H_0H0​ is true, observed counts should sit close to expected counts, so χ2\chi^2χ2 should be small.

Key term

chi-square statistic

The chi-square statistic, χ2\chi^2χ2, is the sum over all cells of (O−E)2E\frac{(O-E)^2}{E}E(O−E)2​, where OOO is the observed and EEE the expected count.

Part 1 done

2

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: observed 50 pizza, 30 salad, 40 wrap, with expected counts 42, 36, 42. Seniors: observed 20 pizza, 30 salad, 30 wrap, with expected counts 28, 24, 28. Calculate the chi-square statistic.
  1. 1
    Freshmen: (50−42)242≈1.524\frac{(50-42)^2}{42} \approx 1.52442(50−42)2​≈1.524, (30−36)236=1.000\frac{(30-36)^2}{36} = 1.00036(30−36)2​=1.000, (40−42)242≈0.095\frac{(40-42)^2}{42} \approx 0.09542(40−42)2​≈0.095.
  2. 2
    Seniors: (20−28)228≈2.286\frac{(20-28)^2}{28} \approx 2.28628(20−28)2​≈2.286, (30−24)224=1.500\frac{(30-24)^2}{24} = 1.50024(30−24)2​=1.500, (30−28)228≈0.143\frac{(30-28)^2}{28} \approx 0.14328(30−28)2​≈0.143.
  3. 3
    Add all six terms: 1.524+1.000+0.095+2.286+1.500+0.143≈6.5481.524 + 1.000 + 0.095 + 2.286 + 1.500 + 0.143 \approx 6.5481.524+1.000+0.095+2.286+1.500+0.143≈6.548.

Answer: χ2≈6.55\chi^2 \approx 6.55χ2≈6.55.

Exam tip

Show the first term or two of the sum, then the total. Keep extra decimals until the final rounding.

Part 2 done

Quick check

One question on the part you just read

Easy

Identify the correct formula for the chi-square statistic.
Show answer and explanation

Answer: D · Worked explanation

The statistic squares each gap and divides by the expected count. Without squaring, positive and negative gaps cancel. Dividing by the observed count scales the gap by the wrong quantity, and leaving out the division treats a gap in a small cell the same as one in a large cell.
3

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 df=(r−1)(c−1)df = (r-1)(c-1)df=(r−1)(c−1). Here rrr is the number of rows, and ccc 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 df=(2−1)(3−1)=2df = (2-1)(3-1) = 2df=(2−1)(3−1)=2.

Common mistake

Counting the totals as a row or column gives the wrong degrees of freedom and p-value.

Key term

degrees of freedom

The degrees of freedom of a two-way table test is the number df=(r−1)(c−1)df = (r-1)(c-1)df=(r−1)(c−1) that selects the chi-square curve.

Part 3 done

4

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 χ2\chi^2χ2 upward, so only the right tail counts as evidence against H0H_0H0​. As the degrees of freedom increase, the curve shifts right and flattens.

Figure 1. The p-value is the area under the curve to the right of the observed statistic of 6.55.

The p-value is the area to the right of the statistic, assuming H0H_0H0​ is true. Find it with a calculator function such as χ2cdf\chi^2\text{cdf}χ2cdf or a table. For χ2=6.55\chi^2 = 6.55χ2=6.55 with df=2df = 2df=2, 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 χ2\chi^2χ2 when the null hypothesis is true.

Part 4 done

Quick check

One question on the part you just read

Easy

A two-way table has 3 rows and 4 columns of categories, not counting totals. Determine the degrees of freedom.
Show answer and explanation

Answer: D · Worked explanation

df=(r−1)(c−1)=(3−1)(4−1)=6df = (r-1)(c-1) = (3-1)(4-1) = 6df=(r−1)(c−1)=(3−1)(4−1)=6. The value 12 multiplies the rows and columns without subtracting 1. The value 7 adds them, and 11 subtracts 1 from the number of cells, which is a rule for a different test.
5

Part 5 of 5: The decision and conclusion refer to the distributions in context

The last step compares the p-value with α\alphaα and says what it means. Reject H0H_0H0​ when the p-value is less than α\alphaα. Otherwise, fail to reject H0H_0H0​.

For the lunch survey with α=0.05\alpha = 0.05α=0.05, we have 0.038<0.050.038 < 0.050.038<0.05, so we reject H0H_0H0​. 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.

Common mistake

A significant result does not show that every group differs. It shows only that the distributions are not all the same.

Go deeperLink to the two-proportion test

For a 2 by 2 table comparing two proportions with a two-sided alternative, the chi-square statistic equals the square of the two-proportion z statistic. The degrees of freedom are 1, and the p-values match.

This shows that both tests answer the same question when only two groups and two outcomes are present.

Note read

Check your recall[14 marks]

6 written questions. Answer each one in your head or on paper, then open the mark scheme.

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

    χ2=(30−24)224+(20−26)226+(18−24)224+(32−26)226=1.500+1.385+1.500+1.385≈5.77\chi^2 = \frac{(30-24)^2}{24} + \frac{(20-26)^2}{26} + \frac{(18-24)^2}{24} + \frac{(32-26)^2}{26} = 1.500 + 1.385 + 1.500 + 1.385 \approx 5.77χ2=24(30−24)2​+26(20−26)2​+24(18−24)2​+26(32−26)2​=1.500+1.385+1.500+1.385≈5.77.

    • 1 mark for using (O−E)2E\frac{(O-E)^2}{E}E(O−E)2​ for each cell
    • 1 mark for calculating the four terms correctly
    • 1 mark for adding them to get χ2≈5.77\chi^2 \approx 5.77χ2≈5.77
  2. 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

    df=(4−1)(3−1)=6df = (4-1)(3-1) = 6df=(4−1)(3−1)=6.

    • 1 mark for using (r−1)(c−1)(r-1)(c-1)(r−1)(c−1)
    • 1 mark for obtaining 6
  3. 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. 4.Justify[3 marks]

    Justify a conclusion in context for a test of homogeneity of preferred study method across three grade levels, with χ2=7.20\chi^2 = 7.20χ2=7.20, df=2df = 2df=2, p-value 0.027, and α=0.05\alpha = 0.05α=0.05.

    Show mark schemeHide mark scheme

    Model answer

    Because 0.027<0.050.027 < 0.050.027<0.05, we reject H0H_0H0​. 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 α\alphaα
    • 1 mark for rejecting the null hypothesis
    • 1 mark for concluding in context that the distributions are not all the same
  5. 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. 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.

3.

Easy·Identify[1 mark]

Identify the area under the chi-square curve that gives the p-value.
Show answer and explanation

Answer: B · Worked explanation

Large gaps from the expected counts produce large chi-square values, so only the right tail counts as evidence against the null hypothesis. The left area measures values that are smaller than observed. A chi-square curve has only one tail of interest, so doubling or using both tails does not apply.
4.

Medium·Calculate[2 marks]

A table has observed counts 18 and 12 in row 1, and 22 and 28 in row 2. The expected counts are 15 and 15 in row 1, and 25 and 25 in row 2. Calculate the chi-square statistic.
Show answer and explanation

Answer: A · Worked explanation

915+915+925+925=0.60+0.60+0.36+0.36=1.92\frac{9}{15} + \frac{9}{15} + \frac{9}{25} + \frac{9}{25} = 0.60 + 0.60 + 0.36 + 0.36 = 1.92159​+159​+259​+259​=0.60+0.60+0.36+0.36=1.92. The value 1.98 comes from dividing by observed counts. The value 36 leaves out the division by expected counts, and 0.48 divides the correct total by the number of cells.
5.

Medium·Determine[2 marks]

A chi-square test has df=2df = 2df=2. The calculator gives 0.90 as the area to the left of the statistic. Determine the p-value.
Show answer and explanation

Answer: B · Worked explanation

The p-value is the area to the right, so it is 1−0.90=0.101 - 0.90 = 0.101−0.90=0.10. The value 0.90 is the area on the wrong side. Doubling to 0.20 or halving to 0.05 would be for a two-sided test or another tail rule, and neither applies to a chi-square test.
6.

Medium·Determine[2 marks]

A test of independence between two categorical variables for one random sample gives a p-value of 0.12 with α=0.05\alpha = 0.05α=0.05. Determine the best conclusion.
Show answer and explanation

Answer: B · Worked explanation

Because 0.12>0.050.12 > 0.050.12>0.05, we fail to reject H0H_0H0​, and the data do not give convincing evidence of an association. This does not show the variables are independent or that one has no effect on the other. Rejecting would require a p-value below α\alphaα.
7.

Medium·Determine[2 marks]

Separate random samples from three treatment groups give a chi-square test of homogeneity with a p-value of 0.003 and α=0.05\alpha = 0.05α=0.05. Determine the best conclusion in context.
Show answer and explanation

Answer: C · Worked explanation

A p-value below the significance level rejects the null hypothesis that the distributions are the same, so at least one distribution differs. The test does not show that all three differ, nor does it give a probability for the null hypothesis. Concluding that the distributions are the same would reverse the result.
8.

Hard·Determine[2 marks]

In a table, one cell has observed 9 and expected 5. A second has observed 60 and expected 50. A third has observed 35 and expected 30. A fourth has observed 20 and expected 24. Determine which cell contributes most to the chi-square statistic.
Show answer and explanation

Answer: B · Worked explanation

The contributions are 165=3.20\frac{16}{5} = 3.20516​=3.20, 10050=2.00\frac{100}{50} = 2.0050100​=2.00, 2530≈0.83\frac{25}{30} \approx 0.833025​≈0.83, and 1624≈0.67\frac{16}{24} \approx 0.672416​≈0.67. The cell with observed 60 has the largest raw gap of 10, but dividing by its large expected count reduces its contribution below the first cell.
9.

Hard·Predict[2 marks]

Every observed count in a two-way table is doubled, so every expected count also doubles. Predict what happens to the chi-square statistic and the degrees of freedom.
Show answer and explanation

Answer: C · Worked explanation

Each term becomes (2O−2E)22E=2⋅(O−E)2E\frac{(2O-2E)^2}{2E} = 2\cdot\frac{(O-E)^2}{E}2E(2O−2E)2​=2⋅E(O−E)2​, so χ2\chi^2χ2 doubles. The degrees of freedom depend only on the number of rows and columns, so they do not change. Squaring the gap alone would quadruple it, but dividing by the doubled expected count removes half of that.
10.

Hard·Determine[2 marks]

A test uses a table with 2 rows and 3 columns. The chi-square statistic is 8.0, and a calculator gives 0.018 as the area to the right of 8.0 for the correct degrees of freedom. Determine the decision at α=0.01\alpha = 0.01α=0.01.
Show answer and explanation

Answer: A · Worked explanation

The degrees of freedom are (2−1)(3−1)=2(2-1)(3-1) = 2(2−1)(3−1)=2. The p-value 0.018 is greater than α=0.01\alpha = 0.01α=0.01, so we fail to reject H0H_0H0​. Comparing with 0.05 uses the wrong cutoff. The values 6 and 5 come from multiplying the rows and columns and from subtracting 1 from the number of cells.

Keep going

Next topic4.1 Sample meansPrevious topic3.14 Setting up a chi-square test for two-way tables

More in Unit 3 · Inference for Categorical Data: Proportions

  1. 3.7Carrying out a test for a proportionNotes · 10 questions
  2. 3.8Errors in testsNotes · 10 questions
  3. 3.9Differences in sample proportionsNotes · 10 questions
  4. 3.10Interval for a difference of proportionsNotes · 10 questions
  5. 3.11Claims from a difference intervalNotes · 10 questions
  6. 3.12Setting up a two-proportion testNotes · 10 questions
  7. 3.13Carrying out a two-proportion testNotes · 10 questions
  8. 3.14Setting up a chi-square test for two-way tablesNotes · 10 questions
  9. 3.15Carrying out a chi-square test for two-way tablesNotes · 10 questions

All AP Statistics topics →

Draft: written by Scribe and checked automatically, not yet by a subject reviewer.

Practice questions are original, written by Scribe and checked automatically for correctness.

Topic codes follow the official numbering. Not endorsed by College Board or any exam board.

On this page

0/5 read

  1. 1The chi-square statistic adds up squared gaps from expected counts
  2. 2Each cell adds one term to the chi-square total
  3. 3Degrees of freedom depend on the table's rows and columns
  4. 4The p-value is the area to the right of the statistic
  5. 5The decision and conclusion refer to the distributions in context
  6. Check your recall
  7. Practice: 10 questions
All coursesScribeHow it worksPricingPrivacyTerms

Notes and questions are written by Scribe in our own words. Topic codes follow the official course numbering so you can find your place. Not produced or endorsed by the IB, College Board, AQA, OCR, Pearson Edexcel or any exam board.

© 2026 Scribe

Chi-square curve with 2 degrees of freedom

Density0246810121400.10.20.30.40.5Chi-square value
  • Chi-square curve, df = 2
  • Observed statistic 6.55