How do you calculate conditional probability from a two-way table?
P(A given B) is the count of A-and-B divided by the count of B. You restrict attention to the rows or columns where B is true and compute the share there. P(A given B) is not the same as P(B given A).
Explain it simply
"Given B" means we shrink the universe to only those cases where B happened. Then count what fraction of that smaller group also has A.
P(A | B) = P(A and B) / P(B)
Example
A college has 100 students in a placement drive.
| Placed | Not placed | Total | |
|---|---|---|---|
| Boys | 21 | 39 | 60 |
| Girls | 16 | 24 | 40 |
| Total | 37 | 63 | 100 |
- P(placed) = 37 / 100 = 0.37
- P(placed | girl) = 16 / 40 = 0.40
- P(girl | placed) = 16 / 37 = 0.432
The two conditionals answer different questions and use different denominators.
placed_girl, girls, placed = 16, 40, 37
print(placed_girl / girls) # 0.4
print(round(placed_girl / placed, 3)) # 0.432What to say in the interview
"For conditional probability I restrict to the given condition and use its count as the denominator. Here, among girls the placement rate is 40%, but only 43% of placed students are girls. These are different numbers, and mixing them up is a common error."
Common mistakes
- Dividing by the grand total instead of the total of the condition.