Skip to content

Bayes and Total Probability: Four Forms

Theorem

Write mX,mYm_X,m_Y for marginal mass or density functions and mX∣Y,mY∣Xm_{X\mid Y},m_{Y\mid X} for the corresponding conditional functions. Where the denominator is positive and finite,

mX∣Y(x∣y)=mY∣X(y∣x)mX(x)mY(y).m_{X\mid Y}(x\mid y)=\frac{m_{Y\mid X}(y\mid x)m_X(x)}{m_Y(y)}.

The four total-probability forms are:

XX YY Marginalization over YY
Discrete Discrete pX(x)=∑ypX∣Y(x∣y)pY(y)\displaystyle p_X(x)=\sum_y p_{X\mid Y}(x\mid y)p_Y(y)
Continuous Continuous fX(x)=∫fX∣Y(x∣y)fY(y) dyf_X(x)=\int f_{X\mid Y}(x\mid y)f_Y(y)\,\mathrm{d}y
Discrete Continuous pX(x)=∫pX∣Y(x∣y)fY(y) dyp_X(x)=\int p_{X\mid Y}(x\mid y)f_Y(y)\,\mathrm{d}y
Continuous Discrete fX(x)=∑yfX∣Y(x∣y)pY(y)\displaystyle f_X(x)=\sum_y f_{X\mid Y}(x\mid y)p_Y(y)

Use appropriate conditional mass or density versions; continuity of marginals alone does not establish a joint density.

For discrete conditional laws use a Conditional Probability Mass Function; for conditional laws with densities use a Conditional Probability Density Function. Both express Conditional Probability, but density conditioning at a point is not division by the probability of that point.


Interpretation

The same factorization works whether each variable is discrete or continuous: sum over discrete values and integrate over continuous ones. In every case "joint == conditional ×\times marginal" produces both Bayes' rule and the law of total probability, with mm standing for a PMF or a density as the type of each variable requires.

Two conditional densities of Y given H = 0 and H = 1, and the posterior probability that H = 1 as a decreasing curve that passes 1/2 at y = ln 2, where the two densities are equal.

In this example, H∼Bern⁡(12)H\sim\operatorname{Bern}(\tfrac{1}{2}) is discrete, while YY has conditional densities fY∣H(y∣0)=e−yf_{Y\mid H}(y\mid0)=\mathrm{e}^{-y} and fY∣H(y∣1)=2e−2yf_{Y\mid H}(y\mid1)=2\mathrm{e}^{-2y} for y>0y>0. Summing over HH gives fY(y)=12e−y+12⋅2e−2yf_Y(y)=\tfrac{1}{2}\mathrm{e}^{-y}+\tfrac{1}{2}\cdot2\mathrm{e}^{-2y}, and Bayes' rule gives P(H=1∣Y=y)=2/(ey+2)\mathbb{P}(H=1\mid Y=y)=2/(\mathrm{e}^y+2), the red curve. It starts at 23\tfrac{2}{3} for yy near 00 and decreases; at y=ln⁡2y=\ln2, where the two densities are equal, the posterior equals the prior 12\tfrac{1}{2}. Small observations favour H=1H=1, whose density puts more weight near 00.

To read the table, note that the variable summed or integrated out is YY, so the operation follows the type of YY. The left-hand side follows the type of XX: a PMF pXp_X if XX is discrete, a density fXf_X if XX is continuous. In the mixed forms a probability and a density appear in one formula. Heuristically, fY(y)f_Y(y) stands for P(y<Y≤y+h)/h\mathbb{P}(y<Y\le y+h)/h for a small h>0h>0, and the width hh cancels between numerator and denominator.

All four forms extend the law of total probability and Bayes' rule for events. The purely continuous forms are treated separately in the continuous law of total probability and the continuous Bayes rule.


Key Results

  • When XX is discrete and YY continuous, pX∣Y(x∣y)=fY∣X(y∣x)pX(x)/fY(y)p_{X\mid Y}(x\mid y)=f_{Y\mid X}(y\mid x)p_X(x)/f_Y(y) and fY(y)=∑xfY∣X(y∣x)pX(x)\displaystyle f_Y(y)=\sum_xf_{Y\mid X}(y\mid x)p_X(x).
  • When XX is continuous and YY discrete, fX∣Y(x∣y)=pY∣X(y∣x)fX(x)/pY(y)f_{X\mid Y}(x\mid y)=p_{Y\mid X}(y\mid x)f_X(x)/p_Y(y) and pY(y)=∫pY∣X(y∣x)fX(x) dxp_Y(y)=\int p_{Y\mid X}(y\mid x)f_X(x)\,\mathrm{d}x.

Examples

  • If Y∼Unif⁡(0,1)Y\sim\operatorname{Unif}(0,1) and X∣Y=y∼Bern⁡(y)X\mid Y=y\sim\operatorname{Bern}(y), then fY∣X(y∣1)=2yf_{Y\mid X}(y\mid1)=2y on (0,1)(0,1).
  • If H∼Bern⁡(1/2)H\sim\operatorname{Bern}(1/2), Y∣H=0∼Exp⁡(1)Y\mid H=0\sim\operatorname{Exp}(1), and Y∣H=1∼Exp⁡(2)Y\mid H=1\sim\operatorname{Exp}(2), then P(H=1∣Y=y)=2e−2y/(e−y+2e−2y)\mathbb{P}(H=1\mid Y=y)=2\mathrm{e}^{-2y}/(\mathrm{e}^{-y}+2\mathrm{e}^{-2y}) for y>0y>0.

Prerequisites

Sources

Symbols: integral, sum

Last updated: 20 October 2026 03:02