Marginal and Conditional Distributions
A marginal distribution is the distribution of one random variable by itself, found from a joint distribution by adding (discrete) or integrating (continuous) over the other variable. A conditional distribution is the distribution of one variable once the other is known: divide the joint probability or density by the marginal of the known variable.
Before this lesson: Joint Probability Distributions and Conditional Probability
Two ways to look at one variable
A joint distribution describes X and Y together. Often you only care about one of them. The marginal distribution of X answers “how does X behave if I ignore Y?” You get it by collapsing the joint distribution onto the x-axis: add across each row of a table, or integrate the joint density over all y.
The conditional distribution of Y given X = x answers a different question: “how does Y behave if I already know X = x?” You keep only the slice of the joint distribution where X = x, then rescale it so it adds or integrates to 1. The rescaling factor is the marginal probability or density of X at x.
The names come from tables. When you write row and column totals in the margins of a joint probability table, those totals are the marginal distributions.
Marginal and conditional distribution formulas
For discrete X and Y with joint PMF p(x, y), the marginal PMFs are
p_X(x) = \sum_y p(x, y), \qquad p_Y(y) = \sum_x p(x, y)
For continuous X and Y with joint density f(x, y), the marginal densities are
f_X(x) = \int_{-\infty}^{\infty} f(x, y)\,dy, \qquad f_Y(y) = \int_{-\infty}^{\infty} f(x, y)\,dxThe conditional PMF and conditional density of Y given X = x, defined wherever the denominator is positive, are
p_{Y|X}(y \mid x) = \dfrac{p(x, y)}{p_X(x)}, \qquad f_{Y|X}(y \mid x) = \dfrac{f(x, y)}{f_X(x)}Swap the roles of x and y to condition on Y instead. Rearranging gives the multiplication rule f(x, y) = f_X(x) f_{Y|X}(y | x), which builds a joint density from a marginal and a conditional.
Steps
- Sketch the region where the joint density is positive (or list the table cells).
- For the marginal of X, fix x and integrate out y over the vertical slice at that x. For the marginal of Y, fix y and integrate out x over the horizontal slice.
- Check that each marginal adds or integrates to 1.
- For a conditional, divide the joint by the marginal of the known variable, and state the range of the other variable.
- Find conditional probabilities by adding or integrating the conditional distribution over the event.
Marginal and conditional distribution examples
Example 1: Marginal and conditional distributions from a table (word problem)
A store tracks X, the number of laptops sold in an hour, and Y, the number of tablets sold. This is the joint table from the joint probability distributions lesson, with the margins filled in. Find the marginal distributions, the conditional distribution of Y given X = 2, and P(X = 2 | Y = 1).
| y = 0 | y = 1 | Marginal of X | |
|---|---|---|---|
| x = 0 | 0.20 | 0.10 | 0.30 |
| x = 1 | 0.25 | 0.15 | 0.40 |
| x = 2 | 0.20 | 0.10 | 0.30 |
| Marginal of Y | 0.65 | 0.35 | 1 |
p_X(0) = 0.20 + 0.10 = 0.30
Add across the x = 0 row.
p_X(1) = 0.25 + 0.15 = 0.40
Add across the x = 1 row.
p_X(2) = 0.20 + 0.10 = 0.30
Add across the x = 2 row.
0.30 + 0.40 + 0.30 = 1
Check: the marginal of X adds to 1.
p_Y(0) = 0.20 + 0.25 + 0.20 = 0.65
Add down the y = 0 column.
p_Y(1) = 0.10 + 0.15 + 0.10 = 0.35
Add down the y = 1 column.
p_{Y|X}(0 \mid 2) = \dfrac{p(2, 0)}{p_X(2)} = \dfrac{0.20}{0.30} = \dfrac{2}{3}Divide the cell by the row total (see conditional probability).
p_{Y|X}(1 \mid 2) = \dfrac{p(2, 1)}{p_X(2)} = \dfrac{0.10}{0.30} = \dfrac{1}{3}Same row, other cell.
P(X = 2 \mid Y = 1) = \dfrac{p(2, 1)}{p_Y(1)} = \dfrac{0.10}{0.35} = \dfrac{2}{7}Now the given variable is Y, so divide by the column total.
Answer: X takes 0, 1, 2 with probabilities 0.30, 0.40, 0.30; Y takes 0, 1 with probabilities 0.65, 0.35. Given two laptops sold, Y is 0 or 1 with probabilities 2/3 and 1/3. Given one tablet sold, the chance of two laptop sales is 2/7, about 0.286.
Example 2: Marginals of a joint PMF formula
X and Y have joint PMF p(x, y) = (x + y)/21 for x = 1, 2 and y = 1, 2, 3. Find both marginal PMFs and the conditional PMF of Y given X = 2.
p_X(1) = \dfrac{2 + 3 + 4}{21} = \dfrac{9}{21} = \dfrac{3}{7}Add p(1, y) over y = 1, 2, 3.
p_X(2) = \dfrac{3 + 4 + 5}{21} = \dfrac{12}{21} = \dfrac{4}{7}Add p(2, y) over y = 1, 2, 3.
p_Y(y) = \dfrac{(1 + y) + (2 + y)}{21} = \dfrac{3 + 2y}{21}Add p(x, y) over x = 1, 2.
p_Y(1) = \dfrac{5}{21},\ p_Y(2) = \dfrac{7}{21} = \dfrac{1}{3},\ p_Y(3) = \dfrac{9}{21} = \dfrac{3}{7}Substitute y = 1, 2, 3.
\dfrac{5}{21} + \dfrac{7}{21} + \dfrac{9}{21} = 1Check: the marginal of Y adds to 1.
p_{Y|X}(y \mid 2) = \dfrac{(2 + y)/21}{12/21} = \dfrac{2 + y}{12}Divide by p_X(2); the 21s cancel.
p_{Y|X}(1 \mid 2) = \dfrac{1}{4},\ p_{Y|X}(2 \mid 2) = \dfrac{1}{3},\ p_{Y|X}(3 \mid 2) = \dfrac{5}{12}Substitute y = 1, 2, 3 and simplify.
Answer: p_X(1) = 3/7, p_X(2) = 4/7; p_Y(y) = (3 + 2y)/21; given X = 2, Y is 1, 2, 3 with probabilities 1/4, 1/3, 5/12.
Example 3: Marginal and conditional densities on a square
X and Y have joint density f(x, y) = (2/3)(x + 2y) on the unit square 0 ≤ x ≤ 1, 0 ≤ y ≤ 1. Find f_X(x), f_Y(y), the conditional density of Y given X = 1/2, and P(Y ≤ 1/2 | X = 1/2).
f_X(x) = \int_0^1 \tfrac{2}{3}(x + 2y)\,dyIntegrate out y over its full range for this x.
f_X(x) = \tfrac{2}{3}\Big[xy + y^2\Big]_0^1 = \tfrac{2}{3}(x + 1), \quad 0 \le x \le 1Antiderivative in y with x held fixed, then evaluate.
\int_0^1 \tfrac{2}{3}(x + 1)\,dx = \tfrac{2}{3} \cdot \tfrac{3}{2} = 1Check: the marginal integrates to 1.
f_Y(y) = \int_0^1 \tfrac{2}{3}(x + 2y)\,dx = \tfrac{2}{3}\left(\tfrac{1}{2} + 2y\right) = \tfrac{1}{3} + \tfrac{4}{3}yIntegrate out x instead.
f_{Y|X}(y \mid x) = \dfrac{\tfrac{2}{3}(x + 2y)}{\tfrac{2}{3}(x + 1)} = \dfrac{x + 2y}{x + 1}, \quad 0 \le y \le 1Divide the joint density by f_X(x); the 2/3 cancels.
f_{Y|X}\left(y \mid \tfrac{1}{2}\right) = \dfrac{\tfrac{1}{2} + 2y}{\tfrac{3}{2}} = \dfrac{1 + 4y}{3}Substitute x = 1/2, then multiply top and bottom by 2.
P\left(Y \le \tfrac{1}{2} \mid X = \tfrac{1}{2}\right) = \int_0^{1/2} \dfrac{1 + 4y}{3}\,dyIntegrate the conditional density over the event.
P\left(Y \le \tfrac{1}{2} \mid X = \tfrac{1}{2}\right) = \dfrac{1}{3}\Big[y + 2y^2\Big]_0^{1/2} = \dfrac{1}{3}\left(\dfrac{1}{2} + \dfrac{1}{2}\right) = \dfrac{1}{3}Evaluate.
Answer: f_X(x) = (2/3)(x + 1), f_Y(y) = 1/3 + (4/3)y, f_{Y|X}(y | 1/2) = (1 + 4y)/3 on [0, 1], and the conditional probability is 1/3. Without the condition, P(Y ≤ 1/2) = 1/6 + 1/6 = 1/3 as well, but for other values of x the answer changes.
Example 4: Marginals on a triangle
X and Y have joint density f(x, y) = 8xy on the triangle 0 ≤ y ≤ x ≤ 1. Find both marginal densities, the conditional density of Y given X = x, and P(Y ≤ 0.25 | X = 0.5).
\int_0^1\int_0^x 8xy\,dy\,dx = \int_0^1 4x^3\,dx = 1
Check that f is a valid joint density (see double integrals over general regions).
f_X(x) = \int_0^x 8xy\,dy = 4xy^2\Big|_0^x = 4x^3, \quad 0 \le x \le 1
For fixed x, y runs from 0 to x (vertical slice).
f_Y(y) = \int_y^1 8xy\,dx = 4x^2y\Big|_y^1 = 4y - 4y^3, \quad 0 \le y \le 1
For fixed y, x runs from y to 1 (horizontal slice).
\int_0^1 (4y - 4y^3)\,dy = 2 - 1 = 1
Check: the marginal of Y integrates to 1.
f_{Y|X}(y \mid x) = \dfrac{8xy}{4x^3} = \dfrac{2y}{x^2}, \quad 0 \le y \le xDivide the joint density by f_X(x); keep the range of y.
f_{Y|X}(y \mid 0.5) = \dfrac{2y}{0.25} = 8y, \quad 0 \le y \le 0.5Substitute x = 0.5.
P(Y \le 0.25 \mid X = 0.5) = \int_0^{0.25} 8y\,dy = 4y^2\Big|_0^{0.25} = 0.25Integrate over the event and evaluate.
Answer: f_X(x) = 4x³ on [0, 1], f_Y(y) = 4y − 4y³ on [0, 1], f_{Y|X}(y | x) = 2y/x² on [0, x], and P(Y ≤ 0.25 | X = 0.5) = 0.25.
Example 5: Breaking a stick twice (word problem)
A 1-meter stick is broken at a point chosen uniformly at random. The left piece has length X. That piece is broken again at a uniform random point, and Y is the length of its left part. Find the joint density of X and Y, the marginal density of Y, and P(Y > 1/2).
f_X(x) = 1, \quad 0 \lt x \lt 1
The first break is uniform on (0, 1) (see uniform distribution).
f_{Y|X}(y \mid x) = \dfrac{1}{x}, \quad 0 \lt y \lt xGiven X = x, the second break is uniform on (0, x).
f(x, y) = f_X(x)\,f_{Y|X}(y \mid x) = \dfrac{1}{x}, \quad 0 \lt y \lt x \lt 1Multiplication rule: joint = marginal × conditional.
f_Y(y) = \int_y^1 \dfrac{1}{x}\,dx = \ln 1 - \ln y = -\ln y, \quad 0 \lt y \lt 1Integrate out x; for fixed y, x runs from y to 1 (see integrals that give natural logarithms).
\int (-\ln y)\,dy = y - y\ln y + C
Antiderivative by integration by parts with u = −ln y and dv = dy.
P\left(Y \gt \tfrac{1}{2}\right) = \Big[y - y\ln y\Big]_{1/2}^{1} = 1 - \left(\tfrac{1}{2} - \tfrac{1}{2}\ln\tfrac{1}{2}\right)Evaluate from 1/2 to 1; ln 1 = 0.
P\left(Y \gt \tfrac{1}{2}\right) = \tfrac{1}{2} - \tfrac{1}{2}\ln 2 \approx 0.1534Simplify with ln(1/2) = −ln 2.
Answer: f(x, y) = 1/x on 0 < y < x < 1, f_Y(y) = −ln y on (0, 1), and P(Y > 1/2) ≈ 0.153. The density of Y is large near 0, because two breaks tend to leave a short piece.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Integrating out the wrong variable | Finding f_X(x) as \int f(x, y)\,dx | To get the marginal of X, integrate out y: \int f(x, y)\,dy. |
| Using square limits on a triangle | f_X(x) = \int_0^1 8xy\,dy = 4x in Example 4 | Read the y-limits from the region: y runs from 0 to x, so f_X(x) = 4x³. |
| Dividing by the wrong marginal | f_{Y|X}(y \mid x) = f(x, y)/f_Y(y) | Divide by the marginal of the variable you are given. |
| Dropping the range of a conditional | Writing 2y/x² for all 0 ≤ y ≤ 1 | State where it is positive: 0 ≤ y ≤ x. |
| An x left in a marginal of Y | An answer for f_Y(y) that still contains x | A marginal of Y depends on y only; check the limits of integration. |
Related ideas
Marginal and conditional relative frequencies
In statistics, a two-way table of counts has marginal and conditional relative frequencies. They are the data versions of the marginal and conditional distributions in Example 1.
The multiplication rule and Bayes’ theorem
The rule f(x, y) = f_X(x) f_{Y|X}(y | x) is the continuous version of P(A and B) = P(A)P(B | A). Combining it with a marginal gives a density form of Bayes’ theorem: f_{X|Y}(x | y) = f_X(x) f_{Y|X}(y | x) / f_Y(y).
When the condition does not matter
In practice problem 9, the conditional density of Y given X = x is the same as the marginal of Y for every x. Then knowing X tells you nothing about Y. The next lesson, Independent Random Variables, makes this precise.
Practice problems
- Using the table in Example 1, find P(Y = 0).
- Using the table in Example 1, find the conditional distribution of X given Y = 0.
- p(x, y) = xy/9 for x = 1, 2 and y = 1, 2. Find the marginal PMF of X.
- For the PMF in problem 3, find the conditional PMF of Y given X = 2.
- f(x, y) = 4xy on the unit square. Find f_X(x) and f_Y(y).
- f(x, y) = x + y on the unit square. Find f_X(x).
- For the density in problem 6, find f_{Y|X}(y | 0) and P(Y ≤ 1/2 | X = 0).
- For the density in Example 4, find f_{X|Y}(x | y) and P(X ≤ 3/4 | Y = 1/2).
- f(x, y) = 6e^(−2x−3y) for x ≥ 0 and y ≥ 0. Find both marginals and f_{Y|X}(y | x).
- In Example 5, find P(Y ≤ 1/4).
Show answers
1.
p_Y(0) = 0.20 + 0.25 + 0.20 = 0.65
Add down the y = 0 column.
Answer: 0.65
2.
P(X = 0 \mid Y = 0) = \dfrac{0.20}{0.65} = \dfrac{4}{13}Divide each cell in the column by 0.65.
P(X = 1 \mid Y = 0) = \dfrac{0.25}{0.65} = \dfrac{5}{13}Next cell.
P(X = 2 \mid Y = 0) = \dfrac{0.20}{0.65} = \dfrac{4}{13}Last cell; 4 + 5 + 4 = 13, so they add to 1.
Answer: 4/13, 5/13, 4/13 for x = 0, 1, 2
3.
p_X(1) = \dfrac{1 \cdot 1 + 1 \cdot 2}{9} = \dfrac{3}{9} = \dfrac{1}{3}Add over y = 1, 2 with x = 1.
p_X(2) = \dfrac{2 \cdot 1 + 2 \cdot 2}{9} = \dfrac{6}{9} = \dfrac{2}{3}Add over y with x = 2.
Answer: p_X(1) = 1/3, p_X(2) = 2/3
4.
p_{Y|X}(1 \mid 2) = \dfrac{2/9}{2/3} = \dfrac{1}{3}Divide p(2, 1) by p_X(2).
p_{Y|X}(2 \mid 2) = \dfrac{4/9}{2/3} = \dfrac{2}{3}Divide p(2, 2) by p_X(2).
Answer: 1/3 and 2/3 for y = 1, 2
5.
f_X(x) = \int_0^1 4xy\,dy = 2xy^2\Big|_0^1 = 2x
Integrate out y.
f_Y(y) = \int_0^1 4xy\,dx = 2x^2y\Big|_0^1 = 2y
Integrate out x.
Answer: f_X(x) = 2x and f_Y(y) = 2y on [0, 1]
6.
f_X(x) = \int_0^1 (x + y)\,dy = xy + \dfrac{y^2}{2}\Big|_0^1 = x + \dfrac{1}{2}Integrate out y.
Answer: f_X(x) = x + 1/2 on [0, 1]
7.
f_{Y|X}(y \mid 0) = \dfrac{0 + y}{0 + 1/2} = 2yDivide f(0, y) by f_X(0).
P\left(Y \le \tfrac{1}{2} \mid X = 0\right) = \int_0^{1/2} 2y\,dy = y^2\Big|_0^{1/2} = \dfrac{1}{4}Integrate over the event.
Answer: 2y on [0, 1]; 1/4
8.
f_{X|Y}(x \mid y) = \dfrac{8xy}{4y - 4y^3} = \dfrac{2x}{1 - y^2}, \quad y \le x \le 1Divide by f_Y(y) and cancel 4y.
f_{X|Y}\left(x \mid \tfrac{1}{2}\right) = \dfrac{2x}{3/4} = \dfrac{8x}{3}, \quad \tfrac{1}{2} \le x \le 1Substitute y = 1/2.
P\left(X \le \tfrac{3}{4} \mid Y = \tfrac{1}{2}\right) = \int_{1/2}^{3/4} \dfrac{8x}{3}\,dx = \dfrac{4}{3}\left(\dfrac{9}{16} - \dfrac{4}{16}\right) = \dfrac{5}{12}Integrate from 1/2 (not 0) to 3/4.
Answer: 2x/(1 − y²) on [y, 1]; 5/12
9.
f_X(x) = \int_0^\infty 6e^{-2x-3y}\,dy = 6e^{-2x} \cdot \dfrac{1}{3} = 2e^{-2x}Integrate out y (see improper integrals).
f_Y(y) = \int_0^\infty 6e^{-2x-3y}\,dx = 6e^{-3y} \cdot \dfrac{1}{2} = 3e^{-3y}Integrate out x.
f_{Y|X}(y \mid x) = \dfrac{6e^{-2x-3y}}{2e^{-2x}} = 3e^{-3y}Divide; e^(−2x) cancels.
Answer: f_X(x) = 2e^(−2x), f_Y(y) = 3e^(−3y) (both exponential), and f_{Y|X}(y | x) = 3e^(−3y), which does not depend on x
10.
P\left(Y \le \tfrac{1}{4}\right) = \Big[y - y\ln y\Big]_0^{1/4}Integrate −ln y from 0 to 1/4 with the antiderivative from Example 5.
\lim_{y \to 0^+} y\ln y = 0The lower limit gives 0 (see L’Hôpital’s rule).
P\left(Y \le \tfrac{1}{4}\right) = \tfrac{1}{4} - \tfrac{1}{4}\ln\tfrac{1}{4} = \dfrac{1 + \ln 4}{4} \approx 0.5966Evaluate and use ln(1/4) = −ln 4.
Answer: (1 + ln 4)/4, about 0.597
Marginal and conditional distribution FAQ
What is a marginal distribution?
It is the distribution of one variable on its own, found from a joint distribution. Add the joint PMF over the other variable, or integrate the joint density over it.
How do you find a conditional distribution?
Divide the joint PMF or density by the marginal of the variable you are given: f_{Y|X}(y | x) = f(x, y)/f_X(x). Then state the range of y where it is positive.
What is the difference between marginal and conditional distributions?
A marginal distribution ignores the other variable completely. A conditional distribution describes one variable after the value of the other is known.
Does a conditional density integrate to 1?
Yes. For each fixed x with f_X(x) > 0, the conditional density of Y integrates to 1 over y, so it is a true density.
Summary
- Marginal of X: add the joint PMF over y, or integrate the joint density over y.
- Read the limits of integration from the region; on a triangle they depend on the other variable.
- Conditional of Y given X = x: joint divided by f_X(x), with its range stated.
- Multiplication rule: f(x, y) = f_X(x) f_{Y|X}(y | x).
- Every marginal and conditional distribution adds or integrates to 1.
Previous lesson: Joint Probability Distributions
Next lesson: Independent Random Variables
Back to the Probability Theory Index