Sign up freeSign in

Exam prep · AP Statistics · Unit guide

AP Statistics Unit 8: Inference for categorical data: chi-square

How goodness of fit, homogeneity and independence tests work, and how to tell them apart

On the exam: Goodness of fit, homogeneity, independence. 2 to 5%.

Take the AP Statistics quiz Study the flashcards Make flashcards from my notes
AP Statistics Unit 8: Inference for categorical data: chi-square mindmap: Comparing Observed and Expected Counts, The Chi-Square Statistic, The Chi-Square Distributions, Goodness of Fit, Homogeneity vs. Independence, Expected Counts in a Two-Way Table, Checking the Conditions, Worked Example: Candy Colors, Writing the Conclusion
The unit on one page. Open the image to save or print it.

Quick question: if a chi-square test gives you a large P-value, have you proved the null hypothesis is true? Lots of students say yes, and that's the trap. In this statistics unit, we'll build the chi-square statistic, compare the three tests, and work a full example.

In this guide
  1. Comparing Observed and Expected Counts
  2. The Chi-Square Statistic
  3. The Chi-Square Distributions
  4. Goodness of Fit
  5. Homogeneity vs. Independence
  6. Expected Counts in a Two-Way Table
  7. Checking the Conditions
  8. Worked Example: Candy Colors
  9. Writing the Conclusion

Comparing Observed and Expected Counts

Chi-square tests are built for categorical data, where each individual lands in a category like eye color or favorite sport. Instead of working with means or a single proportion, you're comparing counts. The idea is simple. You figure out the counts you'd expect if the null hypothesis were true, then measure how far your observed counts stray from them. Big gaps are evidence against the null.

Key points.

  • Chi-square tests are for categorical data
  • They compare counts, not means
  • Expected counts come from assuming H0 is true
  • Big gaps between observed and expected count against H0

The Chi-Square Statistic

Here's the statistic. Chi-square equals the sum, over every cell, of observed minus expected, squared, divided by expected. O stands for the observed count and E for the expected count. Because each difference gets squared, chi-square can never be negative, and it's zero only when every observed count matches its expected count exactly. Always plug in counts here, never percentages, or the value comes out wrong.

χ² = Σ (O − E)²/E
O = observed count
E = expected count
χ² ≥ 0

Key points.

  • Sum of (observed minus expected) squared over expected
  • Add up one term for every cell
  • Chi-square is never negative
  • Always use counts, never percentages

The Chi-Square Distributions

The statistic follows a chi-square distribution, which is really a whole family of curves set by the degrees of freedom. Each curve starts at zero and is skewed to the right, and its mean equals its degrees of freedom. As the degrees of freedom grow, the curve shifts right and looks more symmetric. The P-value is always the area in the right tail beyond your statistic, because only large values signal a poor fit.

Key points.

  • A family of curves set by degrees of freedom
  • Right-skewed, starting at zero
  • Mean equals the degrees of freedom
  • P-value is always the right-tail area

Goodness of Fit

The first test is goodness of fit. You have one sample and one categorical variable, and you check it against a claimed distribution. The null hypothesis says all the claimed proportions are correct, and the alternative says at least one of them is wrong. Each expected count is the sample size times that category's claimed proportion, and the degrees of freedom are the number of categories minus one.

Goodness of fit asks whether one categorical variable from one sample matches a claimed distribution. Chi-square goodness-of-fit test

Key points.

  • One sample, one categorical variable
  • H0: the claimed proportions are correct
  • Expected count = n times the claimed proportion
  • Degrees of freedom = number of categories minus 1

Homogeneity vs. Independence

Students mix up the other two tests all the time, and the difference comes down to how the data were collected. Homogeneity uses separate samples from two or more populations and asks whether one variable has the same distribution in each. Independence uses a single sample, classifies each individual on two variables, and asks whether those variables are associated. The arithmetic is identical, but the hypotheses and wording aren't.

Homogeneity

  • Two or more independent samples
  • One categorical variable
  • H0: same distribution in every group
  • Example: sport preference at 3 schools

Independence

  • One single random sample
  • Two categorical variables
  • H0: no association between variables
  • Example: grade level vs. sport preference

Expected Counts in a Two-Way Table

For a two-way table, each expected count is the row total times the column total, divided by the table total. So if a row has forty, a column has fifty, and the table has two hundred, the expected count is forty times fifty over two hundred, which is ten. The degrees of freedom are rows minus one times columns minus one, so a three by four table gives two times three, or six.

E = (row total)(col total)/table total
E = (40)(50)/200 = 10
df = (r − 1)(c − 1)
3 × 4 table: df = (2)(3) = 6

Key points.

  • Expected = row total times column total over table total
  • Degrees of freedom = (rows minus 1)(columns minus 1)
  • Same formulas for homogeneity and independence

Checking the Conditions

Before you trust the chi-square distribution, check three conditions. The data must come from a random sample or a randomized experiment. When you sample without replacement, the sample should be less than ten percent of the population. And for Large Counts, every expected count, not observed count, has to be at least five. Checking observed counts instead is one of the most common lost points.

5 Every expected count must be at least 5 (Large Counts condition)

Key points.

  • Random: data from a random sample or experiment
  • 10%: sample under 10% of population if no replacement
  • Large Counts: every expected count at least 5

Worked Example: Candy Colors

Here's a typical question. A company claims its candies are thirty percent red, twenty blue, and fifty green, and a random sample of one hundred has twenty-two red, twenty-eight blue, and fifty green. Expected counts are thirty, twenty, and fifty. Red contributes two point one three, blue three point two, green zero. That's a chi-square of five point three three, two degrees of freedom, and a P-value near point zero seven.

E: 30, 20, 50  (n = 100)
(22 − 30)²/30 = 2.13
(28 − 20)²/20 = 3.20
(50 − 50)²/50 = 0
χ² = 5.33, df = 2
P ≈ 0.07 > 0.05

Key points.

  • Claim: 30% red, 20% blue, 50% green
  • Sample of 100: 22 red, 28 blue, 50 green
  • Chi-square = 5.33 with 2 degrees of freedom
  • P-value is about 0.07

Writing the Conclusion

Every test runs through the same four steps: state, plan, do, and conclude. In our example, point zero seven is above point zero five, so we fail to reject the null. We don't have convincing evidence that the claimed color distribution is wrong, but that isn't proof it's right. When you do reject, look at which cells contributed most to explain where the difference comes from.

  1. State: hypotheses and alpha, in context
  2. Plan: name the test and check conditions
  3. Do: expected counts, chi-square, df, P-value
  4. Conclude: compare P to alpha, in context
  5. Follow up: find the largest contributions

Remember this

Remember this: chi-square compares observed counts to expected counts, and the design tells you which of the three tests you're running. Now quiz yourself on the material and see if you can pick the right test every time.

Practice this unit

  • AP Statistics: Probability, Random Variables and Sampling Distributions quiz14 multiple-choice questions with explanations · no account needed
  • SAT Math: Statistics, Probability and Data Interpretation quiz15 multiple-choice questions with explanations · no account needed
  • Statistics 101: Core Concepts30 flashcards · study free
  • Statistics: Hypothesis Testing Practice30 flashcards · study free
  • AP Statistics: Probability, Random Variables and Sampling Distributions38 flashcards · study free
  • SAT Math: Statistics, Probability and Data Interpretation38 flashcards · study free

Every AP Statistics deck and quiz: the AP Statistics page.

Other AP Statistics unit guides

  • Unit 3: Collecting dataStudy guide
  • Unit 4: Probability, random variables and probability distributionsStudy guide
  • Unit 5: Sampling distributionsStudy guide
  • Unit 7: Inference for quantitative data: meansStudy guide

Try it with your own material

Upload a PDF, slides or notes and study the deck in minutes. Making your own cards is free with no limits.

Make flashcards from my notesSee how Quizcard works