AP-STATS-8.4-8.6

U8.4 Chi-Square for Two-Way Tables

Master AP Statistics chi-square tests for two-way tables: compute expected counts, tell homogeneity from independence, and find df = (r−1)(c−1).

What you'll do in this lesson

A voice-first session with the Crimsora tutor on U8.4 Chi-Square for Two-Way Tables, then targeted practice and FRQs — with the tutor adapting to where you get stuck.

What this lesson covers

By now you've handled the chi-square goodness-of-fit test on a single row of counts. This lesson scales that idea up to a full two-way table, where rows and columns cross two categorical variables. You'll learn one formula for expected counts, one degrees-of-freedom rule, and one big conceptual distinction that AP graders love to probe: are you testing homogeneity across several populations or independence of two variables measured on one population?

The arithmetic is nearly identical for both tests, so the exam rewards students who can read the study design and name the correct procedure. We'll build the expected-count table, explain the mechanism behind the formula, and show exactly how conclusions must be worded differently depending on how the data were collected.

Computing Expected Counts

Every cell in a two-way table gets an expected count — the number you'd predict if there were no association between the variables. The formula isE=(row total)(column total)grand totalE = \frac{(\text{row total}) \cdot (\text{column total})}{\text{grand total}}The logic: under the null hypothesis, the proportion falling in a given column should be the same across every row. Multiply that overall column proportion by each row's total, and you get the expected count. Expected counts do not have to be whole numbers — leave them as decimals like 34.734.7.

Before trusting the chi-square approximation, check the large-counts condition: every expected count must be at least 5. This is checked on expected counts, never observed counts. A common error is verifying observed counts instead.

Suppose a table has row total 120, column total 200, and grand total 500. Then E=120200500=48E = \frac{120 \cdot 200}{500} = 48. Repeat for every cell. A quick check: the expected counts in any row sum to that row's total, and the expected counts in any column sum to that column's total — a handy way to catch arithmetic mistakes.

The test statistic then aggregates the discrepancy across all cells:χ2=(OE)2E\chi^2 = \sum \frac{(O - E)^2}{E}Large values of χ2\chi^2 signal that observed data stray far from what independence or homogeneity would predict.

Homogeneity vs. Independence

The single most tested distinction here is which test to run. Both use the same expected-count formula and the same χ2\chi^2 statistic, but they answer different questions and arise from different sampling designs.
FeatureHomogeneityIndependence
Number of populationsTwo or more separate groupsOne single population
Sampling designSeparate samples from each group, or random assignment to treatmentsOne random sample, then classify by two variables
Fixed marginsGroup totals are set by the researcherNeither margin is fixed in advance
Question askedAre the distributions of one variable the SAME across groups?Are the two variables ASSOCIATED within the population?
Homogeneity example: sample 100 seniors, 100 juniors, and 100 sophomores separately, then compare their distributions of favorite subject. Three populations, one categorical variable measured in each.

Independence example: take one random sample of 300 students and record both grade level and favorite subject. One population, two variables.

On the exam, read how the data were gathered. If the row (or column) totals were decided by the researcher — three fixed groups of 100 — it's homogeneity. If a single sample was drawn and then cross-classified, it's independence. The calculation looks identical, but your hypotheses and conclusion sentences must use the right language.

Degrees of Freedom and the Distribution

For any two-way table with rr rows and cc columns,df=(r1)(c1).df = (r-1)(c-1).Why the subtraction? Once you know the row and column totals, only (r1)(c1)(r-1)(c-1) cells are free to vary — the rest are forced to make the margins add up. For a 2×2 table, df=(21)(21)=1df = (2-1)(2-1) = 1. For a 3×4 table, df=(31)(41)=6df = (3-1)(4-1) = 6.

Note this differs from goodness-of-fit, where df=(categories1)df = (\text{categories} - 1). Mixing these up is a frequent slip. Also, degrees of freedom depend only on the table's dimensions, not on the sample size.

The chi-square distribution is right-skewed and always non-negative. Because any deviation between observed and expected — positive or negative — is squared, only large χ2\chi^2 values fall in the tail. So the p-value is always the area to the right of the observed statistic. There is no such thing as a left-tailed chi-square test in this context. A large χ2\chi^2 with a small p-value provides evidence against the null hypothesis of homogeneity or independence.

Hypotheses and Conclusions

Your hypotheses must match the test. For homogeneity, state the null as: the distribution of the response variable is the same across all populations, and the alternative as: the distributions are not all the same. Avoid the word 'independent' here — you have multiple populations, not two variables on one.

For independence, state the null as: the two variables are independent (not associated) in the population, and the alternative as: the two variables are associated. Name the specific variables and population in context; generic templates lose credit.

When writing the conclusion, tie the p-value to the significance level. If p<αp < \alpha, reject H0H_0 and give evidence for the alternative in context. If pαp \geq \alpha, fail to reject and state you lack convincing evidence — never 'accept' the null. A subtle but important point: because these are observational cross-classifications (for independence) or comparisons of pre-existing groups, a significant result shows association, not causation. Only a randomized experiment (a homogeneity setup with random assignment) can support a causal conclusion, and even then only about the treatments studied.

Key terms

Expected count.
The count predicted for a cell under the null hypothesis, found as (row total × column total) / grand total; need not be an integer.
Large-counts condition.
The requirement that all expected counts be at least 5 for the chi-square approximation to be valid.
Chi-square test for homogeneity.
A test comparing the distribution of one categorical variable across two or more separate populations or treatment groups.
Chi-square test for independence.
A test for association between two categorical variables measured on a single random sample from one population.
Degrees of freedom.
For a two-way table, (r − 1)(c − 1); the number of cells free to vary once margins are fixed.
Chi-square statistic.
χ2=(OE)2E\chi^2 = \sum \frac{(O-E)^2}{E}, summed over every cell, measuring total discrepancy between observed and expected.
Right-skewed distribution.
The shape of the chi-square distribution; p-values are always the area to the right of the test statistic.

Worked example

A researcher takes one random sample of 200 adults and records whether they exercise regularly (Yes/No) and whether they sleep at least 7 hours (Yes/No). Of 120 who exercise, 90 sleep 7+ hours; of 80 who don't exercise, 40 sleep 7+ hours. State the appropriate test, compute the expected count for the (Exercise=Yes, Sleep=Yes) cell, and give the degrees of freedom.
First identify the design: one random sample of 200 adults, classified by two variables (exercise and sleep). One population, two variables means this is a chi-square test for independence.

Build the table of observed counts. Exercise Yes: 90 sleep 7+, so 12090=30120 - 90 = 30 sleep less. Exercise No: 40 sleep 7+, so 8040=4080 - 40 = 40 sleep less. Column totals: sleep 7+ is 90+40=13090 + 40 = 130; sleep less is 30+40=7030 + 40 = 70. Grand total is 200.

Now the expected count for (Exercise=Yes, Sleep=Yes):E=(row total)(col total)grand total=120130200=15600200=78.E = \frac{(\text{row total}) \cdot (\text{col total})}{\text{grand total}} = \frac{120 \cdot 130}{200} = \frac{15600}{200} = 78.Since the observed count is 90, this cell contributes (9078)278=144781.85\frac{(90 - 78)^2}{78} = \frac{144}{78} \approx 1.85 to the statistic. You would repeat for all four cells and sum.

Degrees of freedom: the table is 2×2, so df=(21)(21)=1df = (2-1)(2-1) = 1.

Because the researcher drew a single sample and cross-classified, the correct hypotheses are H0H_0: exercise and sleep are independent among adults, versus HaH_a: exercise and sleep are associated.

Practice questions

A school selects separate random samples of 150 freshmen, 150 sophomores, and 150 juniors, then records each student's preferred lunch option (three options). Which test and degrees of freedom are appropriate?
  1. Test for independence with df = 4
  2. Test for homogeneity with df = 4
  3. Test for independence with df = 6
  4. Test for homogeneity with df = 6

Answer: Test for homogeneity with df = 4

Three separate samples were drawn from three distinct populations (grade levels), so this compares one variable's distribution across groups — a test for homogeneity. The table has 3 rows (grades) and 3 columns (lunch options), giving df=(31)(31)=4df = (3-1)(3-1) = 4.
In a two-way table, one cell has a row total of 60, a column total of 150, and the grand total is 300. Compute the expected count for that cell and explain what it represents.

Answer: The expected count is 30.

Apply E=60150300=9000300=30E = \frac{60 \cdot 150}{300} = \frac{9000}{300} = 30. This is the number of observations you would expect in that cell if the null hypothesis (independence or homogeneity) were true — that is, if the column proportions were identical across every row. Comparing observed to this 30 through (OE)2E\frac{(O-E)^2}{E} measures how much the data deviate from no association.
A study finds a statistically significant chi-square result for independence between coffee drinking and headaches in one random sample. Can the study conclude coffee causes headaches? Explain.

Answer: No, it cannot conclude causation.

A significant chi-square test for independence shows the two variables are associated in the population, not that one causes the other. Because the data come from observation (a single sample cross-classified) rather than a randomized experiment, lurking variables could explain the association. Only random assignment of treatments could support a causal claim.

FAQ

How do I tell homogeneity from independence on the AP exam?
Look at how the data were collected. If the researcher drew separate samples from two or more groups (or randomly assigned subjects to treatments) so that group totals were fixed in advance, it's homogeneity. If a single random sample was drawn and then classified by two variables, it's independence. The calculations are identical; only the setup and wording differ.
Do expected counts have to be whole numbers?
No. Expected counts are averages predicted under the null hypothesis and are almost always decimals, like 78.078.0 or 34.734.7. Do not round them to integers — round only at the end if reporting the test statistic, and keep decimals when checking the large-counts condition.
What condition do I check with expected counts?
The large-counts condition: every expected count must be at least 5. Always check this on the expected counts, not the observed counts. You should also confirm the data came from random sampling or random assignment and that observations are independent.
Why is degrees of freedom (r−1)(c−1) instead of the total number of cells?
Once the row and column totals are fixed, most cells are forced. Only (r1)(c1)(r-1)(c-1) cells can be chosen freely before the margins determine the rest. For a 2×2 table that leaves just 1 degree of freedom; for a 3×4 table it leaves 6.

Learn this with a teacher, not a page

The Crimsora tutor teaches U8.4 Chi-Square for Two-Way Tables live — explaining on a whiteboard, asking you questions, and adapting to where you get stuck.