📘 CodingMarble Learn

Two-Way Tables

A two-way table counts data for two categorical variables at once: one in the rows, one in the columns. Row and column totals are marginal totals. Dividing a cell by the grand total gives a joint relative frequency; dividing by its row (or column) total gives a conditional relative frequency. If conditional percentages differ a lot between groups, the variables are associated.

🎬 Step-by-step story

  1. A two-way table counts two things at once. Rows are age groups, columns are ways to school. Each cube is one student.
  2. Add each row and each column. These marginal totals sit at the edges. The grand total is 40.
  3. Joint relative frequency: a cell divided by the grand total. 12 ÷ 40 = 30% of all students are younger walkers.
  4. Conditional relative frequency: look inside one row only. 60% of younger students walk, but only 20% of older ones.
  5. A segmented bar chart makes every row 100% tall. Different colour parts mean the variables are associated.
  6. Free play: change any cell with + and −. Watch totals, percentages and bars update.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

What makes a table "two-way"?

It sorts every person by two questions at once: one answer chooses the row, the other chooses the column. So each cube sits in exactly one cell.

Why are they called marginal totals?

They are written in the margins (edges) of the table: the right-hand column and the bottom row.

Is 12 ÷ 40 the same as 12 ÷ 20?

No. 12 ÷ 40 (30%) is out of everyone (joint). 12 ÷ 20 (60%) is out of younger students only (conditional).

Why compare percentages instead of counts?

Groups can have different sizes. Percentages put every group on the same 100 scale so the comparison is fair.

How do I see association on a graph?

In a segmented bar chart, if the coloured parts sit at very different heights in each bar, the variables are associated.

What would "no association" look like?

Make both rows have the same split (e.g., 10, 6, 4 and 10, 6, 4) in free play. The segmented bars become identical.

What is a two-way table?

A categorical variable puts each person or thing into a group (a category), like "walk / cycle / bus" or "younger / older". A two-way table (also called a contingency table) shows the counts for two categorical variables together: one variable along the rows, the other along the columns. Each cell holds the count for one row group AND one column group.

WalkCycleBusTotal
Younger126220
Older48820
Total16141040

To build one from raw data, list the categories, tally each record into its cell, then add the totals. The totals in the margins are the marginal totals; the bottom-right number is the grand total.

Joint, marginal and conditional relative frequencies

A relative frequency is a count turned into a fraction or percentage. There are three kinds:

Read conditional ones with "given" or "among": "among older students, 40% take the bus" (8 ÷ 20). Notice that "among bus users, 80% are older" (8 ÷ 10) is a different question with a different answer. The phrase tells you which total to divide by.

Graphs and association

Useful graphs for two categorical variables:

Two variables are associated if knowing one changes the chances for the other. Compare the conditional percentages: 60% of younger students walk versus 20% of older ones, a big difference, so age and travel mode are associated. If the percentages were about equal in every row, the segments would line up and there would be little or no association. Association does not prove that one variable causes the other.

Two-variable data beyond tables

Two-way tables are for two categorical variables. When both variables are numbers (like height and arm span), use a scatter plot instead and look for a trend, a fitted line and residuals (see the linear regression lesson). The question is the same in both cases: does one variable tell us something about the other?

Try it: Ask 20 friends or family members two questions: "Tea or coffee?" and "Age under 30 or 30+?" Build the two-way table, find the conditional percentages for each age group, and decide whether drink choice is associated with age. Then type your counts into 3D free play to see your segmented bars.

Key formulas and definitions

Worked examples

1. Using the school table, how many students take the bus, and what fraction is that?

Column total for Bus = 2 + 8 = 10. Marginal relative frequency = 10 ÷ 40 = 0.25 = 25%.

2. What is the joint relative frequency of "older AND cycle"?

Cell = 8. 8 ÷ 40 = 0.20 = 20%.

3. Among younger students, what percentage cycle?

Divide by the Younger row total: 6 ÷ 20 = 0.30 = 30%.

4. Among cyclists, what percentage are younger?

Now divide by the Cycle column total: 6 ÷ 14 ≈ 0.43 = 43%. Different total, different answer from example 3.

5. Complete the table: 50 people (25 men, 25 women); 30 like football, and 18 of those are women.

Line 1: men who like football = 30 − 18 = 12. Line 2: men who do not = 25 − 12 = 13. Line 3: women who do not = 25 − 18 = 7. Line 4: check the "do not" total: 13 + 7 = 20 = 50 − 30. Every row and column adds up.

6. In a survey of 200 adults, 90 of 120 who exercise sleep well, and 30 of 80 who don't exercise sleep well. Is there an association?

Conditional: 90 ÷ 120 = 75% vs 30 ÷ 80 = 37.5%. The percentages are very different, so exercise and good sleep are associated (but this does not prove exercise causes good sleep).

Common mistakes

Practice quiz

1. In a two-way table, the row and column totals are called:
2. Joint relative frequency = cell ÷ ?
3. "Of the older students, what % take the bus?" You divide by:
4. In a segmented bar chart each bar is:
5. Two variables are associated when:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a two-way table in simple words?

A grid that counts how many people (or things) fall into each pair of groups from two different questions.

What is the difference between joint and conditional relative frequency?

Joint divides a cell by everyone (grand total). Conditional divides a cell by just one group's total.

How do you know if two categorical variables are associated?

Find conditional percentages for each group. If they differ a lot, the variables are associated.

Where this is taught

USA (Common Core, NGSS, AP)Grade 8Statistics and Probability (8.SP)
USA (Common Core, NGSS, AP)Grade 9Descriptive statistics
USA (Common Core, NGSS, AP)Grade 9Descriptive statistics
USA (Common Core, NGSS, AP)Grade 12Probability, Random Variables, and Probability Distributions

Learn first

Learn next

Related lessons

All Maths lessons