Instant PDF download, name-and-email checkout. Complete Book Bundle: every Economics, Statistics, Mathematics and Econometrics book
Statistics

Two-Way Tables and Conditional Probability: Marginal, Joint and Testing for Independence

Two-way tables and conditional probability explained: marginal, joint and conditional probabilities and a test for independence, with a worked example.

In 30 seconds
  • Two-way tables show counts for two categorical variables at once: one variable in the rows, one in the columns, and totals in the margins.
  • From one table you can read three kinds of probability: marginal (one variable alone, from the totals), joint (both at once, from an inner cell) and conditional (one given the other, from a single row or column).
  • In our case, 500 students sat a morning test: 60% of breakfast-eaters passed but only 30% of those who skipped breakfast did, against 48% overall.
  • Because \( P(\text{pass} \mid \text{breakfast}) = 0.60 \ne P(\text{pass}) = 0.48 \), passing and eating breakfast are not independent in these data. That is an association, not proof that breakfast causes better marks.
  • Exam point: always say which total you are dividing by. “Given” means you restrict to one row or column and divide by its total.

The case: does breakfast go with better test results?

A school nurse believes that students who skip breakfast do worse in morning lessons. To check, the school adds one question to a morning maths test taken by 500 students: “Did you eat breakfast today?” It then records whether each student passed the test.

Of the 500 students, 300 had eaten breakfast and 200 had not. Of the 300 breakfast-eaters, 180 passed. Of the 200 who skipped breakfast, 60 passed. In total, 240 students passed and 260 failed.

The head teacher asks three questions. What is the chance that a randomly chosen student passed? What is the chance that a student who ate breakfast passed, compared with one who did not? And is there evidence that passing is linked to eating breakfast, or could the two be unrelated? All three can be answered from one small table. (The figures are illustrative.)

The concept: marginal, joint and conditional probability

A two-way table (also called a contingency table) records counts for two categorical variables measured on the same individuals. Here the variables are breakfast (yes or no) and result (pass or fail). Each student falls into exactly one inner cell. The row totals and column totals sit in the margins, and the grand total sits in the corner.

If we choose one student at random from the 500, every count in the table becomes a probability once we divide by the right total. There are three kinds.

A marginal probability involves only one variable and uses a margin total. For example, \( P(\text{pass}) = 240/500 = 0.48 \).

A joint probability involves both variables at once and uses an inner cell over the grand total. For example, \( P(\text{breakfast and pass}) = 180/500 = 0.36 \).

A conditional probability is the probability of one event given that another has happened. The word “given” means we restrict attention to one row or column and divide by that row’s or column’s total. For example, the probability that a student passed, given that they ate breakfast, is \( P(\text{pass} \mid \text{breakfast}) = 180/300 = 0.60 \). The vertical bar is read “given”.

Key termTwo-way table: a table of counts that classifies individuals by two categorical variables, one in the rows and one in the columns, with row totals, column totals and a grand total. It is used to find marginal, joint and conditional probabilities and to check for association or independence.

The formal definition of conditional probability links all three kinds:

\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)}, \qquad \text{and } A \text{ and } B \text{ are independent if } P(A \mid B) = P(A) \]

Here \( A \) and \( B \) are events (for example, \( A \) = “passed” and \( B \) = “ate breakfast”). \( P(A \cap B) \) is the joint probability that both happen. \( P(B) \) is the marginal probability of the condition. \( P(A \mid B) \) is the conditional probability of \( A \) given \( B \). In a two-way table the formula simply says: the count in the cell divided by the total of the row (or column) you are conditioning on, since the grand totals cancel. Two events are independent if knowing that one happened does not change the probability of the other. An equivalent test is the multiplication rule: \( A \) and \( B \) are independent if and only if \( P(A \cap B) = P(A) \times P(B) \)[2].

Statistics Made Simple textbook coverStatistics Made Simple explains two-way tables and conditional probability with worked examples, diagrams and tables.Get the textbook · $12

Why this method fits the case

Both variables in the breakfast study are categorical: each student either ate breakfast or did not, and either passed or failed. There are no means or standard deviations to compute. What we want is a comparison of proportions between groups, and a two-way table is the natural home for that. It keeps every count visible, so a reader can check each probability, and it makes the denominator for each question obvious.

The independence check answers the head teacher’s third question directly. If breakfast and passing were unrelated, the pass rate would be the same, 48%, in both rows. Any big difference between rows is evidence of an association.

When is a two-way table not the right tool? If either variable is quantitative, for example the actual test mark out of 100, you lose information by cutting it into “pass” and “fail”; comparing the two groups’ marks with box plots or a two-sample test is better. If there is a third variable that could be driving both, such as family income or year group, one two-way table can mislead you; you would need to split the table by that variable (and you may meet Simpson’s paradox). And a two-way table, on its own, cannot tell you whether a difference this size could be just chance. For that you need a formal test such as the chi-square test for independence or a two-proportion z-test.

Setting it up

Put the explanatory variable (breakfast) in the rows and the response (result) in the columns. Fill in the counts you are given, then use the totals to complete the rest: for example, failed with breakfast \( = 300 – 180 = 120 \).

PassedFailedRow total
Ate breakfast180120300
No breakfast60140200
Column total240260500

Check: the inner cells add to \( 180 + 120 + 60 + 140 = 500 \), the row totals add to 500 and the column totals add to 500.

Solving it

Worked example

Example 1 (marginal and joint probabilities). A student is chosen at random from the 500. Find \( P(\text{pass}) \), \( P(\text{breakfast}) \), \( P(\text{breakfast and pass}) \) and \( P(\text{breakfast or pass}) \).

Step 1Marginal: \( P(\text{pass}) = 240/500 = 0.48 \); \( P(\text{breakfast}) = 300/500 = 0.60 \).
Step 2Joint: \( P(\text{breakfast} \cap \text{pass}) = 180/500 = 0.36 \).
Step 3Union, using the addition rule: \( P(\text{breakfast} \cup \text{pass}) = 0.60 + 0.48 – 0.36 = 0.72 \).
Step 4Check by counting: students who ate breakfast or passed (or both) \( = 300 + 60 = 360 \), and \( 360/500 = 0.72 \).

48% of students passed, and 36% both ate breakfast and passed.

Worked example

Example 2 (conditional probability both ways round). Find \( P(\text{pass} \mid \text{breakfast}) \), \( P(\text{pass} \mid \text{no breakfast}) \) and \( P(\text{breakfast} \mid \text{pass}) \).

Step 1Given breakfast: restrict to the “Ate breakfast” row, total 300. \( P(\text{pass} \mid \text{breakfast}) = 180/300 = 0.60 \).
Step 2Given no breakfast: restrict to that row, total 200. \( P(\text{pass} \mid \text{no breakfast}) = 60/200 = 0.30 \).
Step 3Given pass: restrict to the “Passed” column, total 240. \( P(\text{breakfast} \mid \text{pass}) = 180/240 = 0.75 \).
Step 4Check with the formula: \( P(\text{pass} \mid \text{breakfast}) = P(\text{breakfast} \cap \text{pass})/P(\text{breakfast}) = 0.36/0.60 = 0.60 \).

Breakfast-eaters passed at twice the rate of non-eaters (60% v 30%), and three quarters of those who passed had eaten breakfast.

Worked example

Example 3 (testing for independence). Use two different methods to decide whether “passed” and “ate breakfast” are independent in these data. Then find the counts you would expect if they were independent.

Step 1Conditional method: \( P(\text{pass} \mid \text{breakfast}) = 0.60 \) but \( P(\text{pass}) = 0.48 \). They differ, so the events are not independent.
Step 2Multiplication method: \( P(\text{breakfast}) \times P(\text{pass}) = 0.60 \times 0.48 = 0.288 \), but \( P(\text{breakfast} \cap \text{pass}) = 0.36 \). Again they differ.
Step 3Expected counts under independence: row total × column total ÷ grand total. Breakfast and pass: \( 300 \times 240/500 = 144 \). Breakfast and fail: \( 300 \times 260/500 = 156 \). No breakfast and pass: \( 200 \times 240/500 = 96 \). No breakfast and fail: \( 200 \times 260/500 = 104 \).
Step 4Compare: 180 students in the breakfast-and-pass cell against 144 expected; 60 in the no-breakfast-and-pass cell against 96 expected.

The observed counts are far from the independence counts, so in these data passing and eating breakfast are associated.

Statistics Made Simple Practice Questions coverMake two-way tables and conditional probability automatic with the Practice Questions book: 1,569 questions, all fully worked.Get 1,569 questions · $9

What the answer tells us

Figure 1 shows the conditional distributions of the result for each breakfast group as segmented bars. If breakfast and passing were independent, both group bars would split at the same height as the overall bar, 48%. They do not: the breakfast bar splits at 60% and the no-breakfast bar at 30%.

Pass rate on the morning test, by breakfast group (% of students in each group)
PassedFailedOverall P(pass)
0%10%20%30%40%50%60%70%80%90%100%Pass 60%Fail 40%Ate breakfast (n = 300)Pass 30%Fail 70%No breakfast (n = 200)Pass 48%Fail 52%All students (n = 500)48% overall
Figure 1. If breakfast and passing were independent, both group bars would split at the overall 48% line. Instead the breakfast group splits at 60% and the no-breakfast group at 30%. (The figures are illustrative.)

Association is not causation. This was an observational study. The school did not decide who ate breakfast; the students (and their families) did. Students who eat breakfast may also sleep more, have more settled home routines or be more organised in general, and any of those could explain better marks. These are possible confounding variables. To show that breakfast itself improves results, you would need a randomised experiment, for example randomly assigning students to receive a school breakfast or not. The two-way table shows a strong association; it cannot by itself show cause[1].

Could it be chance? With 500 students and a 30-point gap, chance is very unlikely to explain it. A two-proportion z-test gives a test statistic of about 6.6, far beyond any usual critical value, and a chi-square test on this table leads to the same conclusion. Our existing posts on the chi-square test cover that formal step.

Reasonableness check. The overall pass rate must lie between the two group rates, because it is their weighted average: \( 0.60 \times 0.60 + 0.40 \times 0.30 = 0.36 + 0.12 = 0.48 \). It does. That identity is the law of total probability, and checking it is a quick way to catch arithmetic slips.

Sensitivity. Suppose only 90 of the 200 non-eaters had failed, so that 110 passed. Then \( P(\text{pass} \mid \text{no breakfast}) = 110/200 = 0.55 \) and the overall rate would be \( 290/500 = 0.58 \), very close to the breakfast group’s 60%. The gap, and the evidence of association, would almost vanish. Conclusions from a two-way table can change quickly if a few cells change, which is why the counts, not just the percentages, should always be reported.

Common mistakeConfusing \( P(A \mid B) \) with \( P(B \mid A) \). The probability that a student passed given breakfast (0.60) is not the same as the probability that a student ate breakfast given they passed (0.75). They use different denominators: the breakfast row (300) versus the pass column (240). Always ask “which group am I restricting to?”
Common mistakeMixing up “independent” and “mutually exclusive”. Mutually exclusive events cannot happen together, so \( P(A \cap B) = 0 \). Independent events can happen together; one just does not change the probability of the other. Two events with non-zero probabilities cannot be both mutually exclusive and independent.
Exam tipFor “show that A and B are not independent”, one clear numerical comparison is enough: either \( P(A \mid B) \ne P(A) \) or \( P(A \cap B) \ne P(A)P(B) \), with both numbers written out. Finish with a sentence in context. Questions using two-way tables and conditional probability appear in AP Statistics, Cambridge AS & A Level Mathematics (probability and statistics) and IB Mathematics; all of them expect you to show the fraction you used, not just the final decimal[3].

Our Statistics Made Simple textbook covers two-way tables, the addition and multiplication rules, tree diagrams and independence step by step, and the Statistics Made Simple Practice Questions book has hundreds of conditional probability questions with fully worked answers.

Statistics Made Simple bundle coverMaster probability and categorical data with both Statistics Made Simple books for $16.Both books · $16

Practice questions

Try each question before opening the worked answer. The last one is written in exam style with a mark scheme.

EasyQ1. Using the breakfast table, find the probability that a randomly chosen student skipped breakfast and failed. Show worked answer
This is a joint probability: use the inner cell over the grand total.
\( P(\text{no breakfast} \cap \text{fail}) = 140/500 = 0.28 \).
EasyQ2. Using the breakfast table, find the probability that a student failed, given that they skipped breakfast. Show worked answer
Restrict to the “No breakfast” row, total 200.
\( P(\text{fail} \mid \text{no breakfast}) = 140/200 = 0.70 \).
MediumQ3. In a survey of 400 adults, 160 own a dog. Of the dog owners, 120 walk at least 30 minutes a day; of the 240 non-owners, 150 do. Find \( P(\text{walks}) \) and \( P(\text{walks} \mid \text{dog}) \), and decide whether walking and dog ownership are independent. Show worked answer
Walkers \( = 120 + 150 = 270 \), so \( P(\text{walks}) = 270/400 = 0.675 \).
\( P(\text{walks} \mid \text{dog}) = 120/160 = 0.75 \).
\( 0.75 \ne 0.675 \), so the events are not independent: dog owners are more likely to walk daily in this sample.
MediumQ4. Events A and B have \( P(A) = 0.4 \), \( P(B) = 0.5 \) and \( P(A \cap B) = 0.2 \). Find \( P(A \mid B) \) and \( P(A \cup B) \), and state whether A and B are independent. Show worked answer
\( P(A \mid B) = 0.2/0.5 = 0.4 \).
\( P(A \cup B) = 0.4 + 0.5 – 0.2 = 0.7 \).
\( P(A \mid B) = 0.4 = P(A) \) (equivalently \( 0.4 \times 0.5 = 0.2 \)), so A and B are independent.
ExamQ5. 800 customers of a streaming service are classified by plan (Basic 480, Premium 320) and whether they renewed (384 renewed in total). 192 Premium customers renewed. (a) Complete the two-way table. (b) Find P(renewed | Premium) and P(renewed | Basic). (c) Determine whether renewing is independent of plan, and interpret in context. [7 marks] Show worked answer
(a) Premium: renewed 192, not renewed \( 320 – 192 = 128 \). [1] Basic: renewed \( 384 – 192 = 192 \), not renewed \( 480 – 192 = 288 \). Not renewed total \( = 800 – 384 = 416 \). [1]
(b) \( P(\text{renewed} \mid \text{Premium}) = 192/320 = 0.60 \). [1] \( P(\text{renewed} \mid \text{Basic}) = 192/480 = 0.40 \). [1]
(c) \( P(\text{renewed}) = 384/800 = 0.48 \). [1] Since \( 0.60 \ne 0.48 \), renewing is not independent of plan. [1] Premium customers were more likely to renew (60% v 40%); this is an association and may reflect the type of customer who chooses Premium, not the plan itself. [1]

Frequently asked questions

What is the difference between a joint and a conditional probability?

A joint probability, \( P(A \cap B) \), asks how likely it is that both events happen, out of everyone; in a table you divide a cell by the grand total. A conditional probability, \( P(A \mid B) \), asks how likely \( A \) is among only those for whom \( B \) happened; you divide the same cell by the total for \( B \).

Why are they called marginal probabilities?

Because they come from the totals written in the margins of the table, at the end of each row and the bottom of each column. They describe one variable on its own, ignoring the other.

If two events are not independent, does one cause the other?

No. Dependence in a table only shows that the two variables are associated. The link could be caused by a third variable, could run in the other direction, or could be partly chance in a small sample. Cause and effect needs a well-designed randomised experiment.

How is a two-way table related to a tree diagram?

They hold the same information. A tree diagram for “breakfast, then result” would have first branches 0.6 and 0.4, then pass branches 0.6 (after breakfast) and 0.3 (after no breakfast). Multiplying along the branches gives the joint probabilities, which are the inner cells of the table divided by 500. Tables are easier when you start from counts; trees are easier when you start from conditional probabilities.

References

  1. Illowsky, B. and Dean, S. (2023) Introductory Statistics 2e. Houston, TX: OpenStax. https://openstax.org/details/books/introductory-statistics-2e
  2. Agresti, A., Franklin, C. and Klingenberg, B. Statistics: The Art and Science of Learning from Data. Harlow: Pearson.
  3. Cambridge International. Cambridge International AS & A Level Mathematics 9709 syllabus 2026–2027. https://www.cambridgeinternational.org/programmes-and-qualifications/cambridge-international-as-and-a-level-mathematics-9709/
  4. College Board. AP Statistics Course and Exam Description. New York: College Board.
  5. Starnes, D. S. and Tabor, J. The Practice of Statistics. New York: W. H. Freeman.
Statistics Made Simple Complete Bundle cover showing both the textbook and practice book
This topic has a full chapter in Statistics Made Simple, with 1,569 worked practice questions in the bundle.Statistics Made Simple Complete Bundle — Textbook + 1,569 Practice Questions
Get it for $16
E

The EconTutorials team writes clear, exam-focused lessons in economics and statistics for A-Level, IB, AP and university students, with more than 13 years of classroom teaching behind every guide and book in the Made Simple series.