SECTION 1
Historical Context & Motivation
Humans have always needed ways to compare groups. Whether a government wanted to know how many men and women lived in each province, or a doctor wanted to track which patients recovered based on treatment type, the challenge was the same: how do you organize information about two different categories at the same time? The answer that emerged over centuries is the two-way table, sometimes called a contingency table. It places one categorical variable along the rows and another along the columns, creating a grid where every cell tells a story about how those categories overlap.
1700s • Early Census Tables
1900 • Karl Pearson & the Chi-Square Test
1930s • Ronald Fisher's Exact Test
Today • Data Science & Everyday Use
The central question this lesson addresses is straightforward but powerful: when you have data on two categorical variables, how do you organize it clearly enough to spot patterns, compute totals, and draw conclusions? Two-way tables give you a structured, visual way to do exactly that.
SECTION 2
Core Principles & Definitions
Before you build a two-way table, you need a solid understanding of the key vocabulary. A categorical variable is any variable that describes a quality or category rather than a numerical amount. Examples include favorite genre (action, comedy, drama), lunch choice (pizza, salad, sandwich), or grade level (freshman, sophomore, junior, senior). When you record data on two categorical variables for the same group of individuals, a two-way table is the ideal way to display that information.
Two-Way Table
Joint Frequency
Marginal Frequency
Grand Total
KEY TAKEAWAY
SECTION 3
Visual Explanation — Anatomy of a Two-Way Table
The diagram below shows a two-way table that records 200 students' preferences for two categorical variables: Grade Level (Freshman or Sophomore) and Favorite Subject (Math, Science, or English). Notice how the interior cells hold joint frequencies, and the rightmost column and bottom row hold marginal frequencies.
Each interior cell answers a very specific question. For instance, the cell at the intersection of "Freshman" and "Science" shows 45, meaning exactly 45 freshmen in this data set chose Science as their favorite subject. That is a joint frequency — it sits at the joint intersection of two categories. Meanwhile, the row total of 100 for Freshman is a marginal frequency; it tells you the total number of freshmen surveyed, regardless of their subject preference.
SECTION 4
Mathematical Framework
The arithmetic behind two-way tables is straightforward, but the notation helps you communicate precisely. Below are the key formulas you will use when computing frequencies from a two-way table.
MARGINAL FREQUENCY (ROW)
Add every joint frequency across a single row. Each fᵢ is the count in that row's i-th column.
MARGINAL FREQUENCY (COLUMN)
Add every joint frequency down a single column. Each fⱼ is the count in that column's j-th row.
GRAND TOTAL
The grand total n can be computed three ways: sum all interior cells, sum all row marginals, or sum all column marginals. All three methods must give the same answer.
RELATIVE JOINT FREQUENCY
Dividing a joint frequency by the grand total converts it to a proportion (decimal) or percentage, showing what fraction of all data points fall in that cell.
Quick Check
SECTION 5
Joint vs. Marginal Frequencies — A Closer Look
Let's dig deeper into the difference between joint frequencies and marginal frequencies using a new example. Suppose a school surveyed 150 students about their transportation to school (Bus, Car, Walk) and their involvement in after-school activities (Yes or No).
Notice in this example that every column marginal equals 50. That is a coincidence of this data set, not a requirement. In general, row totals and column totals can be any values. The only rule is that all marginals must add up to the same grand total. If you ever find a mismatch, go back and recheck your addition — something went wrong in one of the cells.
SECTION 6
Worked Example — Building and Analyzing a Two-Way Table
A gym teacher surveyed 120 students about two things: whether they prefer Indoor or Outdoor sports, and whether they are in 9th or 10th grade. Here are the raw results: 35 ninth graders prefer indoor, 25 ninth graders prefer outdoor, 30 tenth graders prefer indoor, and 30 tenth graders prefer outdoor. Build the two-way table, find all marginal frequencies, and compute the relative joint frequency for "10th grade and Outdoor."
Building a Two-Way Table from Survey Data
- 1
Step 1 — Identify the Variables
The two categorical variables are Grade Level (9th or 10th) and Sport Preference (Indoor or Outdoor). Grade Level will label the rows, and Sport Preference will label the columns. - 2
Step 2 — Fill in the Joint Frequencies
Place each count in the correct cell. 9th/Indoor = 35, 9th/Outdoor = 25, 10th/Indoor = 30, 10th/Outdoor = 30. These four values are the joint frequencies. - 3
Step 3 — Compute Row Marginal Frequencies
Sum across each row. For 9th grade: 35 + 25 = 60. For 10th grade: 30 + 30 = 60.Row totals: 9th = 60, 10th = 60 - 4
Step 4 — Compute Column Marginal Frequencies
Sum down each column. Indoor: 35 + 30 = 65. Outdoor: 25 + 30 = 55.Column totals: Indoor = 65, Outdoor = 55 - 5
Step 5 — Verify with the Grand Total
Sum of row totals: 60 + 60 = 120. Sum of column totals: 65 + 55 = 120. Both match the number of students surveyed (120). ✓Grand total: n = 120 - 6
Step 6 — Compute Relative Joint Frequency
For "10th grade and Outdoor," the joint frequency is 30. Divide by the grand total: 30 ÷ 120 = 0.25. Convert to a percentage: 0.25 × 100 = 25%.Relative joint frequency (10th, Outdoor) = 0.25 or 25%
| Indoor | Outdoor | Total | |
|---|---|---|---|
| 9th Grade | 35 | 25 | 60 |
| 10th Grade | 30 | 30 | 60 |
| Total | 65 | 55 | 120 |
Completed two-way table for the gym teacher's survey
SECTION 7
Strengths & Limitations of Two-Way Tables
Two-way tables are incredibly useful, but like any tool, they have both strengths and limitations. Understanding these helps you decide when a two-way table is the right choice and when you might need a different approach.
| Strengths | Limitations |
|---|---|
| Simple to construct — requires only counting and addition. | Only works for categorical data. Continuous data (like height or weight) must be grouped into categories first. |
| Makes patterns and associations between two variables immediately visible. | Can only handle two variables at a time. Three or more variables require multiple tables or more advanced techniques. |
| Provides a foundation for more advanced tests like the chi-square test. | Shows association but cannot prove causation — correlation is not causation. |
| Easy to compute relative frequencies and conditional probabilities from the same table. | Tables with many rows and columns can become hard to read and interpret. |
KEY TAKEAWAY
SECTION 8
Connection to Conditional Relative Frequency & Probability
Once you are comfortable with joint and marginal frequencies, the next step is conditional relative frequency. Instead of dividing a joint frequency by the grand total (which gives a relative joint frequency), you divide it by the relevant marginal frequency. This answers questions like "Of the students who ride the bus, what proportion do after-school activities?" That's a conditional question — you're restricting your view to just one row or column.
| Concept | Formula | What It Answers |
|---|---|---|
| Joint Frequency | Count in an interior cell | How many individuals share both categories? |
| Marginal Frequency | Sum of a row or column | How many individuals are in one category overall? |
| Relative Joint Frequency | Joint freq ÷ grand total | What proportion of everyone falls in this cell? |
| Conditional Rel. Frequency | Joint freq ÷ marginal freq | Given one category, what proportion falls in a specific cell? |
Frequency concepts build on each other
In future courses, you'll use conditional relative frequencies to determine whether two variables are independent or associated. If the conditional relative frequencies are roughly the same across all rows (or columns), the variables appear independent. If they differ significantly, you have evidence of an association. This idea leads directly into the chi-square test of independence, a cornerstone of statistical inference.
SECTION 9
Practice Problems
Use the following data to answer Problems 1–4. A school cafeteria surveyed 200 students on their lunch preference (Pizza or Salad) and their grade (Junior or Senior). The results: 55 juniors chose pizza, 45 juniors chose salad, 60 seniors chose pizza, and 40 seniors chose salad.
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Lesson Summary
Summary
A two-way table organizes data on two categorical variables into a grid of rows and columns. The interior cells contain joint frequencies — counts that describe how many data points share a specific combination of both categories. The row and column totals are called marginal frequencies, and the bottom-right corner holds the grand total of all observations.
To convert raw counts into proportions, divide a joint frequency by the grand total to get a relative joint frequency. Always verify your table by checking that all row marginals and all column marginals sum to the same grand total. Mastering these skills prepares you for conditional relative frequencies and the chi-square test of independence in future statistics courses.