📘 CodingMarble Learn

Two-Way Tables, Conditional Probability and Independence

A two-way table counts how many items fall in each pair of categories. Treating events as subsets of all outcomes, P(A and B) is the overlap cell. Conditional probability P(A|B) = P(A and B) / P(B) means: keep only the B group and count again. If P(A|B) = P(A), knowing B tells us nothing about A, and the events are independent.

🎬 Step-by-step story

  1. These are 100 students. Each cube is one student. For now they all look the same.
  2. Ask two questions: football? chess? The students move into four boxes. This is a two-way table.
  3. Add along the rows and columns. 60 play football. 30 like chess. Total 100.
  4. Now suppose we know the student plays football. Hide everyone else. 60 are left, and 18 of them like chess.
  5. Compare: knowing football gives 18 / 60 = 0.30. Everyone gives 30 / 100 = 0.30. They are equal, so the events are independent.
  6. Now try it yourself. Switch data A or B, change the condition, and see when the two numbers match.

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

🤔 Common doubts, cleared

How are the cells and the totals connected?

Each total is the sum of the cells in its row or column. Football 60 = 18 + 42. All totals together make 100.

Why do we divide by 60 and not by 100?

Because we already know the student plays football. Everyone else is hidden, so only 60 students are left to count.

Is P(A | B) the same as P(B | A)?

No. Look at the chess row: 18 out of 30 like football, but in the football column only 18 out of 60 like chess. Different groups, different answers.

What does independent really mean?

Knowing football does not change the chance of chess: 0.30 in the football group and 0.30 for everyone.

Does "A given B" mean B causes A?

No. Conditional probability only describes how common A is inside group B. It does not say why.

Do the two numbers have to match exactly?

For independence in a table, yes. Try data A (equal) and data B (0.45 against 0.30). In real surveys small gaps happen by chance.

Events as subsets

Think of all the students in the survey as one big set. An event is a smaller group inside it: the students who play football is event F, the students who like chess is event C. An event is a subset of everyone.

The chance of an event is the size of its group divided by the size of everyone: P(F) = 60 / 100 = 0.6.

Two-way tables

A two-way table sorts the same people by two questions at once. One question gives the rows, the other gives the columns. Each box (a cell) counts the people in both.

FootballNo footballTotal
Chess181230
No chess422870
Total6040100

The inside cells give joint counts (F and C = 18). The edges give totals for one question only. Always check that the cells add up to the grand total.

Conditional probability: keep only one group

P(C | F) is read "the probability of C given F". We already know the student plays football, so we look only at the football column. The new total is 60, not 100.

P(C | F) = P(C and F) ÷ P(F) = 18/100 ÷ 60/100 = 18/60 = 0.30.

Use the cell count on top and the column or row total of the condition at the bottom. Careful: P(F | C) = 18/30 = 0.60 is a different question, because the condition is now chess.

Independence: the test

Two events are independent if knowing one does not change the chance of the other. We test it with numbers:

Here P(C | F) = 0.30 and P(C) = 30/100 = 0.30. They match, so football and chess are independent in this survey. Also P(F) × P(C) = 0.6 × 0.3 = 0.18 = P(F and C).

In data B the football-and-chess cell is 27. Then P(C | F) = 27/60 = 0.45, which is not 0.30. Knowing football changes the chance, so the events are not independent.

Do not mix up independent with mutually exclusive. Mutually exclusive events share no cell. Independent events usually share one.

Try it: make your own table

Ask 20 people at home two yes/no questions, for example "Do you like tea?" and "Do you like coffee?". Make a 2 by 2 table. Then work out P(coffee), P(coffee | tea) and compare. Before you calculate, guess: will they be equal? Then check. Real data is rarely perfectly independent, so small differences are normal.

Key formulas and definitions

Worked examples

1. In a survey of 100 students, 60 play football and 18 play football and like chess. Find P(football and chess).

P = 18 / 100 = 0.18.

2. Of 200 commuters, 120 take the bus and 30 take the bus and also cycle. Find P(cycle | bus).

Keep only the 120 bus users. P = 30 / 120 = 0.25.

3. Using the 100-student table, find P(football or chess).

Add the groups and remove the overlap counted twice: (60 + 30 - 18) / 100 = 72 / 100 = 0.72.

4. Using the same table, find P(football | chess) and compare it with P(chess | football).

P(football | chess) = 18 / 30 = 0.60. P(chess | football) = 18 / 60 = 0.30. They are different because the condition is different.

5. Of 50 students, 20 wear glasses. Of the 30 girls, 12 wear glasses. Are 'girl' and 'glasses' independent?

P(glasses) = 20/50 = 0.40. P(glasses | girl) = 12/30 = 0.40. They are equal, so the events are independent.

6. P(A) = 0.4, P(B) = 0.5 and P(A and B) = 0.3. Are A and B independent?

P(A) × P(B) = 0.4 × 0.5 = 0.20, but P(A and B) = 0.30. They are not equal, so A and B are not independent.

Common mistakes

Practice quiz

1. In a two-way table, a cell shows:
2. P(A | B) means the chance of A:
3. 40 of 100 are in B and 10 are in both A and B. P(A | B) is:
4. A and B are independent when:
5. If P(A) = 0.2, P(B) = 0.5 and A, B are independent, P(A and B) is:

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 conditional probability in simple words?

It is the chance of something when you already know something else is true. You shrink the group to people who fit the condition, then count again.

How do I check independence from a two-way table?

Find P(A) from the totals and P(A | B) from one column or row. If the two numbers are equal, the events are independent.

Are independent events the same as mutually exclusive events?

No. Mutually exclusive events cannot happen together. Independent events do not change each other's chance and can easily happen together.

Learn first

Learn next

Related lessons

All Maths lessons