1.3.13Probability & Statistics

Joint, marginal, and conditional distributions

1,640 words7 min readdifficulty · medium3 backlinks

WHY do we need all three?

  • WHAT we have: two RVs, say XX = "is email spam?" and YY = "does it contain the word free?"
  • WHY we care: a joint p(X,Y)p(X,Y) is the complete description — you can recover any question about XX and YY from it. But often we only want part of the story:
    • "How often is email spam, ignoring words?" → marginal
    • "Given the word free appeared, how likely is spam?" → conditional
  • HOW they connect: marginal = collapse a dimension; conditional = take a slice and rescale.

Definitions from first principles

Deriving the conditional (don't memorize — build it)

From the two ways of factoring the joint we immediately get Bayes' theorem: pXY(xy)=pYX(yx)pX(x)pY(y).p_{X\mid Y}(x\mid y) = \frac{p_{Y\mid X}(y\mid x)\,p_X(x)}{p_Y(y)}.

Figure — Joint, marginal, and conditional distributions

Worked Example 1 — a 2×2 joint table (discrete)

Let XX = spam? (x{0,1}x\in\{0,1\}), YY = contains "free"? (y{0,1}y\in\{0,1\}). Joint pmf:

p(x,y)p(x,y) Y=0Y=0 Y=1Y=1 Row sum = pXp_X
X=0X=0 (ham) 0.60 0.10 0.70
X=1X=1 (spam) 0.05 0.25 0.30
Col sum = pYp_Y 0.65 0.35 1.00

Marginals (edge sums — that's literally why they're written in the margins):

  • pX(1)=0.05+0.25=0.30p_X(1) = 0.05+0.25 = 0.30. Why this step? Summing over both YY values erases the word info.
  • pY(1)=0.10+0.25=0.35p_Y(1) = 0.10+0.25 = 0.35.

Conditional P(spam"free")P(\text{spam}\mid \text{"free"}): pXY(11)=pX,Y(1,1)pY(1)=0.250.350.714.p_{X\mid Y}(1\mid 1) = \frac{p_{X,Y}(1,1)}{p_Y(1)} = \frac{0.25}{0.35}\approx 0.714. Why this step? We restrict to the "free"-column (total 0.35) and ask what fraction is spam.

Independent? Check p(1,1)=?pX(1)pY(1)=0.30×0.35=0.1050.25p(1,1)\overset{?}{=}p_X(1)p_Y(1)=0.30\times0.35=0.105 \ne 0.25. Not equal ⇒ dependent. Good — the word free really does raise spam probability from 0.30 to 0.714.


Worked Example 2 — continuous joint

Let fX,Y(x,y)=4xyf_{X,Y}(x,y) = 4xy on the unit square 0x1, 0y10\le x\le1,\ 0\le y\le1.

Step 1 — valid? Why? A pdf must integrate to 1. 01 ⁣ ⁣014xydxdy=4(12)(12)=1. \int_0^1\!\!\int_0^1 4xy\,dx\,dy = 4\Big(\tfrac12\Big)\Big(\tfrac12\Big)=1.\ \checkmark

Step 2 — marginal of XX: integrate out yy. fX(x)=014xydy=4x12=2x,0x1.f_X(x)=\int_0^1 4xy\,dy = 4x\cdot\tfrac12 = 2x,\quad 0\le x\le1.

Step 3 — conditional of YY given X=xX=x: fYX(yx)=4xy2x=2y.f_{Y\mid X}(y\mid x)=\frac{4xy}{2x}=2y. Why interesting? It doesn't depend on xxXX and YY are independent here. Indeed fX,Y=2x2y=fXfYf_{X,Y}=2x\cdot2y=f_X f_Y. ✔


Common mistakes (Steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine a big grid of boxes counting kids by (favorite fruit) and (favorite sport). The joint is the count in each little box. If you push all the boxes in each row into one pile, you get how many like each fruit no matter the sport — that's the marginal. If you look at only the kids who play football and ask "of these, how many like apples?", you first grab that column then split it into fractions that add to one — that's the conditional. Marginal = squish a direction; conditional = pick a strip and share it out to 100%.


Active recall

How do you get a marginal pX(x)p_X(x) from a joint pX,Yp_{X,Y}?
Sum (or integrate) the joint over all values of the other variable: pX(x)=ypX,Y(x,y)p_X(x)=\sum_y p_{X,Y}(x,y).
Define the conditional pmf pYX(yx)p_{Y\mid X}(y\mid x).
pYX(yx)=pX,Y(x,y)pX(x)p_{Y\mid X}(y\mid x)=\dfrac{p_{X,Y}(x,y)}{p_X(x)} for pX(x)>0p_X(x)>0 — the joint slice re-normalized.
Why must we divide by the marginal when conditioning?
Because the joint slice at X=xX=x sums to pX(x)p_X(x), not 1; dividing renormalizes it to a valid distribution.
State the product/chain rule for the joint.
pX,Y(x,y)=pYX(yx)pX(x)=pXY(xy)pY(y)p_{X,Y}(x,y)=p_{Y\mid X}(y\mid x)\,p_X(x)=p_{X\mid Y}(x\mid y)\,p_Y(y).
When are XX and YY independent (in terms of distributions)?
When pX,Y(x,y)=pX(x)pY(y)p_{X,Y}(x,y)=p_X(x)p_Y(y) for all x,yx,y, equivalently pYX=pYp_{Y\mid X}=p_Y.
Derive Bayes' theorem from the two factorizations of the joint.
Equate pXYpY=pYXpXp_{X\mid Y}p_Y=p_{Y\mid X}p_XpXY(xy)=pYX(yx)pX(x)pY(y)p_{X\mid Y}(x\mid y)=\dfrac{p_{Y\mid X}(y\mid x)p_X(x)}{p_Y(y)}.
Given the spam table, compute P(spam"free")P(\text{spam}\mid\text{"free"}).
0.25/0.350.7140.25/0.35\approx0.714.
True/False: uncorrelated implies independent.
False — independence implies uncorrelated, but not vice versa.

Connections

  • Bayes' theorem — direct consequence of the two joint factorizations.
  • Independence and conditional independence — the factorization condition.
  • Covariance and correlation — weaker summaries of the joint than the full distribution.
  • Naive Bayes classifier — assumes conditional independence of features given the label.
  • Marginalization and the law of total probabilitypY(y)=xpYX(yx)pX(x)p_Y(y)=\sum_x p_{Y\mid X}(y\mid x)p_X(x).
  • Probabilistic graphical models — encode which conditionals factor the joint.
  • Expectation and variance — computed against these distributions.

Concept Map

sum out a variable

slice at X=x

divide by p X

denominator

rearrange

equals joint

two factorings

factorizes then

implies

Joint distribution p X,Y

Marginal p X

Conditional p Y given X

Re-normalize by p X

Chain rule / product rule

Bayes theorem

Independence

Probabilistic ML models

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Socho tumhare paas ek table hai jisme do cheezein saath-saath likhi hain — jaise "email spam hai ya nahi" aur "email me 'free' word hai ya nahi". Har chhoti box ki probability ko joint distribution kehte hain: yeh poori kahani batata hai, dono variables ke bare me sab kuch isi se nikal sakta hai.

Ab agar tum sirf "spam kitna common hai" jaanna chahte ho, chahe word kuch bhi ho, to tum uss row ko poora add kar dete ho — isko marginal kehte hain (naam isliye kyunki yeh table ke kinare, yaani margin me likha aata hai). Aur agar tum bolo "maan lo 'free' word aa gaya, ab spam ki kya chance hai?", to tum sirf uss column ko dekhte ho, phir usko re-scale karte ho taaki total 1 ho jaye — yeh hai conditional. Formula: joint ko marginal se divide karo.

Sabse important trap: P(spamfree)P(\text{spam}\mid\text{free}) aur P(freespam)P(\text{free}\mid\text{spam}) ek nahi hote — inke denominator alag hote hain, isliye kabhi bhi bar ke dono taraf ko swap mat karo. Isi swap ko theek karne ke liye Bayes theorem use hota hai, jo bas joint ko do tareeke se todne se aa jaata hai.

Yeh cheez ML me har jagah hai: Naive Bayes, generative models, graphical models — sab is ek simple idea (slice karo aur normalize karo, ya squish karke bhulo) par khade hain. Ek baar joint–marginal–conditional ka rishta samajh liya, to aadhi probability apne aap clear ho jaati hai — yahi 80/20 hai.

Go deeper — visual, from zero

Test yourself — Probability & Statistics

Connections