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.
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.
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?
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 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.
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.
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.
How to Build a Two-Way Table
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
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.
Common Mistakes
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?