AP Statistics · Topic 3.14 · Reading guide, about 5 min

Picking the right two-way table chi-square test

Learn what the chi-square statistic measures and how to choose between the homogeneity and independence tests and check conditions.

In one minute

When data fall into categories and you want to compare more than two proportions, or to ask whether two categorical variables are related, the two-proportion z-test no longer fits. A chi-square test on a two-way table handles these cases.

There are two versions that look identical on paper but answer different questions. Choosing the right one, writing its hypotheses in context, and checking expected counts is the heart of this topic.

Key terms

Chi-square statistic
χ2\chi^2, the sum over all cells of (observed minus expected) squared, divided by expected. It measures total distance from what H0H_0 predicts.
Observed count
The number of individuals actually found in a cell of the two-way table.
Expected count
The count a cell would have if H0H_0 were true, found from the row and column totals.
Chi-square distribution
A family of right-skewed distributions of positive values. Skew lessens as the degrees of freedom increase.
Test for homogeneity
Compares the distribution of one categorical variable across two or more populations or treatments.
Test for independence
Asks whether two categorical variables are associated in a single population.
Association
Two categorical variables are associated when the distribution of one changes across the categories of the other.
Expected counts condition
Every expected count must be at least 5. Check expected counts, not observed counts.

What the statistic measures

For each cell, find the gap between observed and expected, square it so that positive and negative gaps both count, and divide by the expected count so a gap of 5 matters more in a small cell than a large one. Add these contributions over every cell to get χ2\chi^2.

If observed counts are close to expected, every term is small and χ2\chi^2 is near 0. A large χ2\chi^2 means the table is far from what H0H_0 predicts. Because the terms are squares, the statistic is never negative, and only large values count as evidence, so the p-value is always the upper tail.

Its sampling distribution is a chi-square curve with (rows−1)(columns−1)(\text{rows}-1)(\text{columns}-1) degrees of freedom. These curves start at 0, are skewed right, and look more symmetric as degrees of freedom grow. This course covers the tests on two-way tables; the goodness-of-fit test is not part of it.

Homogeneity or independence?

Look at how the data were collected. In a homogeneity study you have separate groups, such as independent random samples from several populations or subjects randomly assigned to several treatments, and you compare how a categorical response is distributed in each group. In an independence study you take a single random sample from one population and record two categorical variables on each individual.

The table can be identical in both cases; the difference is in the design and wording. Homogeneity hypotheses: H0H_0: the distribution of the response variable is the same for all populations (or treatments); HaH_a: the distribution is not the same for all. Independence hypotheses: H0H_0: the two variables are independent in the population; HaH_a: the two variables are associated. For example, if one random sample of 300 students at a school records each student's grade level and favorite type of exercise, then H0H_0: grade level and favorite type of exercise are independent among students at this school; HaH_a: grade level and favorite type of exercise are associated among students at this school.

Choosing between the two chi-square tests
FeatureHomogeneityIndependence
DesignSeveral independent random samples, or random assignment to treatmentsOne random sample, two variables recorded
QuestionIs the response distribution the same in every group?Are the two variables associated?
RandomizationIndependent random samples or a randomized experimentOne random sample from the population
Conditions10% condition for samples; all expected counts at least 510% condition; all expected counts at least 5

Conditions, checked in context

Randomization: for independence, one random sample; for homogeneity, independent random samples or a randomized experiment. 10% condition: when sampling without replacement, each sample is less than 10% of its population; not needed in an experiment. Counts: every expected count is at least 5, and you must compute the expected counts to show it.

If a table has many cells, one small expected count is enough to fail the condition. Then the chi-square distribution may be a poor model, and you may need to combine categories sensibly or collect more data.

Worked example

A gardener randomly assigns 180 seedlings to three fertilizers, 60 each, and records whether each seedling survived (invented data). Survived: A 48, B 42, C 36, for 126 in all. Died: A 12, B 18, C 24, for 54 in all. Because treatments were randomly assigned and one response is compared across treatments, this is a chi-square test for homogeneity.

Hypotheses: H0H_0: the true distribution of survival (survived or died) is the same for all three fertilizers. HaH_a: the distribution of survival is not the same for all three fertilizers.

Conditions: random assignment holds, so no 10% check. Expected survived count for each fertilizer is 126(60)/180=42126(60)/180=42 and expected died count is 54(60)/180=1854(60)/180=18, all at least 5.

Statistic: for fertilizer A, (48−42)2/42=0.8571(48-42)^2/42=0.8571 and (12−18)2/18=2.0000(12-18)^2/18=2.0000. Fertilizer B matches expected exactly, so contributes 0. For C, (36−42)2/42=0.8571(36-42)^2/42=0.8571 and (24−18)2/18=2.0000(24-18)^2/18=2.0000. The sum is χ2=5.7143\chi^2=5.7143 with (3−1)(2−1)=2(3-1)(2-1)=2 degrees of freedom. The p-value, about 0.057, is found in 3.15, where the conclusion is written.

How it connects

  • Back to 2.1 and 2.2: two-way tables and conditional relative frequencies are how you first see whether a distribution changes across groups.
  • Back to 3.13: a two-sided two-proportion z-test is equivalent to the homogeneity test with two groups and two outcomes; a one-sided z-test has no chi-square counterpart.
  • Back to 1.13: random assignment is what makes a homogeneity test in an experiment support a cause-and-effect conclusion.
  • Forward to 3.15: expected counts, degrees of freedom, the p-value and the conclusion are completed there.

Common mistakes

  • Checking observed counts instead of expected counts. The condition is on expected counts, all at least 5.
  • Choosing the test by the table instead of the design. Ask how the data were collected: several groups or one sample.
  • Writing hypotheses about the sample or without context. State them about the populations or treatments, naming the variables in context; a bare 'the variables are independent' is not enough.
  • Using a goodness-of-fit setup. This course uses only the two-way table tests.

How it shows up on the exam

  • A scenario describes how data were collected and asks which test applies, with a reason.
  • A written prompt asks for hypotheses in context for homogeneity or independence.
  • A prompt asks you to verify the expected counts condition from a two-way table.

Check yourself

  1. A school surveys one random sample of students about club membership and sleep habits. Which test fits, and why?
  2. Why can the chi-square statistic never be negative?
  3. If students were instead randomly assigned to three homework schedules and each student's sleep category was recorded, which test would fit, and how would you word its hypotheses?

Practice this topic. AP Practice questions on exactly what this lesson covers, with an explanation for every answer.