Skip to main content

Unit 3 · Topic 3.15

3.15 Carrying Out a Chi-Square Test for Homogeneity or Independence

Carrying out a chi-square test means computing expected counts, adding up (observed − expected)²/expected over every cell, finding the p-value with df = (rows − 1)(columns − 1) and stating a conclusion in context. Looking at which cells contribute most tells you where the difference is.

Key terms

  • expected count
  • chi-square statistic (χ²)
  • df = (rows − 1)(columns − 1)
  • p-value
  • conclusion in context

Expected counts

Expected count = (row total × column total) ÷ table total. This is the count you'd expect in a cell if H₀ were true. It comes from independence: P(row and column) = P(row) × P(column), times the total.

Expected counts don't have to be whole numbers. Don't round them to integers.

A quick check: the expected counts in each row add up to that row's total, and the same holds for columns. If they don't, there's an arithmetic error.

The statistic and df

χ² = Σ (observed − expected)² / expected, summed over every cell in the table (not including totals). It's on the formula sheet.

Degrees of freedom: df = (number of rows − 1)(number of columns − 1). A 3 × 3 table has df = 2 × 2 = 4.

The p-value is the area to the right of χ² under the chi-square distribution with that df: P(χ² ≥ observed value). Use technology (χ²cdf or χ²-Test) or a table. Chi-square tests are always right-tailed, since only large values count as evidence against H₀.

Interpreting the p-value

"Assuming there is no association between age group and main news source among adults in the state, there is about a 0.00001 probability of getting a χ² statistic of 27.8 or larger by chance alone." As always, the interpretation starts by assuming H₀ in context.

Conclusion

Comparison, decision, context, as always. If you reject H₀ in a test for independence, say there's convincing evidence of an association between the two variables in the population. If you fail to reject, say there isn't convincing evidence of an association. Don't say the variables are independent; that would be accepting H₀.

Where is the difference?

After rejecting H₀, look at the cell contributions, (O − E)²/E. The biggest ones show where observed and expected counts differ most. Compare observed with expected in those cells to describe the pattern: "Far more younger adults than expected get news online, and fewer than expected rely on TV."

On the calculator

Enter the observed counts (not totals) as a matrix and run the χ²-Test. It returns χ², the p-value and df, and stores the expected counts in a second matrix, which you can use to check the expected counts condition.

For a 2 × 2 table, the chi-square test gives the same p-value as a two-sided two-sample z-test, and χ² equals z². For the flu-shot data, z ≈ 2.24 and χ² ≈ 5.02 ≈ 2.24², both with a two-sided p-value of about 0.025.

Worked examples

Try each one yourself first, then open the solution.

  1. Example 1Calculator allowed

    Test for independence

    A random sample of 400 adults in a large state records age group and main news source. 18–34: online 90, TV 30, other 20. 35–54: online 70, TV 50, other 20. 55+: online 40, TV 60, other 20. Test at α = 0.05 whether age group and news source are associated.

    Show the solution
    1. Step 1: H₀: there is no association between age group and main news source among adults in the state. Hₐ: there is an association. Chi-square test for independence.
    2. Step 2: Totals: rows 140, 140, 120; columns online 200, TV 140, other 60; table 400.
    3. Step 3: Expected counts: 18–34 and 35–54 rows: online 70, TV 49, other 21. 55+ row: online 60, TV 42, other 18. All greater than 5. Random sample, and 400 is less than 10% of the state's adults.
    4. Step 4: Contributions: 18–34: (90 − 70)²/70 ≈ 5.71, (30 − 49)²/49 ≈ 7.37, (20 − 21)²/21 ≈ 0.05. 35–54: 0, 0.02, 0.05. 55+: (40 − 60)²/60 ≈ 6.67, (60 − 42)²/42 ≈ 7.71, (20 − 18)²/18 ≈ 0.22.
    5. Step 5: χ² ≈ 27.80 with df = (3 − 1)(3 − 1) = 4.
    6. Step 6: p-value = P(χ² ≥ 27.80) ≈ 0.00001.
    7. Step 7: The p-value is far below 0.05, so reject H₀.

    Answer: χ² ≈ 27.8, df = 4, p-value ≈ 0.00001. There is convincing evidence of an association between age group and main news source among adults in the state. The largest contributions show younger adults use online sources more, and TV less, than expected, with the reverse for adults 55+.

  2. Example 2Calculator allowed

    Test for homogeneity

    Finish the three-school club test from 3.14 (yes/no: A 30/20, B 25/25, C 15/35; expected yes 23.3 and no 26.7 for each school). Use α = 0.05.

    Show the solution
    1. Step 1: χ² = Σ (O − E)²/E over all 6 cells ≈ 9.375.
    2. Step 2: df = (3 − 1)(2 − 1) = 2.
    3. Step 3: p-value = P(χ² ≥ 9.375) ≈ 0.0092.
    4. Step 4: 0.0092 < 0.05, so reject H₀.

    Answer: χ² ≈ 9.38, df = 2, p-value ≈ 0.009. There is convincing evidence that the distribution of club membership differs among students at the three schools. School C has far fewer members than expected (15 vs. 23.3).

  3. Example 3Calculator allowed

    Trap: including totals or wrong df

    A student computes df for a 2 × 3 table as 2 × 3 = 6 and includes the total row in the χ² sum. Fix both errors.

    Show the solution
    1. Step 1: df = (rows − 1)(columns − 1) = (2 − 1)(3 − 1) = 2.
    2. Step 2: χ² sums only over the 6 interior cells; totals are not cells.

    Answer: df = 2, and sum over the 6 interior cells only.

Common mistakes

  • Using rows × columns for df instead of (rows − 1)(columns − 1).
  • Rounding expected counts to whole numbers, or swapping observed and expected in the formula.
  • Concluding "the variables are independent" after failing to reject H₀.
  • Finding a two-tailed or left-tailed p-value. Chi-square p-values are always the right tail.

On the exam

  • Show at least one expected count calculation and one contribution, then give χ², df and the p-value.
  • If asked which cell contributes most to χ², find the largest (O − E)²/E and describe in context whether the observed count was above or below expected.

Connected topics

Videos

  • Chi-Square Test for Independence (FULL Tutorial) | AP Statistics Review

    Michael Porinchak - AP Statistics & AP PrecalculusWatch on YouTube (opens in a new tab)

  • AP Stats 3.B.5 - Chi-Square Test for Independence

    Skew The ScriptWatch on YouTube (opens in a new tab)

  • Chi-square test for association (independence) | AP Statistics | Khan Academy

    Khan AcademyWatch on YouTube (opens in a new tab)

  • Chi-square Tests of Independence (Chi-square Tests for Two-Way Tables)

    jbstatisticsWatch on YouTube (opens in a new tab)

  • AP Statistics The Chi-Square Distribution – The Chi-Square Test for Association/Independence

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • AP Statistics: Topic 8.4 Expected Counts in Two Way Tables

    Michael Porinchak - AP Statistics & AP PrecalculusWatch on YouTube (opens in a new tab)

Check yourself

3 questions on 3.15 Carrying Out a Chi-Square Test for Homogeneity or Independence. Pick an answer to see if you got it, and why.

Question 1 of 3Calculator allowed

In a chi-square test, one cell has an observed count of 60 and an expected count of 39. What is this cell's contribution to the χ² statistic?

Question 2 of 3Calculator allowed

A chi-square test for homogeneity on a table with 3 rows and 2 columns gives χ² = 4.10. What is the p-value?

Question 3 of 3Calculator allowed

A school compares the distribution of preferred lunch period (early, middle or late) for random samples of 9th, 10th, 11th and 12th graders. A chi-square test gives a p-value of 0.31. Which conclusion is correct at α = 0.05?

0 of 3 answered