SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.5.1 Joint, marginal and conditional distributionsConcept · 30 min
      2. 5.5.2 Covariance, correlation and independenceConcept · 35 min
      3. 5.5.3 The multivariate normal distributionConcept · 35 min
      4. 5.5.4 Practice set: joint distributionsPractice set · 25 min
      5. 5.5.5 Case study: portfolio risk and conditional expectationCase study · 35 min

Level 5, Probability and statistics 5.5 Joint distributions Lesson 1 of 5

ConceptLesson 5.5.1 in Level 5, Probability and statistics. About 30 minutes.

Joint, marginal and conditional distributions

Two random variables on one experiment

A single experiment can give several numbers at once. Toss three fair coins. Let XX count the heads in the first two tosses, and YY the heads in the last two.

The middle coin counts in both, so XX and YY are linked.

Each of the 8 equally likely outcomes (lesson 5.1.1) gives one pair (x,y)(x, y). Tails, heads, heads gives X=1X = 1 and Y=2Y = 2; heads, heads, heads gives X=2X = 2 and Y=2Y = 2. Counting the outcomes for each pair gives the joint probability mass function pX,Y(x,y)=P(X=x and Y=y)p_{X,Y}(x, y) = P(X = x \text{ and } Y = y), in eighths:

y=0y = 0y=1y = 1y=2y = 2
x=0x = 01/81/80
x=1x = 11/82/81/8
x=2x = 201/81/8

Row xx and column yy hold P(X=x,Y=y)P(X = x, Y = y); the comma reads "and". The pair (0,2)(0, 2) cannot happen: no heads in the first two tosses leaves at most one head in the last two.

Rule: Joint pmf

pX,Y(x,y)=P(X=x, Y=y)pX,Y(x,y)≥0∑x∑ypX,Y(x,y)=1\begin{gathered} p_{X,Y}(x, y) = P(X = x,\ Y = y) \\[4pt] p_{X,Y}(x, y) \ge 0 \\[4pt] \textstyle\sum_x \sum_y p_{X,Y}(x, y) = 1 \end{gathered}

One entry for every pair of values. The probability of any statement about both variables is the sum of the cells where it holds.

Three events read off the table:

  • P(X=Y)P(X = Y): the diagonal, 1+2+18=12\frac{1 + 2 + 1}{8} = \frac{1}{2}.
  • P(X>Y)P(X > Y): the cells below the diagonal, 1+0+18=14\frac{1 + 0 + 1}{8} = \frac{1}{4}.
  • P(X+Y≥3)P(X + Y \ge 3): the cells (1,2)(1, 2), (2,1)(2, 1) and (2,2)(2, 2), 38\frac{3}{8}.

Try it

The cell lists the 8 outcomes with itertools.product, adds 18\frac{1}{8} to the cell of each, and prints the table in eighths. Fraction keeps the arithmetic exact.

Then it simulates 100,000 tosses of three coins with a fixed seed and prints the share of each cell, times 8. In this one seeded run every entry is within 0.02 of the exact count.

⌘/Ctrl + Enter runs the cell

Marginal distributions

The distribution of XX alone sits in the table too. X=1X = 1 happens in three cells, so P(X=1)=18+28+18=12P(X = 1) = \frac{1}{8} + \frac{2}{8} + \frac{1}{8} = \frac{1}{2}.

Adding each row gives pXp_X, and adding each column gives pYp_Y. Written in the margins of the table, they are called the marginal distributions.

y=0y = 0y=1y = 1y=2y = 2pX(x)p_X(x)
x=0x = 01/81/801/4
x=1x = 11/82/81/81/2
x=2x = 201/81/81/4
pY(y)p_Y(y)1/41/21/41

Both are binomial with n=2n = 2 and p=12p = \frac{1}{2} (lesson 5.2.2), as two tosses each should be.

Rule: Marginal pmf

pX(x)=∑ypX,Y(x,y)pY(y)=∑xpX,Y(x,y)\begin{gathered} p_X(x) = \textstyle\sum_y p_{X,Y}(x, y) \\[4pt] p_Y(y) = \textstyle\sum_x p_{X,Y}(x, y) \end{gathered}

Add over every value of the other variable: across a row for XX, down a column for YY. Each marginal adds up to 1.

The marginals do not fix the joint. Count YY on two new coins instead, so the four tosses share nothing. The marginals stay 14,12,14\frac{1}{4}, \frac{1}{2}, \frac{1}{4}, but every cell becomes a product: P(X=0,Y=2)=14⋅14=116P(X = 0, Y = 2) = \frac{1}{4} \cdot \frac{1}{4} = \frac{1}{16} instead of 0.

Then P(X=Y)=38P(X = Y) = \frac{3}{8}, not 12\frac{1}{2}. Two variables need their joint distribution, not just one distribution each.

Conditional distributions

Suppose you learn that X=0X = 0: the first two tosses were tails. Only the row x=0x = 0 is still possible, so the sample space shrinks to it, as in lesson 5.1.3. Its cells, 18\frac{1}{8}, 18\frac{1}{8} and 0, add up to pX(0)=14p_X(0) = \frac{1}{4}; divided by that total, they become probabilities again: 12\frac{1}{2}, 12\frac{1}{2} and 0.

Rule: Conditional pmf

pY∣X(y∣x)=pX,Y(x,y)pX(x)for pX(x)>0\begin{gathered} p_{Y \mid X}(y \mid x) = \frac{p_{X,Y}(x, y)}{p_X(x)} \\[4pt] \text{for } p_X(x) > 0 \end{gathered}

The row of xx divided by its own total. It is the distribution of YY once you know that X=xX = x, and it adds up to 1 over yy. Given a value with pX(x)=0p_X(x) = 0, it is not defined.

Each conditional distribution has a mean, the conditional mean E[Y∣X=x]=∑yy pY∣X(y∣x)\mathbb{E}[Y \mid X = x] = \sum_y y\,p_{Y \mid X}(y \mid x) (lesson 5.3.1):

giveny=0y = 0y=1y = 1y=2y = 2E[Y∣X=x]\mathbb{E}[Y \mid X = x]
X=0X = 01/21/200.5
X=1X = 11/41/21/41
X=2X = 201/21/21.5

Knowing XX moves YY: each extra head among the first two tosses raises the expected YY by 0.5. Weighting the three conditional means by pXp_X gives back E[Y]=14(0.5)+12(1)+14(1.5)=1\mathbb{E}[Y] = \frac{1}{4}(0.5) + \frac{1}{2}(1) + \frac{1}{4}(1.5) = 1, the law of total probability of lesson 5.1.3 applied to means. Case study 5.5.5 uses conditional means of asset returns.

Conditioning the other way divides by a column total instead. P(Y=2∣X=1)=1/81/2=14P(Y = 2 \mid X = 1) = \frac{1/8}{1/2} = \frac{1}{4}, but P(X=1∣Y=2)=1/81/4=12P(X = 1 \mid Y = 2) = \frac{1/8}{1/4} = \frac{1}{2}.

Try it

The first lines divide each row of the table by its total and print the conditional distribution and mean for each xx.

The loop repeats it on the seeded simulation: among the tosses with X=xX = x, the share of each value of YY and their average. They land within 0.005 of the exact table.

⌘/Ctrl + Enter runs the cell

Joint densities

Two continuous random variables have a joint density fX,Y(x,y)f_{X,Y}(x, y): a surface over the plane, never negative, with volume 1 under it. The probability that the pair lands in a region RR is the volume over RR, a double integral (lesson 4.7.1). A joint density is a probability per unit area: per unit of xx times unit of yy.

Case study 4.7.5 met one joint density, for two normal returns. Here is a simpler one: fX,Y(x,y)=x+yf_{X,Y}(x, y) = x + y on the unit square 0≤x≤10 \le x \le 1, 0≤y≤10 \le y \le 1, and 0 outside it. Its volume is ∫01∫01(x+y) dy dx=12+12=1\int_0^1 \int_0^1 (x + y)\,dy\,dx = \frac{1}{2} + \frac{1}{2} = 1.

  • P(X<12, Y<12)P(X < \frac{1}{2},\ Y < \frac{1}{2}), a square: ∫01/2∫01/2(x+y) dy dx=18\int_0^{1/2} \int_0^{1/2} (x + y)\,dy\,dx = \frac{1}{8}.
  • P(X+Y<1)P(X + Y < 1), the triangle below the line y=1−xy = 1 - x: ∫01∫01−x(x+y) dy dx=13\int_0^1 \int_0^{1 - x} (x + y)\,dy\,dx = \frac{1}{3}.

The density is a height, not a probability: fX,Y(1,1)=2f_{X,Y}(1, 1) = 2. As in lesson 5.4.1, the probability of any single point, or of a line, is 0.

Marginal density. A sum over yy becomes an integral over yy: fX(x)=∫01(x+y) dy=x+12f_X(x) = \int_0^1 (x + y)\,dy = x + \frac{1}{2} on [0,1][0, 1]. That is the area of the slice of the surface at xx (lesson 4.7.1). By symmetry fY(y)=y+12f_Y(y) = y + \frac{1}{2}.

Conditional density. Given X=xX = x, divide the slice at xx by its area, so that it has area 1:

fY∣X(y∣x)=fX,Y(x,y)fX(x)=x+yx+12f_{Y \mid X}(y \mid x) = \frac{f_{X,Y}(x, y)}{f_X(x)} = \frac{x + y}{x + \frac{1}{2}}

At x=0.25x = 0.25 it runs from 0.3333 at y=0y = 0 to 1.6667 at y=1y = 1, and its mean is E[Y∣X=0.25]=0.6111\mathbb{E}[Y \mid X = 0.25] = 0.6111. At x=0.75x = 0.75 it is flatter, from 0.6 to 1.4, with mean 0.5667.

The density x+yx + y and two slices of it, each rescaled to area 1: the conditional densities of YY. The slice at x=0.25x = 0.25 tilts more, so it puts more weight on large yy and has the larger mean.

Rule: Joint, marginal and conditional densities

P((X,Y)∈R)=∬RfX,Y dAfX(x)=∫fX,Y(x,y) dyfY∣X(y∣x)=fX,Y(x,y)fX(x)\begin{gathered} P\big((X, Y) \in R\big) = \textstyle\iint_R f_{X,Y}\,dA \\[4pt] f_X(x) = \textstyle\int f_{X,Y}(x, y)\,dy \\[4pt] f_{Y \mid X}(y \mid x) = \dfrac{f_{X,Y}(x, y)}{f_X(x)} \end{gathered}

The same three ideas as for a table, with sums replaced by integrals. The conditional density is defined where fX(x)>0f_X(x) > 0, even though P(X=x)P(X = x) is 0.

Since P(X=x)=0P(X = x) = 0, the conditional density cannot come from lesson 5.1.3's P(A∣B)P(A \mid B) directly. Think of it as conditioning on XX falling in a thin strip around xx, and letting the strip shrink. The simulation below does exactly that.

Try it

dblquad (lesson 4.7.1) checks the volume and the two probabilities; its function takes the inner variable first, f(y, x). quad gives the conditional mean at x=0.25x = 0.25.

To simulate, the cell draws points uniformly in the square and keeps each with probability x+y2\frac{x + y}{2}, half its height. Kept points pile up where ff is high, so they follow the density.

In this seeded run about 200,000 are kept. Among those with 0.2<X<0.30.2 < X < 0.3, the average YY is 0.6123; the exact average over that strip is 0.6111.

⌘/Ctrl + Enter runs the cell

Independence

Lesson 5.1.3 called two events independent when P(A∩B)=P(A) P(B)P(A \cap B) = P(A)\,P(B). Two random variables are independent when this holds for every event about XX and every event about YY. For a table, that means every cell equals the product of its two margins.

Rule: Independent random variables

pX,Y(x,y)=pX(x) pY(y)fX,Y(x,y)=fX(x) fY(y)for every x and y\begin{gathered} p_{X,Y}(x, y) = p_X(x)\,p_Y(y) \\[4pt] f_{X,Y}(x, y) = f_X(x)\,f_Y(y) \\[4pt] \text{for every } x \text{ and } y \end{gathered}

The joint distribution is the product of the marginals. Then every conditional distribution of YY equals its marginal: knowing XX tells you nothing about YY. With nn variables, the joint is the product of all nn marginals.

Four checks:

  • The three coins: dependent. The cell (0,2)(0, 2) holds 0, but pX(0) pY(2)=116p_X(0)\,p_Y(2) = \frac{1}{16}. One failed cell is enough. Five of the nine cells pass, the middle one among them, 28=12⋅12\frac{2}{8} = \frac{1}{2} \cdot \frac{1}{2}, which proves nothing.
  • x+yx + y on the square: dependent. At (0,0)(0, 0) the density is 0, but fX(0) fY(0)=14f_X(0)\,f_Y(0) = \frac{1}{4}. The figure shows it too: the conditional density of YY changes with xx.
  • 4xy4xy on the square: independent. It factors as (2x)(2y)(2x)(2y), and the marginals are fX(x)=2xf_X(x) = 2x and fY(y)=2yf_Y(y) = 2y.
  • 2 on the triangle 0<y<x<10 < y < x < 1: dependent. The formula is a constant, which looks like a product, but the density is 0 off the triangle. The marginals are fX(x)=2xf_X(x) = 2x and fY(y)=2(1−y)f_Y(y) = 2(1 - y), and at (0.2,0.8)(0.2, 0.8) their product is 0.16 where ff is 0. Knowing X=0.2X = 0.2 forces Y<0.2Y < 0.2.

The last check gives a quick test. If the region where the density is positive is not a rectangle, the variables are dependent, whatever the formula.

Independent normal draws

Case study 3.7.4 drew a table of standard normal numbers and said its columns were independent, "one tells you nothing about the others". Now that is precise. The three numbers in a row, Z1Z_1, Z2Z_2 and Z3Z_3, have the joint density φ(z1) φ(z2) φ(z3)\varphi(z_1)\,\varphi(z_2)\,\varphi(z_3), with φ\varphi the standard normal density.

So the conditional density of Z2Z_2 given Z1=z1Z_1 = z_1 is φ(z2)\varphi(z_2), whatever z1z_1 is. In that table (seed 37), the 1,597 rows with Z1>1Z_1 > 1 have Z2Z_2 with mean −0.006-0.006 and standard deviation 0.996. All 10,000 rows give −0.015-0.015 and 0.993.

Case study 4.7.5's correlated returns are the opposite case. Their density is not a product. So the chance that both lose more than 10% was 0.0288, not the product of the single chances, 0.0145.

Try it

The first lines test every cell of the coin table against the product of its margins: the four corners fail. Then the triangle's marginals at (0.2,0.8)(0.2, 0.8).

The last lines rebuild case study 3.7.4's table of normal draws and compare Z2Z_2 in the rows with Z1>1Z_1 > 1, then Z1<−1Z_1 < -1, with all rows.

⌘/Ctrl + Enter runs the cell

Lesson 5.5.2 measures how strongly two dependent variables move together. Case study 5.5.5 uses independence across months and days to scale risk over time.

Common mistakes

  1. The marginals are not the whole story. The coin table and the four-coin table share their marginals, yet P(X=Y)P(X = Y) is 12\frac{1}{2} in one and 38\frac{3}{8} in the other.
  2. Divide by the total of what you know. pY∣X(y∣x)p_{Y \mid X}(y \mid x) divides by the row total pX(x)p_X(x). P(Y=2∣X=1)=14P(Y = 2 \mid X = 1) = \frac{1}{4} and P(X=1∣Y=2)=12P(X = 1 \mid Y = 2) = \frac{1}{2} are different numbers.
  3. Independence needs every cell. Five of the coin table's nine cells equal their products, yet XX and YY are dependent.
  4. A density can exceed 1. fX,Y(1,1)=2f_{X,Y}(1, 1) = 2 is a height; only volumes are probabilities.
  5. Look at the region, not only the formula. A constant density on a triangle gives dependent variables.
  6. No conditioning on the impossible. Given a value with pX(x)=0p_X(x) = 0, the conditional distribution is not defined.

Joint, marginal and conditional distributions

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • The joint pmf pX,Y(x,y)=P(X=x,Y=y)p_{X,Y}(x, y) = P(X = x, Y = y) is a table adding up to 1; a joint density fX,Yf_{X,Y} is a surface with volume 1, and P((X,Y)∈R)=∬RfX,Y dAP((X, Y) \in R) = \iint_R f_{X,Y}\,dA.
  • Marginals: pX(x)=∑ypX,Y(x,y)p_X(x) = \sum_y p_{X,Y}(x, y) and fX(x)=∫fX,Y(x,y) dyf_X(x) = \int f_{X,Y}(x, y)\,dy. They do not determine the joint.
  • Conditionals: pY∣X(y∣x)=pX,Y(x,y)pX(x)p_{Y \mid X}(y \mid x) = \frac{p_{X,Y}(x, y)}{p_X(x)} and fY∣X(y∣x)=fX,Y(x,y)fX(x)f_{Y \mid X}(y \mid x) = \frac{f_{X,Y}(x, y)}{f_X(x)}: a row or a slice rescaled to total 1. Their means are the conditional means E[Y∣X=x]\mathbb{E}[Y \mid X = x].
  • Independent: the joint is the product of the marginals at every point, so every conditional equals the marginal. One failed cell, or a region that is not a rectangle, means dependent.
  • Independent standard normals have joint density φ(z1)φ(z2)⋯φ(zn)\varphi(z_1)\varphi(z_2)\cdots\varphi(z_n).

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.