Skip to content
VibeFormer
Beginner24 min

Joint, Marginal and Conditional Probability

Reading probability tables, the multiplication rule, and marginalising a joint distribution.

Joint, Marginal and Conditional Probability

Intuition first

Most real questions involve two things at once: age and churn, symptom and disease, word and spam. Once there are two attributes, there are three different questions you can ask, and they have three different answers.

Picture a table of 100 people split by whether they exercise and whether they sleep well.

  • Joint: pick one person at random — what is the chance they exercise and sleep well? That is one cell of the table divided by 100.
  • Marginal: what is the chance they exercise, ignoring sleep entirely? That is a whole row total divided by 100.
  • Conditional: given that they exercise, what is the chance they sleep well? That is one cell divided by its row total — you have thrown away everyone who does not exercise.

The only mechanical difference is what you divide by. Get the denominator right and conditional probability stops being confusing.

Notation used in this lesson
SymbolMeaning
P(A ∩ B)Joint: both A and B occur
P(A)Marginal: A occurs, regardless of B
P(A | B)Conditional: A occurs, given B occurred
P(A, B)Alternative notation for the joint probability

A worked table

A survey of 100 people records exercise habit and sleep quality.

Sleeps wellSleeps badlyRow total
Exercises351550
Does not153550
Column total5050100

Let EE = "exercises" and WW = "sleeps well".

Joint probabilities — cells ÷ grand total

P(EW)=35100=0.35\Prob(E \cap W) = \frac{35}{100} = 0.35

Each of the four cells gives a joint probability, and the four sum to 11:

0.35+0.15+0.15+0.35=1  0.35 + 0.15 + 0.15 + 0.35 = 1 \;\checkmark

Marginal probabilities — totals ÷ grand total

P(E)=50100=0.5,P(W)=50100=0.5\Prob(E) = \frac{50}{100} = 0.5, \qquad \Prob(W) = \frac{50}{100} = 0.5

The word marginal is literal: these are the numbers written in the margins of the table.

Marginals are obtained from joints by summing over the variable you want to discard:

P(E)=P(EW)+P(EWc)=0.35+0.15=0.5\Prob(E) = \Prob(E \cap W) + \Prob(E \cap W^c) = 0.35 + 0.15 = 0.5

Conditional probabilities — cell ÷ row or column total

P(WE)=3550=0.7\Prob(W \mid E) = \frac{35}{50} = 0.7

Among the 50 people who exercise, 35 sleep well. The denominator changed from 100 to 50 because conditioning on EE discards everyone outside EE.

The definition of conditional probability

P(AB)=P(AB)P(B),P(B)>0\Prob(A \mid B) = \frac{\Prob(A \cap B)}{\Prob(B)}, \qquad \Prob(B) > 0
Where the formula comes fromAdvanced

Conditioning on BB means restricting the sample space to BB — we now treat BB as the whole world. Within that restricted world, the outcomes favourable to AA are exactly those in ABA \cap B.

For equally likely outcomes this is transparent:

P(AB)=ABB\Prob(A \mid B) = \frac{|A \cap B|}{|B|}

Divide numerator and denominator by Ω|\Omega|:

P(AB)=AB/ΩB/Ω=P(AB)P(B)\Prob(A \mid B) = \frac{|A \cap B| / |\Omega|}{|B| / |\Omega|} = \frac{\Prob(A \cap B)}{\Prob(B)}

The general definition is taken to be this ratio, which reduces to the counting version when outcomes are equally likely. Dividing by P(B)\Prob(B) is precisely what re-normalises the restricted world so its probabilities sum to 1 again.

Check with the table:

P(WE)=P(EW)P(E)=0.350.5=0.7  \Prob(W \mid E) = \frac{\Prob(E \cap W)}{\Prob(E)} = \frac{0.35}{0.5} = 0.7 \;\checkmark

The multiplication rule

Rearranging the definition gives a rule for building joints out of conditionals:

P(AB)=P(AB)P(B)=P(BA)P(A)\Prob(A \cap B) = \Prob(A \mid B)\,\Prob(B) = \Prob(B \mid A)\,\Prob(A)

Both forms are valid, which is the seed of Bayes' theorem two lessons from now.

Extended to three events (the chain rule):

P(ABC)=P(A)P(BA)P(CAB)\Prob(A \cap B \cap C) = \Prob(A)\,\Prob(B \mid A)\,\Prob(C \mid A \cap B)

Conditioning is not symmetric

P(AB)\Prob(A \mid B) and P(BA)\Prob(B \mid A) are different quantities. From the table:

P(WE)=3550=0.70,P(EW)=3550=0.70\Prob(W \mid E) = \frac{35}{50} = 0.70, \qquad \Prob(E \mid W) = \frac{35}{50} = 0.70

Here they coincide, but only because the margins happen to be equal. Change the table so 80 people exercise and 20 do not, keeping P(EW)=0.35\Prob(E \cap W) = 0.35:

P(WE)=0.350.80=0.4375,P(EW)=0.350.50=0.70\Prob(W \mid E) = \frac{0.35}{0.80} = 0.4375, \qquad \Prob(E \mid W) = \frac{0.35}{0.50} = 0.70

Solved problem 1 · Reading all three from one table

A shop classifies 200 visits by whether the visitor used a mobile device and whether they purchased.

PurchasedDid notTotal
Mobile2496120
Desktop324880
Total56144200

Let MM = mobile, BB = purchased. Find the joint, both marginals, and both conditionals. Are MM and BB independent?

Step 1 — joint probability

P(MB)=24200=0.12\Prob(M \cap B) = \frac{24}{200} = 0.12

Step 2 — marginals from the totals

P(M)=120200=0.60,P(B)=56200=0.28\Prob(M) = \frac{120}{200} = 0.60, \qquad \Prob(B) = \frac{56}{200} = 0.28

Step 3 — conversion rate on mobile

P(BM)=P(MB)P(M)=0.120.60=0.20\Prob(B \mid M) = \frac{\Prob(M \cap B)}{\Prob(M)} = \frac{0.12}{0.60} = 0.20

Directly from the table: 24/120=0.2024/120 = 0.20 — 20% of mobile visits convert.

Step 4 — share of purchasers who were on mobile

P(MB)=P(MB)P(B)=0.120.280.4286\Prob(M \mid B) = \frac{\Prob(M \cap B)}{\Prob(B)} = \frac{0.12}{0.28} \approx 0.4286

Directly: 24/560.428624/56 \approx 0.4286 — about 43% of purchasers came from mobile.

Note how different these two numbers are (0.20 versus 0.43) despite sharing the same numerator. They answer different questions.

Step 5 — test independence

P(M)P(B)=0.60×0.28=0.168\Prob(M)\Prob(B) = 0.60 \times 0.28 = 0.168P(MB)=0.120.168\Prob(M \cap B) = 0.12 \neq 0.168

Not independent. Compare the conditional with the marginal:

P(BM)=0.20<P(B)=0.28\Prob(B \mid M) = 0.20 < \Prob(B) = 0.28

Mobile visitors convert at 20% against a 28% baseline, so device type carries genuine information about purchasing.

Answer

P(MB)=0.12\Prob(M \cap B) = 0.12; P(M)=0.60\Prob(M) = 0.60; P(B)=0.28\Prob(B) = 0.28; P(BM)=0.20\Prob(B \mid M) = 0.20; P(MB)0.429\Prob(M \mid B) \approx 0.429. The events are not independent — mobile visitors convert below the overall rate.

Solved problem 2 · Drawing without replacement

An urn holds 5 red and 3 blue balls. Two are drawn without replacement. Find the probability that both are red.

Step 1 — name the events

Let R1R_1 = first ball red, R2R_2 = second ball red. We want P(R1R2)\Prob(R_1 \cap R_2).

Step 2 — the first draw

P(R1)=58\Prob(R_1) = \frac{5}{8}

Step 3 — the second draw, conditioned on the first

After removing one red ball, 7 balls remain of which 4 are red:

P(R2R1)=47\Prob(R_2 \mid R_1) = \frac{4}{7}

This conditional differs from P(R2)\Prob(R_2), which is what "without replacement" means — the draws are dependent.

Step 4 — multiplication rule

P(R1R2)=P(R2R1)P(R1)=47×58=2056=5140.357\Prob(R_1 \cap R_2) = \Prob(R_2 \mid R_1)\,\Prob(R_1) = \frac{4}{7} \times \frac{5}{8} = \frac{20}{56} = \frac{5}{14} \approx 0.357

Step 5 — verify by counting

Choose 2 of 5 reds from 2 of 8 balls:

(52)(82)=1028=514  \frac{\binom{5}{2}}{\binom{8}{2}} = \frac{10}{28} = \frac{5}{14} \;\checkmark

Answer

P(both red)=5140.357\Prob(\text{both red}) = \dfrac{5}{14} \approx 0.357.

Conditional probability obeys the axioms

For fixed BB with P(B)>0\Prob(B) > 0, the function AP(AB)A \mapsto \Prob(A \mid B) is itself a valid probability measure. In particular:

P(AcB)=1P(AB)\Prob(A^c \mid B) = 1 - \Prob(A \mid B)
Verifying the axioms for conditional probabilityAdvanced

Non-negativity. P(AB)=P(AB)/P(B)\Prob(A \mid B) = \Prob(A \cap B)/\Prob(B) is a non-negative number divided by a positive one, so it is 0\geq 0.

Normalisation.

P(ΩB)=P(ΩB)P(B)=P(B)P(B)=1\Prob(\Omega \mid B) = \frac{\Prob(\Omega \cap B)}{\Prob(B)} = \frac{\Prob(B)}{\Prob(B)} = 1

Additivity. For disjoint A1,A2A_1, A_2, the sets A1BA_1 \cap B and A2BA_2 \cap B are also disjoint, so

P(A1A2B)=P((A1B)(A2B))P(B)=P(A1B)+P(A2B)P(B)\Prob(A_1 \cup A_2 \mid B) = \frac{\Prob((A_1 \cap B) \cup (A_2 \cap B))}{\Prob(B)} = \frac{\Prob(A_1 \cap B) + \Prob(A_2 \cap B)}{\Prob(B)}

which is P(A1B)+P(A2B)\Prob(A_1 \mid B) + \Prob(A_2 \mid B).

All three axioms hold, so every theorem proved for P\Prob also holds for P(B)\Prob(\cdot \mid B). This is why you may freely use the complement rule and inclusion–exclusion inside a conditional.

Exercise 1

From the shop table, compute P(BMc)\Prob(B \mid M^c) — the desktop conversion rate — and confirm that the two conditional rates, weighted by their marginals, recover P(B)\Prob(B).

Show solution
P(BMc)=3280=0.40\Prob(B \mid M^c) = \frac{32}{80} = 0.40

Weighting each rate by the share of traffic:

P(B)=P(BM)P(M)+P(BMc)P(Mc)\Prob(B) = \Prob(B \mid M)\Prob(M) + \Prob(B \mid M^c)\Prob(M^c)=0.20(0.60)+0.40(0.40)=0.12+0.16=0.28  = 0.20(0.60) + 0.40(0.40) = 0.12 + 0.16 = 0.28 \;\checkmark

This weighted-average identity is the law of total probability, covered in the next lesson.

Exercise 2

A family has two children. Given that at least one is a girl, what is the probability both are girls? Assume each child is independently a girl with probability 1/21/2.

Show solution

Sample space with birth order: Ω={GG,GB,BG,BB}\Omega = \{GG, GB, BG, BB\}, each of probability 1/41/4.

Let AA = "at least one girl" ={GG,GB,BG}= \{GG, GB, BG\} and CC = "both girls" ={GG}= \{GG\}.

P(CA)=P(CA)P(A)=1/43/4=13\Prob(C \mid A) = \frac{\Prob(C \cap A)}{\Prob(A)} = \frac{1/4}{3/4} = \frac{1}{3}

Not 1/21/2. Conditioning on "at least one" eliminates only BBBB, leaving three equally likely cases, of which one is GGGG.

The common wrong answer, 1/21/2, comes from imagining a specific child is a girl. That is a different condition: "the elder is a girl" restricts to {GG,GB}\{GG, GB\} and does give 1/21/2.

Exercise 3

Show that if P(AB)>P(A)\Prob(A \mid B) > \Prob(A), then P(BA)>P(B)\Prob(B \mid A) > \Prob(B).

Show solution

Start from the assumption and substitute the definition:

P(AB)P(B)>P(A)\frac{\Prob(A \cap B)}{\Prob(B)} > \Prob(A)

Multiply both sides by P(B)>0\Prob(B) > 0:

P(AB)>P(A)P(B)\Prob(A \cap B) > \Prob(A)\Prob(B)

Now divide both sides by P(A)>0\Prob(A) > 0:

P(AB)P(A)>P(B)P(BA)>P(B)\frac{\Prob(A \cap B)}{\Prob(A)} > \Prob(B) \quad\Longrightarrow\quad \Prob(B \mid A) > \Prob(B)

So "positive association" is symmetric: if BB raises the chance of AA, then AA raises the chance of BB — even though the two conditional probabilities themselves are generally different numbers.


Next: The Law of Total Probability, which formalises the weighted-average trick from Exercise 1 and is the direct prerequisite for Bayes' theorem.