01 / 21

Representing Two
Categorical Variables

Learn to organize and display the relationship between two categorical variables using two-way tables, bar charts, and segmented bar charts.

AP Statistics

What Are Categorical Variables?

A categorical variable places individuals into one of several groups or categories. Unlike quantitative variables (which measure amounts), categorical variables describe qualities or labels.

Categorical
Gender, eye color, political party, grade level, treatment group
Quantitative
Height, weight, test score, temperature, income

Why Study Two Variables Together?

Analyzing a single categorical variable tells us about the distribution of one characteristic. But real questions involve relationships: Does treatment type affect outcome? Does gender relate to preference?

1
Describe associations: Are two variables related, or are they independent?
2
Compare groups: How does the distribution of one variable differ across categories of the other?
3
Inform decisions: Evidence-based conclusions require examining multi-variable data.

The Two-Way Table

A two-way table (also called a contingency table) organizes counts for two categorical variables. Rows represent one variable; columns represent the other.

Prefers Dogs Prefers Cats Total
Male 36 24 60
Female 30 30 60
Total 66 54 120

Key Terminology

Joint Frequency
A count in an interior cell: the number of individuals in a specific combination of categories.
Marginal Frequency
A row or column total: the distribution of one variable regardless of the other.
Conditional Distribution
The distribution of one variable within a fixed category of the other variable.

Joint vs Marginal vs Conditional

Joint Marginal Conditional
Question What fraction fall in this cell? What fraction are in this row/column? Given this group, what fraction are in that category?
Denominator Grand total Grand total Row or column total
Example \(\frac{36}{120} = 0.30\) \(\frac{66}{120} = 0.55\) \(\frac{36}{60} = 0.60\)

Visualizing with Bar Charts

A side-by-side bar chart displays the joint frequencies for each combination of categories. Each group gets adjacent bars for easy comparison.

0 10 20 30 40 36 24 30 30 Male Female Count
Dogs
Cats

Segmented Bar Charts

A segmented (stacked) bar chart shows each bar as 100% of a group, divided into segments. This makes it easy to compare conditional distributions across groups.

0% 25% 50% 75% 100% 60% 40% 50% 50% Male Female
Dogs
Cats

The Mosaic Plot

A mosaic plot is like a segmented bar chart, but the width of each bar is proportional to the group size. This lets you see both the conditional distributions and the marginal distribution simultaneously.

36 24 30 30 Male (50%) Female (50%) Dogs Cats

How to Build a Two-Way Table

1
Identify the two categorical variables and list all possible categories for each.
2
Set up the table: one variable defines rows, the other defines columns. Add a "Total" row and column.
3
Count and fill in joint frequencies for each cell by tallying the raw data.
4
Compute marginal totals by summing across each row and down each column.
5
Verify: the grand total should equal the sum of all row totals and the sum of all column totals.

Worked Example: Movie Preferences

A survey of 200 students asked about class year (Freshman, Sophomore) and favorite genre (Action, Comedy, Drama).

Action Comedy Drama Total
Freshman 40 35 25 100
Sophomore 30 25 45 100
Total 70 60 70 200

Conditional Distributions in Action

Using the movie data, let's compute the conditional distribution of genre given class year:

Action Comedy Drama
Freshman \(\frac{40}{100} = 40\%\) \(\frac{35}{100} = 35\%\) \(\frac{25}{100} = 25\%\)
Sophomore \(\frac{30}{100} = 30\%\) \(\frac{25}{100} = 25\%\) \(\frac{45}{100} = 45\%\)

Visualizing the Association

0% 50% 100% 40% 35% 25% 30% 25% 45% Freshman Sophomore
Action
Comedy
Drama

What Does Independence Look Like?

Two categorical variables are independent if knowing the value of one variable tells you nothing new about the other. In a segmented bar chart, independence means all bars have identical segment proportions.

0% 100% 50% 50% 50% 50% 50% Group A Group B Identical proportions = Independence

Common Mistakes

Wrong Denominator
Using the grand total instead of the row/column total when computing a conditional relative frequency.
Confusing Joint and Marginal
Reporting a joint frequency (one cell) when asked for a marginal frequency (row or column total), or vice versa.
Comparing Counts Instead of %
When group sizes differ, comparing raw counts can be misleading. Always use conditional relative frequencies to compare.

Summary of Display Methods

Display Shows Best For Limitation
Two-Way Table Exact counts and totals Precise calculations Hard to spot patterns visually
Side-by-Side Bar Joint frequencies by group Comparing counts across groups Misleading with unequal group sizes
Segmented Bar Conditional distributions (%) Detecting association Exact values harder to read
Mosaic Plot Conditional + marginal info Full picture of both variables Can be unfamiliar to readers

Question 1 of 5

In a two-way table, the value in an interior cell represents which type of frequency?

Question 2 of 5

A survey of 300 people yields the following: 90 are men who prefer tea, 60 are men who prefer coffee, 80 are women who prefer tea, 70 are women who prefer coffee. What is the conditional proportion of tea drinkers among women?

Question 3 of 5

Which display is most appropriate for comparing the conditional distributions of a response variable across groups of different sizes?

Question 4 of 5

Two categorical variables are independent if and only if:

Question 5 of 5

In a two-way table with 3 rows and 4 columns (not counting totals), how many joint frequencies are there?