AP Statistics · Topic 2.1 · Reading guide, about 4 min

Two-way tables and segmented bar charts

Organize two categorical variables in two-way tables, graph them, and judge association by comparing distributions.

In one minute

When you record two categorical variables for each individual, such as grade and lunch choice, the data go into a two-way table, which counts how many individuals fall into each pair of categories. The question to answer is whether the variables are associated: does knowing one category change what you expect for the other?

To judge association fairly you compare proportions, not raw counts, and you draw graphs that put groups on equal footing. This topic is about building the table, making the graph and writing a claim you can defend from the data.

Key terms

Two-way table (contingency table)
A table of counts (or proportions) in which rows are categories of one variable and columns are categories of the other; also called a contingency table.
Joint cell
A single cell in the table, holding the count for one pairing of categories.
Marginal totals
The row and column totals in the margins of the table, giving each variable's distribution alone.
Side-by-side bar chart
Bars for the categories of one variable, grouped by the other variable.
Segmented bar chart
A set of bars, one per group, each split into segments showing that group's percentages and scaled to the same total height.
Mosaic plot
A segmented bar chart whose bar widths are proportional to group sizes.
Association
Two categorical variables are associated if the distribution of one differs across the categories of the other.
Conditional distribution
The percentages of one variable among only those individuals in a given category of the other.

Reading and building a two-way table

Each individual contributes one count to exactly one cell. Row totals and column totals give the marginal counts, and the grand total in the corner equals the sample size. Always check that the cells add to the totals; it catches mistakes.

Raw counts can mislead when the groups are different sizes. A larger group will have larger counts in every cell, even if it has the same pattern. To compare groups, convert each group's counts into percentages of that group's total. That produces its conditional distribution, which is the core idea behind the graphs here.

Graphs for two categorical variables

A side-by-side bar chart shows the counts or percentages for one variable at each level of the other. A segmented bar chart stacks the categories of the response in each bar, and each bar's total height is 100%, so you can compare the segments directly across groups. A mosaic plot adds information about group size by making the bars wider for larger groups.

In all three, put the explanatory variable (the one doing the grouping) on the horizontal axis and show the response variable's categories in the bars or segments. If the segments line up at the same heights in every bar, the variables look unrelated. If they shift, the variables look associated.

Invented lunch survey: counts by grade
GradeHot lunchPacked lunchRow total
Grade 9453580
Grade 10305080
Grade 11206080
Column total95145240

Worked example: grade and lunch choice

Invented data: 240 students, 80 from each of grades 9, 10 and 11, were asked whether they usually buy hot lunch or pack lunch. The counts are in the table above. Check the totals first: 45+35=8045+35=80, 30+50=8030+50=80, 20+60=8020+60=80, so the rows sum to 240240; the columns give 45+30+20=9545+30+20=95 hot and 35+50+60=14535+50+60=145 packed, and 95+145=24095+145=240.

Step 1: find the percent buying hot lunch within each grade. Grade 9: 4580=0.5625\frac{45}{80}=0.5625, or 56.25%. Grade 10: 3080=0.375\frac{30}{80}=0.375, or 37.5%. Grade 11: 2080=0.25\frac{20}{80}=0.25, or 25%. The packed percentages are the remainders: 43.75%, 62.5% and 75%.

Step 2: draw a segmented bar chart with one bar per grade, each 100% tall, with the hot-lunch segment at the bottom. The bottom segments would be 56.25%, 37.5% and 25% tall, shrinking from grade 9 to grade 11.

Step 3: write the claim in context. The percentage of students who buy hot lunch decreases as grade level rises, from 56.25% in grade 9 to 25% in grade 11. Because the conditional distributions differ, grade and lunch choice are associated in this sample. The data do not show that being in a higher grade causes students to pack lunch.

Check with the overall rate: 95240=0.3958\frac{95}{240}=0.3958, about 39.6% of all students buy hot lunch. This sits between the grade percentages, and because the groups are equal in size it also equals their average: 56.25+37.5+253=39.58\frac{56.25+37.5+25}{3}=39.58.

How it connects

  • Back to 1.4: bar charts of one categorical variable become segmented bars when a second variable is added.
  • Forward to 2.2: the percentages here are formalized as joint, marginal and conditional relative frequencies.
  • Forward to 3.14: the chi-square test asks whether an observed association could be chance alone.
  • Forward to 2.6: conditional proportions are the same idea as conditional probability.

Common mistakes

  • Comparing raw counts of groups of different sizes. Convert to percentages of each group first.
  • Using the wrong total. Percentages for each group must use that group's total as the denominator, not the table total.
  • Concluding causation from association. A table cannot show why the pattern exists.
  • Describing only one group. To argue association, compare the distributions across groups with numbers.

How it shows up on the exam

  • A two-way table or segmented bar chart is given, and you are asked whether the variables appear associated, using percentages as evidence.
  • You complete a table of counts or build a graph from a described data set.
  • A short claim question asks you to support or challenge a statement using the data in context.

Check yourself

  1. Why is it risky to compare raw counts across groups of different sizes?
  2. In a segmented bar chart, what pattern suggests no association?
  3. Which variable goes on the horizontal axis and why?
  4. If two variables are associated, can you say one causes the other?

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