AP Statistics · Unit 3 · Inference for Categorical Data: Proportions
3.14 Setting up a chi-square test for two-way tables
Write hypotheses for a chi-square test of homogeneity or independence, check its conditions, and calculate expected counts for a two-way table.
1/5Two-way tables organize counts for categorical variables
- Two-way tables organize counts for categorical variables
- The study design decides which chi-square test to use
- The hypotheses describe populations, not samples
- Expected counts show what the null hypothesis predicts
- Valid conclusions need randomness, independence, and expected counts of at least 5
- Check your recall
- Practice: 10 questions
Part 1 of 5: Two-way tables organize counts for categorical variables
Proportion tests handle two groups and a yes-or-no outcome. Real data often have more groups or more categories than that. A two-way table lays out counts for any number of groups and categories.
Each cell holds the number of individuals with one particular combination. The chi-square test compares these observed counts with the counts we would expect if the null hypothesis were true. It judges whether the pattern could easily come from chance alone.
These tests need actual counts, with each individual in exactly one cell. Percentages and proportions are not enough. Convert percentages back to counts before you start.
Key terms · tap one for its definition
two-way table
A two-way table is a table of counts in which rows represent categories of one variable and columns represent categories of another.
chi-square test
A chi-square test is a significance test that compares observed counts in a table with the counts expected when the null hypothesis is true.
Part 2 of 5: The study design decides which chi-square test to use
Two versions of the test use the same calculations. The test of homogeneity asks whether a categorical variable has the same distribution in several populations. The test of independence asks whether two categorical variables are associated in one population.
Choosing between the two tests
- Feature
- Data collection
- Homogeneity
- Separate random samples, or randomized treatment groups
- Independence
- One random sample
- Feature
- Variables
- Homogeneity
- One variable measured in each group
- Independence
- Two variables measured on each individual
- Feature
- Question
- Homogeneity
- Is the distribution the same in every group?
- Independence
- Are the variables associated?
The calculations will not reveal the design, so read the description of the data. Look for separate samples from each group, or for one sample sorted two ways.
Key terms · tap one for its definition
test of homogeneity
A test of homogeneity is a chi-square test of whether one categorical variable has the same distribution in several populations or treatment groups.
test of independence
A test of independence is a chi-square test of whether two categorical variables are associated among the individuals of one population.

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: B · Worked explanation
Part 3 of 5: The hypotheses describe populations, not samples
Once the test is chosen, the hypotheses follow a fixed pattern. Write both in context, using the names of the variables and groups.
- Homogeneity: says the variable has the same distribution in all populations; says it does not
- Independence: says the two variables are independent in the population; says they are not
The alternative never specifies which groups or categories differ. It says only that the distributions are not all the same, or that an association exists.
Part 4 of 5: Expected counts show what the null hypothesis predicts
The conditions and the test statistic both use expected counts, so we calculate them next. The expected count for a cell is the count we would anticipate if were true. If every group had the same distribution, each group would match the overall column percentages.
The formula is .
Expected counts need not be whole numbers, so keep the decimals. Each row of expected counts adds to its row total. Each column adds to its column total.
Worked example
Finding expected counts
- Row totals: freshmen 120 and seniors 80. Column totals: pizza 70, salad 60, wrap 70. Table total: 200.
- Freshmen pizza: . Freshmen salad: . Freshmen wrap: 42.
- Seniors pizza: . Seniors salad: . Seniors wrap: 28.
- Check that each row of expected counts adds to its row total.
Answer: The expected counts are 42, 36, 42 for freshmen and 28, 24, 28 for seniors.
Expected counts for the lunch survey
- Group
- Freshmen
- Pizza
- 42
- Salad
- 36
- Wrap
- 42
- Group
- Seniors
- Pizza
- 28
- Salad
- 24
- Wrap
- 28
Key term
expected count
The expected count for a cell is its row total times its column total, divided by the table total, assuming the null hypothesis is true.

Quick check
One question on the part you just read
Easy
Show answer and explanation
Answer: B · Worked explanation
Part 5 of 5: Valid conclusions need randomness, independence, and expected counts of at least 5
With expected counts in hand, we can finish checking the conditions. Check each of these:
- Random: separate random samples, one random sample, or random assignment
- Independent: each sample is less than 10% of its population when sampling without replacement
- Large counts: every expected count is at least 5
In the lunch survey, the smallest expected count is 24, so the large counts condition is met. Write the check using the actual numbers, not just a statement that it holds.
Check your recall[13 marks]
6 written questions. Answer each one in your head or on paper, then open the mark scheme.
- 1.Identify[2 marks]
Identify the chi-square test that fits random samples of 150 residents from each of three cities, each asked whether they usually travel by car, bus, or bike.
Show mark schemeHide mark scheme
Model answer
A test of homogeneity fits, because separate random samples were taken from three populations and one categorical variable was measured in each.
- 1 mark for identifying the test of homogeneity
- 1 mark for justifying it with separate random samples from several populations
- 2.Identify[2 marks]
Identify the null and alternative hypotheses for one random sample of 300 adults classified by age group and favorite social media site.
Show mark schemeHide mark scheme
Model answer
: Age group and favorite site are independent in the population of adults. : Age group and favorite site are not independent.
- 1 mark for stating the null hypothesis of independence in context
- 1 mark for stating the alternative hypothesis of an association in context
- 3.Calculate[2 marks]
Calculate the expected count for a cell in a table with row total 90, column total 60, and table total 240.
Show mark schemeHide mark scheme
Model answer
.
- 1 mark for using row total times column total divided by table total
- 1 mark for obtaining 22.5
- 4.Describe[3 marks]
Describe the conditions for using a chi-square test with a two-way table.
Show mark schemeHide mark scheme
Model answer
The data must come from random samples or random assignment. Observations must be independent, with each sample under 10% of its population when sampling without replacement. Every expected count must be at least 5.
- 1 mark for stating random sampling or random assignment
- 1 mark for stating independence including the 10% condition
- 1 mark for stating that all expected counts are at least 5
- 5.Determine[2 marks]
Determine whether the large counts condition is met when the expected counts are 12.5, 8.0, 4.5, and 15.0.
Show mark schemeHide mark scheme
Model answer
The condition is not met, because the expected count of 4.5 is less than 5.
- 1 mark for identifying 4.5 as an expected count below 5
- 1 mark for concluding that the condition is not met
- 6.Explain[2 marks]
Explain why the alternative hypothesis for a test of homogeneity does not say which groups differ.
Show mark schemeHide mark scheme
Model answer
The alternative states only that the distribution of the variable is not the same in all groups. The test checks whether any difference exists overall, not where the difference lies.
- 1 mark for stating that the alternative says the distributions are not all the same
- 1 mark for explaining that the test does not identify which groups differ

Practice this topic
10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)
0 right0 of 10 answered
Includes the 2 quick checks in the note above.
EasyIdentify[1 mark]
Show answer and explanation
Answer: B · Worked explanation
MediumCalculate[2 marks]
Show answer and explanation
Answer: D · Worked explanation
MediumIdentify[2 marks]
Show answer and explanation
Answer: A · Worked explanation
MediumDetermine[2 marks]
Show answer and explanation
Answer: A · Worked explanation
MediumIdentify[2 marks]
Show answer and explanation
Answer: D · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: D · Worked explanation
HardIdentify[2 marks]
Show answer and explanation
Answer: D · Worked explanation
HardDetermine[2 marks]
Show answer and explanation
Answer: B · Worked explanation