Instant PDF download, name-and-email checkout. Complete bundle: every Economics and Statistics book
Statistics guide, Unit 2, step 6 of 22Previous stepNext step

Step 6: Two-Way Tables and Simulation

SyllabusAP Stats 2.1–2.3
In 30 seconds
  • A two-way table counts individuals by two categorical variables at once, such as year group and how students travel to school.
  • Joint relative frequency = cell ÷ grand total; marginal = row or column total ÷ grand total; conditional = cell ÷ the total of the row or column you are conditioning on.
  • Two categorical variables are associated if the conditional distributions differ from one group to another.
  • A simulation imitates a chance process with random digits or technology; describe it clearly so anyone could repeat it, then estimate the probability as a proportion of trials.
Video lesson coming soonA short animated lesson for this step will appear here.

What a two-way table shows

Imagine a school asks 250 students “Which year are you in?” and “How do you usually get to school?” Both answers are categorical: they put each student into a group rather than giving a number.

Key termTwo-way table: a table of counts that summarises data on the relationship between two categorical variables for a group of individuals.

For example:

WalkBusCarTotal
Year 10304525100
Year 11206070150
Total5010595250

The six numbers inside the table are the cells. The numbers in the “Total” row and column sit in the margins of the table, which is where the word “marginal” comes from. Always check that rows and columns add up: 30 + 45 + 25 = 100, and 100 + 150 = 250.

Joint, marginal and conditional relative frequencies

Counts are hard to compare when groups differ in size (100 Year 10s, 150 Year 11s), so we use relative frequencies (proportions). There are three kinds; the only difference is what you divide by.

Key termJoint relative frequency: the count in one cell divided by the grand total. It answers “what proportion of everyone is in this row and this column?”
Key termMarginal relative frequency: a row or column total divided by the grand total. It describes one variable on its own.
Key termConditional relative frequency: a cell count divided by the total of the row or column you are given. It answers “of those in this group, what proportion are in that category?”
\[ \text{joint} = \frac{\text{cell}}{\text{grand total}} \qquad \text{marginal} = \frac{\text{row or column total}}{\text{grand total}} \qquad \text{conditional} = \frac{\text{cell}}{\text{total of the given group}} \]

The word “given” (or “of those who…”, “among…”) is your signal for a conditional. The group after “given” is the one whose total goes on the bottom.

Worked example

Using the travel table above, find (a) the proportion of all students who are in Year 11 and travel by car, (b) the proportion of all students who travel by car, (c) the proportion of Year 11 students who travel by car, and (d) the proportion of car travellers who are in Year 11.

Step 1Joint: \( \dfrac{70}{250} = 0.28 \), so 28% of all students are Year 11 car travellers.
Step 2Marginal: \( \dfrac{95}{250} = 0.38 \), so 38% of all students travel by car.
Step 3Conditional on Year 11: \( \dfrac{70}{150} \approx 0.467 \), so about 46.7% of Year 11 students travel by car.
Step 4Conditional on car: \( \dfrac{70}{95} \approx 0.737 \), so about 73.7% of car travellers are in Year 11.

Notice that (c) and (d) use the same cell, 70, but answer completely different questions because they divide by different totals.

Common mistakeMixing up “the proportion of Year 11 students who travel by car” (70 ÷ 150) with “the proportion of car travellers who are in Year 11” (70 ÷ 95). Before dividing, underline the group you are restricted to; its total is your denominator.

Conditional distributions and association

A conditional distribution lists the conditional relative frequencies for every category of one variable, within one group of the other. For our survey, the distribution of travel method for each year group is:

WalkBusCarTotal
Year 1030 ÷ 100 = 30.0%45 ÷ 100 = 45.0%25 ÷ 100 = 25.0%100%
Year 1120 ÷ 150 ≈ 13.3%60 ÷ 150 = 40.0%70 ÷ 150 ≈ 46.7%100%

Year 11 students are much more likely to travel by car (46.7% compared with 25%) and less likely to walk (13.3% compared with 30%). Because the conditional distributions are different, we say there is an association between year group and travel method.

Key termAssociation: two categorical variables are associated if knowing the value of one variable helps predict the value of the other, that is, if the conditional distributions of one variable differ across the categories of the other. If the conditional distributions are the same (or nearly the same), there is no association.

Association is not causation: being in Year 11 does not itself make anyone ride in a car. And with sample data, small differences may just be chance.

Segmented bar charts and mosaic plots

You can show conditional distributions with a graph.

DiagramSegmented bar chart. Draw two vertical bars side by side, one labelled “Year 10” and one “Year 11” on the horizontal axis. The vertical axis is “Percent”, from 0% to 100%. Each bar reaches 100% and is divided into three segments, shaded differently, with a key: Walk at the bottom, Bus in the middle, Car on top. The Year 10 bar has Walk from 0 to 30%, Bus from 30% to 75%, Car from 75% to 100%. The Year 11 bar has Walk from 0 to 13.3%, Bus from 13.3% to 53.3%, Car from 53.3% to 100%. The Car segment is clearly taller in Year 11, which shows the association at a glance.
DiagramMosaic plot. Draw the same segmented bars, but make each bar’s width proportional to the size of the group. Year 10 has 100 of the 250 students, so its bar takes 40% of the width; Year 11 has 150, so its bar takes 60%. The area of each rectangle is then proportional to the cell count, so the plot shows both the conditional distributions (heights) and the marginal distribution of year group (widths).

If the segments line up at the same heights in every bar, there is no association. The more the segment heights differ, the stronger the association.

Exam tipIn an AP free-response question asking whether there is an association, compare conditional relative frequencies (percentages within each group), never raw counts when group sizes differ. Quote the actual numbers in context: “46.7% of Year 11 students travel by car compared with 25% of Year 10 students, so there is an association between year group and travel method.” A bare “yes, they are associated” earns little.

Estimating probabilities by simulation

Some probability questions are hard to work out with formulas. A simulation imitates the chance process many times using random numbers, then uses the results to estimate the probability.

Key termSimulation: the imitation of chance behaviour, based on a model that accurately reflects the situation, used to estimate probabilities by the proportion of trials in which an outcome occurs.

A good simulation description has four parts, and AP examiners look for all of them:

  1. Model / assign digits. Say how random digits (or a random number generator) represent the outcomes, with the correct probabilities.
  2. Describe one trial. Say how many digits you read for one repetition, whether repeats are allowed, and what you record.
  3. Repeat. Carry out many trials (state how many).
  4. Estimate. The estimated probability is the proportion of trials where the event happened. Answer the question in context.

More trials give an estimate closer to the true probability.

Worked example

A cereal company puts a prize in 20% of its boxes. You buy 5 boxes. Use the random digits below to estimate the probability that you get no prize at all.

34167 21106 84038 85421 43044 32445 19568 32374 18404 94836

Step 1Model: let the digits 0 and 1 represent a box with a prize, and 2 to 9 represent a box without one. This gives \( P(\text{prize}) = \tfrac{2}{10} = 0.2 \). Repeats are allowed, because each box is independent.
Step 2One trial: read 5 digits (one block) for the 5 boxes. Record whether the block contains no 0 or 1, meaning no prize.
Step 3Carry out 10 trials. Blocks with no 0 or 1 are trial 6 (32445), trial 8 (32374) and trial 10 (94836). All other blocks contain at least one 0 or 1.
Step 4Estimate: \( \dfrac{3}{10} = 0.3 \).

Based on this simulation, the estimated probability of getting no prize in 5 boxes is about 0.3. The exact answer is \( 0.8^5 \approx 0.328 \), so our small simulation was close; with more trials, the estimate would usually get closer still.

Using technology

With a calculator or spreadsheet: generate a random integer from 1 to 100, letting 1 to 20 mean “prize”. Generate 5 for one trial, record whether none is 20 or less, and repeat 1,000 times. Describe the method in words, not calculator syntax, so an examiner could repeat it.

Common mistakeAssigning digits so the probabilities are wrong. For a probability of 0.35, single digits will not work; use pairs of digits 00 to 99, with 00 to 34 meaning success (35 out of 100). Also say clearly whether repeated numbers are allowed: if you are choosing 3 different people from 10, you must skip repeats.

Practise: 6 questions

Try each one on paper first, then check the worked answer. Questions 1 to 4 use this table of 120 students, recording whether they ate breakfast and whether they passed a test.

PassFailTotal
Breakfast541872
No breakfast301848
Total8436120
EasyQ1. What proportion of all students ate breakfast and failed? Show worked answer
This is a joint relative frequency: 18 ÷ 120 = 0.15. So 15% of all students ate breakfast and failed.
EasyQ2. Give the marginal distribution of test result. Show worked answer
Pass: 84 ÷ 120 = 0.70 (70%). Fail: 36 ÷ 120 = 0.30 (30%). Check: 70% + 30% = 100%.
MediumQ3. Find the proportion of students who passed, (a) among those who ate breakfast, (b) among those who did not. Is there an association between eating breakfast and passing? Show worked answer
(a) 54 ÷ 72 = 0.75 (75%). (b) 30 ÷ 48 = 0.625 (62.5%). Yes: 75% of breakfast eaters passed compared with 62.5% of those who skipped breakfast. The conditional distributions differ, so there is an association between eating breakfast and passing in this group. It does not prove breakfast causes passing; this is observational data.
MediumQ4. What proportion of students who passed had eaten breakfast? Why is this different from your answer to Q3(a)? Show worked answer
54 ÷ 84 ≈ 0.643 (about 64.3%). Q3(a) divided by the breakfast total (72): “of breakfast eaters, how many passed?” This question divides by the pass total (84): “of those who passed, how many ate breakfast?” Same cell, different condition.
MediumQ5. A basketball player makes 70% of her free throws. Describe how to use random digits to simulate one trial of her taking 3 free throws, recording whether she makes all three. Show worked answer
Let the digits 0 to 6 represent a made shot and 7 to 9 a miss, giving P(make) = 7/10 = 0.7. Repeats are allowed, since each shot is independent. One trial: read 3 random digits. Record “yes” if all three digits are between 0 and 6, otherwise “no”. (Repeating many times and finding the proportion of “yes” trials estimates the probability. The exact value is 0.7³ = 0.343.)
ExamQ6. In a class of 30 students, 12 are girls. The teacher claims she picks 4 students “at random” to present, but all 4 chosen are girls. Describe a simulation to estimate the probability that 4 students picked at random are all girls. In 200 trials of your simulation, 5 trials gave four girls. What do you conclude? [5 marks] Show worked answer
Label the students 01 to 30, with 01 to 12 representing the girls and 13 to 30 the boys [1]. One trial: read pairs of random digits, ignoring 00 and 31 to 99 and ignoring repeats, until you have 4 different labels. Record whether all 4 are from 01 to 12 [1]. (Repeats must be skipped because a student cannot be chosen twice.) Repeat for many trials, for example 200 [1]. Estimate: 5 ÷ 200 = 0.025 [1]. Conclusion: if the choice were truly random, getting 4 girls would happen only about 2.5% of the time. This is quite unlikely, so there is some evidence that the teacher’s choice was not random [1]. (The exact probability is (12 × 11 × 10 × 9) ÷ (30 × 29 × 28 × 27) ≈ 0.0181.)

Check yourself

1. In the travel table, what is 45 ÷ 100?

It is the proportion of Year 10 students (total 100) who take the bus: a cell divided by a group total.

2. Two categorical variables have no association when:

No association means knowing one variable does not change the distribution of the other.

3. To simulate an event with probability 0.25 using random digits, you should:

25 out of the 100 pairs gives exactly 0.25; single digits can only give tenths.

Your score: 0 out of 3

The short version

  • A two-way table counts individuals by two categorical variables; always check that rows and columns add up.
  • Joint: cell ÷ grand total. Marginal: total ÷ grand total. Conditional: cell ÷ total of the given group.
  • Compare conditional distributions (segmented bar charts or mosaic plots) to judge association, and remember association is not causation.
  • A simulation needs: a digit assignment with correct probabilities, a clear description of one trial, many repetitions, and an estimate in context.
  • More trials give a more reliable estimate of the true probability.
Want more questions like these, with worked answers?
The practice book has hundreds more, graded from easy to exam level.
Next: step 7 of 22Probability