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.
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 isThe 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 .
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 . 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:Large values of signal that observed data stray far from what independence or homogeneity would predict.
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 . 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:Large values of 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 statistic, but they answer different questions and arise from different sampling designs.
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.
| Feature | Homogeneity | Independence |
|---|---|---|
| Number of populations | Two or more separate groups | One single population |
| Sampling design | Separate samples from each group, or random assignment to treatments | One random sample, then classify by two variables |
| Fixed margins | Group totals are set by the researcher | Neither margin is fixed in advance |
| Question asked | Are the distributions of one variable the SAME across groups? | Are the two variables ASSOCIATED within the population? |
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 rows and columns,Why the subtraction? Once you know the row and column totals, only cells are free to vary — the rest are forced to make the margins add up. For a 2×2 table, . For a 3×4 table, .
Note this differs from goodness-of-fit, where . 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 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 with a small p-value provides evidence against the null hypothesis of homogeneity or independence.
Note this differs from goodness-of-fit, where . 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 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 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 , reject and give evidence for the alternative in context. If , 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.
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 , reject and give evidence for the alternative in context. If , 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.
- , 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 sleep less. Exercise No: 40 sleep 7+, so sleep less. Column totals: sleep 7+ is ; sleep less is . Grand total is 200.
Now the expected count for (Exercise=Yes, Sleep=Yes):Since the observed count is 90, this cell contributes to the statistic. You would repeat for all four cells and sum.
Degrees of freedom: the table is 2×2, so .
Because the researcher drew a single sample and cross-classified, the correct hypotheses are : exercise and sleep are independent among adults, versus : exercise and sleep are associated.
Build the table of observed counts. Exercise Yes: 90 sleep 7+, so sleep less. Exercise No: 40 sleep 7+, so sleep less. Column totals: sleep 7+ is ; sleep less is . Grand total is 200.
Now the expected count for (Exercise=Yes, Sleep=Yes):Since the observed count is 90, this cell contributes to the statistic. You would repeat for all four cells and sum.
Degrees of freedom: the table is 2×2, so .
Because the researcher drew a single sample and cross-classified, the correct hypotheses are : exercise and sleep are independent among adults, versus : 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?
- Test for independence with df = 4
- Test for homogeneity with df = 4
- Test for independence with df = 6
- 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 .
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 . 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 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 or . 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 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.