Lesson 1 of 6
Joint, marginal, and conditional laws
A joint distribution is a complete map of how variables behave together; marginals and conditionals are different views of that map.
Core lesson · about 5 minutes · 3 guided parts
A lunch table records both drink and snack. Row totals answer drink questions; a single row answers snack questions after the drink is known.
Your learning route
Build the idea one piece at a time
- Marginalize and condition
- Conditional expectation and dependence
- Use total expectation and variance in a mixture
Marginalize and condition
To forget a variable, add or integrate it out. To learn its value, slice and renormalize.
For discrete variables, pX(x)=Σ over y of pXY(x,y). For continuous variables, replace the sum by an integral.
Conditioning gives p(x|y)=p(x,y)/pY(y) when the denominator is positive.
The product rule p(x,y)=p(x|y)p(y) factors a joint law in either direction.
A joint table assigns probability to every pair. Summing across a row or column forgets the other coordinate and creates a marginal; selecting one row or column and renormalizing creates a conditional distribution.
Marginalization adds mutually exclusive ways to obtain x. Conditioning divides the desired joint cell by the total mass in the known slice so the new reduced world sums to one.
The product rule rebuilds the joint from a marginal and a conditional. This factorization is the foundation of probability trees, graphical models, sequence models, and Bayesian updates.
pX(x)=Σ over y of p(x,y); p(x|y)=p(x,y)/pY(y)Worked example
A joint table has p(0,0)=0.2, p(0,1)=0.3, p(1,0)=0.1, p(1,1)=0.4. Find P(X=1) and P(X=1|Y=1).
- Marginalize over Y: P(X=1)=0.1+0.4=0.5.
- P(Y=1)=0.3+0.4=0.7.
- Condition: 0.4/0.7=4/7.
Answer: P(X=1)=0.5; P(X=1|Y=1)=4/7
Conditional expectation and dependence
E[X|Y] is the best mean-squared prediction of X after seeing Y.
Conditional expectation is itself a random variable: its value changes with Y.
The tower property E[E[X|Y]]=E[X] says that averaging all conditional means restores the overall mean.
The law of total variance splits uncertainty into average remaining noise plus variation in conditional means.
Conditional expectation is a function of the information Y: each possible y gets its own best mean-squared prediction of X. Averaging those predictions over Y returns the unconditional mean by the tower property.
Total variance splits uncertainty into noise remaining inside Y-groups and variation between their conditional means. The pieces answer whether uncertainty comes mainly from unexplained individual variation or predictable group differences.
A demand forecast conditions orders on weekday and weather, averages within each state, then combines states using their forecast probabilities. This works because conditional expectation uses available information optimally under squared error, while omitted events and distribution shift still limit accuracy.
Var(X)=E[Var(X|Y)]+Var(E[X|Y])Worked example
Y is 0 or 1 with equal chance. Given Y, E[X|Y]=2+3Y. Find E[X].
- Use the tower property E[X]=E[E[X|Y]].
- E[Y]=0.5, so E[2+3Y]=2+3(0.5).
- The unconditional mean is 3.5.
Answer: 3.5
Practical deep dive for this lesson
Use total expectation and variance in a mixture
Condition on a meaningful group, calculate within each group, then combine to reveal both internal noise and differences between groups.
Suppose demand depends on weather. E[X|weather] gives each weather-specific forecast; weighting those means by weather probabilities gives overall expected demand through the tower property.
Total variance adds average within-weather variance and variance among weather-specific means. Even perfectly stable demand inside each weather state can have large overall variance when the state means differ.
This decomposition guides action: better within-state models reduce the first component, while better prediction of the state helps explain the second. Missing states or changing conditional laws still cause forecast error.
Var(X)=within-state variance+between-state varianceWorked example
Two equally likely states have means 10 and 14 and conditional variances 1 and 3. Find E[X] and Var(X).
- Average conditional means: E[X]=(10+14)/2=12.
- Average conditional variances: (1+3)/2=2.
- Variance of conditional means around 12 is [(10−12)²+(14−12)²]/2=4.
- Add components: Var(X)=2+4=6.
Answer: E[X]=12 and Var(X)=6
Check your picture
If E[X|Y]=Y² and E[Y²]=5, what is E[X]?
Reveal answer
5
This lesson versus the whole chapter
Your topic-specific practical example is above.
The final lesson collects five longer chapter-wide workflows for machine learning, LLMs, trading, physics, and everyday decisions.
Formula shelf
Symbols with meaning
p(x)=Σ over y of p(x,y)Remove an unobserved variable by summing its joint mass.
E[E[X|Y]]=E[X]Averaging conditional means restores the overall mean.
Var(X)=E Var(X|Y)+Var E(X|Y)Split within-group and between-group uncertainty.
fY(y)=fX(g⁻¹(y)) × |d(g⁻¹(y))/dy|Preserve probability when transforming a density.
P(|X−μ|≥kσ)≤1/k²A distribution-free finite-variance tail bound.
p(θ|D)∝p(D|θ)p(θ)Combine prior and likelihood.
p(x*|D)=∫p(x*|θ)p(θ|D)dθAverage prediction across parameter uncertainty.
the action a minimizing E[L(a,θ)|D]Choose the action with least posterior expected harm.
posterior precision=data precision+population precisionBalance group evidence with population-level evidence.
Eq[log p(D,z)−log q(z)]Objective whose evidence gap is reverse KL to the posterior.
Before moving on
You are ready when you can…
- Move among joint, marginal, and conditional distributions
- Transform variables and apply honest tail bounds
- Build and critique a Bayesian model
- Perform conjugate updates and posterior prediction
- Use hierarchical partial pooling while checking exchangeability and hyperprior assumptions
- Explain ordinary and self-normalized importance sampling, MCMC dependence, and diagnostics
- Derive the ELBO identity and name variational approximation, optimization, and model errors