Two-Way Tables and Categorical Variables
Theory
A two-way table sorts people by two categorical variables at once. This Year 10 maths page shows how to read, complete and build a two-way table, use row percentages to decide whether two variables are associated, and find probabilities from the table, including when you are told which group the person is in and whether two events are independent. In the Victorian Curriculum this is Level 10 content; in the Australian Curriculum it is Year 10 content. Curriculum: VC2M10ST03 / AC9M10ST04.
A two-way table sorts data by two attributes at once, such as year group (rows) and pet (columns). Each person is counted in exactly one inner cell.
The row totals add across and the column totals add down. The grand total in the corner is the total number surveyed.
"\(A\) and \(B\)" is one inner cell. "\(A\) or \(B\)" means \(A\), or \(B\), or both: add the cells, counting any cell only once.
When the question tells you the group first ("a Year 7 student is chosen", "of those who had lessons"), the sample space is restricted to that row or column. Divide by that row or column total, not the grand total. This is called conditional probability.
Two categorical variables are associated if the percentages in one row differ from those in another, for example if boys and girls answer a question differently. If the row percentages are about the same, there is no association.
Two events are independent if knowing one does not change the probability of the other: \(P(A \mid B) = P(A)\).
For a person chosen at random from the whole table, and from one known group:
How to complete a two-way table
- Draw the table with a Total row and a Total column.
- Put in every number you are given (change percentages or probabilities to numbers first).
- Fill a gap in any row or column that has only one missing value, by subtracting from its total.
- Repeat until the table is full, then check both sets of totals.
How to find a probability from the table
- Decide the denominator. Anyone at all: the grand total. A known group: that row or column total.
- Find the numerator: the cell ("and") or the cells ("or", counting each cell once).
- Divide and simplify.
How to decide on an association or independence
- Find the row percentages (or row probabilities), each with its own row total.
- Compare them. Clearly different: associated, so not independent. Equal: no association, independent.
- Answer in context, quoting the percentages.
| Uses a laptop | Does not | Total | |
|---|---|---|---|
| Year 9 | \(18\) | \(?\) | \(40\) |
| Year 10 | \(?\) | \(?\) | \(?\) |
| Total | \(44\) | \(?\) | \(80\) |
Fill each gap from a row or column that has only one gap.
| \(\text{Year 9, does not}\) | \(=\) | \(40 - 18 = 22\) |
| \(\text{Year 10, laptop}\) | \(=\) | \(44 - 18 = 26\) |
| \(\text{Does not, total}\) | \(=\) | \(80 - 44 = 36\) |
| \(\text{Year 10, does not}\) | \(=\) | \(36 - 22 = 14\) |
| Uses a laptop | Does not | Total | |
|---|---|---|---|
| Year 9 | \(18\) | \(22\) | \(40\) |
| Year 10 | \(26\) | \(14\) | \(40\) |
| Total | \(44\) | \(36\) | \(80\) |
| \(P\) | \(=\) | \(\dfrac{14}{80} = \boldsymbol{\dfrac{7}{40}}\) |
| Exercises regularly | Does not | Total | |
|---|---|---|---|
| Under 40 | \(72\) | \(48\) | \(120\) |
| 40 and over | \(65\) | \(65\) | \(130\) |
(ii) Is there an association between age group and exercising regularly?
(iii) Why compare percentages and not the counts \(72\) and \(65\)?
(i) Divide by each row's own total.
| \(\text{under 40}\) | \(:\) | \(\dfrac{72}{120} \times 100\% = \mathbf{60\%}\) |
| \(\text{40 and over}\) | \(:\) | \(\dfrac{65}{130} \times 100\% = \mathbf{50\%}\) |
(ii) Yes. The row percentages differ: in this group, adults under \(40\) are more likely to exercise regularly (\(60\%\) compared with \(50\%\)). If there were no association, the two percentages would be about equal.
(iii) The groups are different sizes (\(120\) and \(130\)), so counts are not a fair comparison. Percentages put both groups on the same scale.
| Satisfied | Not satisfied | Total | |
|---|---|---|---|
| Online | \(72\) | \(18\) | \(90\) |
| In store | \(88\) | \(22\) | \(110\) |
| Total | \(160\) | \(40\) | \(200\) |
(i) An online customer is chosen. Find the probability that they were satisfied.
(ii) A customer who was not satisfied is chosen. Find the probability that they bought in store.
(i) Only the Online row counts: \(90\) customers.
| \(P\) | \(=\) | \(\dfrac{72}{90} = \boldsymbol{\dfrac{4}{5}}\) |
(ii) Only the Not satisfied column counts: \(40\) customers.
| \(P\) | \(=\) | \(\dfrac{22}{40} = \boldsymbol{\dfrac{11}{20}}\) |
Dividing by \(200\) would answer a different question: the chance a random customer is both.
Change each probability to a number of people by multiplying by \(400\).
| \(\text{locals}\) | \(=\) | \(0.35 \times 400 = 140\) |
| \(\text{locals with food}\) | \(=\) | \(0.2 \times 400 = 80\) |
| Bought food | No food | Total | |
|---|---|---|---|
| Local | \(80\) | \(60\) | \(140\) |
| Visitor | \(170\) | \(90\) | \(260\) |
| Total | \(250\) | \(150\) | \(400\) |
Only the Bought food column counts: \(80 + 170 = 250\) people.
| \(P\) | \(=\) | \(\dfrac{80}{250} = \boldsymbol{\dfrac{8}{25}}\) |
Common pitfalls
Frequently asked questions
What is a two-way table?
It is a table that sorts data by two attributes at once, with one attribute down the side and the other across the top, plus row and column totals.
How do you find a probability from a two-way table?
Divide the number in the cell or cells you want by the total of the group you are choosing from. For anyone at all, that is the grand total.
How do you fill in missing values in a two-way table?
Find a row or column with only one gap and subtract the known values from its total. Keep going until the table is full, then check the totals.
What does 'given that' mean in probability?
It means you already know which group the person is in. Only that row or column counts, so divide by its total.
How do you work out an 'or' probability from a two-way table?
Add the cells where either event happens, counting the cell where both happen only once, then divide by the total.
How do you tell if two categorical variables are associated?
Work out the percentage with the feature in each row, using each row's own total. If the percentages are clearly different, the variables are associated; if they are about the same, they are not.