Edit the joint table and watch the row and column totals (the marginals) update. Click a row or column heading to condition on it: the bars show the conditional distribution next to the marginal, and the set picture keeps only that group. The cards below test independence and compare \(P(A \mid B)\) with \(P(B \mid A)\).
← All labsBased on Chapter 1, Probability and Uncertainty, of Polson and Sokolov, Bayes, Artificial Intelligence, and Deep Learning (vsokolov.org/html/_book).
Each cell is the share of everyone who has both that salary and that happiness. The four rows run from low salary to very high. The three columns run from low happiness to high. The entries already add to 1.
| Low happiness | Medium | High | Share of everyone | |
|---|---|---|---|---|
| Low salary | 0.03 | 0.12 | 0.07 | 0.22 |
| Medium | 0.02 | 0.13 | 0.11 | 0.26 |
| High | 0.01 | 0.13 | 0.14 | 0.28 |
| Very high | 0.01 | 0.09 | 0.14 | 0.24 |
| Share of everyone | 0.07 | 0.47 | 0.46 | 1 |
The outlined cell, 0.14, is the 14% of people with a very high salary who also report high happiness. The rightmost column ignores happiness: 24% have a very high salary. The bottom row ignores salary: 46% report high happiness, and only 7% report low happiness. Salary itself is spread fairly evenly.
Keeping the very high salary row and dividing by its total, 0.24, gives about 0.04, 0.38, and 0.58. High happiness in that group is 0.14 / 0.24 = 0.583, above the 0.46 for everyone. Across the four salaries, the share reporting high happiness is about 0.32, 0.42, 0.50, and 0.58. Higher salary goes with a larger share reporting high happiness, which is why the cuts in the picture do not line up. If salary told you nothing, every row would split 0.07, 0.47, 0.46.
The same 0.14 answers a second question when you divide by the high-happiness column instead of the row. Among people who report high happiness, the share with a very high salary is 0.14 / 0.46 = 0.304. High happiness given a very high salary is 0.583. A very high salary given high happiness is 0.304. One cell, two groups, two totals.
If X and Y are independent, every cell equals its row total times its column total. The third table shows how far each actual cell is from that product.
| P(A and B) | – |
| P(A) | – |
| P(B) | – |
| Base-rate ratio P(A) / P(B) | – |
Every probability in this topic can be read off one joint table. The joint is a cell, a marginal is a row or column total, and a conditional is one row or column rescaled so it adds to 1.
The cell in row \(X = 3\), column \(Y = 2\) holds \(P(X = 3, Y = 2) = 0.14\). Of all people, 14% are very high earners who also report high happiness. In the set picture that cell is one block, and its area is that 14%.
The row total \(P(X = 3) = 0.01 + 0.09 + 0.14 = 0.24\) ignores happiness. The column total \(P(Y = 2) = 0.46\) ignores salary.
Knowing \(X = 3\) removes every other row. Dividing the row by its total gives \(P(Y = 2 \mid X = 3) = 0.14 / 0.24 = 0.583\). That beats 0.46, so very high earners are more likely to report high happiness. The right-hand set is that one group, stretched to fill the square.
If every salary row, once rescaled, looked like the marginal row, salary would tell you nothing about happiness. Then each cell equals \(P(x)\cdot P(y)\). In this table the rows do not match, and the cuts in the picture do not line up.
Takeaway for students. \(P(A \mid B)\) and \(P(B \mid A)\) share the same numerator, \(P(A \text{ and } B)\). They divide it by different totals. High happiness given very high salary is 0.583. Very high salary given high happiness is 0.304. Same cell, two different questions.