---
title: Joint distributions
heading: Two random quantities at once
eyebrow: A11 · Lesson 21 · Joint distributions
xp: 40
---

::: hook
A receiver's input bit and output bit are both random, and the interesting question is how they relate: how often they disagree, and what a received 1 says about what was sent. Two parts in a system each have a random lifetime; the system fails at the first failure, or the last, depending on how they're connected. Questions about two random quantities need their joint distribution: the chance of every combination of values. From it you can read either one alone, one given the other, or any event that involves both.
:::

::: play
- Two parts with independent exponential lifetimes $T_1$ and $T_2$ (failure rates $\lambda_1$ and $\lambda_2$ per year). The shading is their joint density, brightest near the origin.
- The diagonal is $T_1 = T_2$. Above it, part 1 fails first. The readout gives the probability of that region.
- Make $\lambda_1$ larger. The density squeezes toward the $T_2$ axis, and part 1 is more likely to fail first.
:::
:::

```sim plot
view: flow
x: t1 = 0..5 years
y: t2 = 0..5 years
aspect: equal
slider: l1 = 0.2..2 step 0.1 = 0.5 /year
slider: l2 = 0.2..2 step 0.1 = 1 /year
shade: l1*l2*exp(-l1*t1 - l2*t2) | contours: 10
path: 5*u, 5*u | over: u = 0..1 | color: ch3
readout: P(part 1 fails first) = l1/(l1 + l2) | digits: 3
readout: mean time to the first failure, years = 1/(l1 + l2) | digits: 3
```

::: predict
## Two parts fail at random with rates 0.1 and 0.3 per year, independently. The system stops at the first failure. What is its mean lifetime?

- [ ] 10 years, the better part's
- [ ] 6.7 years, the average of 10 and 3.3
- [x] 2.5 years
- [ ] 3.3 years, the worse part's

::: reveal
2.5 years. The system survives to $t$ only if both parts do: $e^{-0.1t}e^{-0.3t} = e^{-0.4t}$. That's an exponential with rate 0.4, so its mean is $\frac{1}{0.4} = 2.5$ years. In series, failure rates add, and the system is worse than either part alone.
:::
:::

::: nameit
## Joint distributions

For two discrete variables, the **joint PMF** $p(x, y) = P(X = x, Y = y)$ lists every combination; for continuous ones, a **joint density** $p(x, y)$ gives probability as volume:

$$P\big((X, Y) \in R\big) = \iint_R p(x, y)\,dx\,dy$$

This is a double integral over a region, as in A9.14.

## Marginals and conditionals

The distribution of one variable alone, its **marginal**, sums or integrates out the other:

$$p_X(x) = \sum_y p(x, y) \qquad\text{or}\qquad \int p(x, y)\,dy$$

The **conditional** distribution of $Y$ given $X = x$ is a slice of the joint, rescaled to total 1:

$$p(y \mid x) = \frac{p(x, y)}{p_X(x)}$$

## Independence

$X$ and $Y$ are independent exactly when the joint factors, $p(x, y) = p_X(x)\,p_Y(y)$ for every $x$ and $y$. Then every conditional equals its marginal. One pair of values that breaks the product rule is enough to show dependence.

## Two lifetimes

For independent exponential lifetimes with rates $\lambda_1$ and $\lambda_2$:

- **The first failure** (a series system) is exponential with rate $\lambda_1 + \lambda_2$: in series, failure rates add.
- **Which fails first:** $P(T_1 < T_2) = \frac{\lambda_1}{\lambda_1 + \lambda_2}$, the integral of the joint density over the region above the diagonal.
- **The last failure** (a parallel system): $P(\max \le t) = (1 - e^{-\lambda_1t})(1 - e^{-\lambda_2t})$.
:::

::: example
## A binary channel's input $X$ and output $Y$ have joint PMF $p(0, 0) = 0.45$, $p(0, 1) = 0.05$, $p(1, 0) = 0.02$, $p(1, 1) = 0.48$. Find the marginals, the error rate and $P(X = 1 \mid Y = 1)$. Are $X$ and $Y$ independent?

::: solution
1. **Marginals.** Add the cells for each value:
   $$\begin{aligned} P(X = 1) &= 0.02 + 0.48 \\ &= 0.50 \end{aligned}$$
   $$\begin{aligned} P(Y = 1) &= 0.05 + 0.48 \\ &= 0.53 \end{aligned}$$
2. **Error rate.** Errors are the off-diagonal cells:
   $$0.05 + 0.02 = 0.07$$
3. **Posterior.**
   $$\begin{aligned} P(X = 1 \mid Y = 1) &= \frac{0.48}{0.53} \\ &= 0.906 \end{aligned}$$
4. **Test independence.** Independence would need
   $$\begin{aligned} p(1, 1) &= 0.50 \times 0.53 \\ &= 0.265 \end{aligned}$$
   but it's 0.48, so they're strongly dependent, which is what you want from a channel.

**Answer:** $P(X = 1) = 0.50$ and $P(Y = 1) = 0.53$, the error rate is 0.07, $P(X = 1 \mid Y = 1) = 0.906$, and $X$ and $Y$ are strongly dependent.
:::
:::

::: example
## $X$ and $Y$ have joint density $p(x, y) = x + y$ on the unit square. Find the marginal density of $X$, and check that the joint density has total probability 1.

::: solution
1. **Marginal of $X$.** Integrate out $y$:
   $$\begin{aligned} p_X(x) &= \int_0^1 (x + y)\,dy \\ &= x + \frac{1}{2} \end{aligned}$$
2. **Check the total.**
   $$\begin{aligned} \int_0^1 \left(x + \frac12\right)dx &= \frac12 + \frac12 \\ &= 1 \end{aligned}$$
   so the joint density is properly normalized.
3. **Independence.** Since $x + y$ isn't a product of a function of $x$ and a function of $y$, $X$ and $Y$ aren't independent.

**Answer:** $p_X(x) = x + \frac12$, and the joint density has total probability 1.
:::
:::

::: example
## $X$ and $Y$ are independent and uniform on $[0, 1]$. What are $P(Y > X)$ and $P(Y > 2X)$?

::: solution
1. **Probability as area.** The joint density is 1 on the unit square, so each probability is the area of a region.
2. **$Y > X$.** It's the triangle above the diagonal, with area $\frac12$.
3. **$Y > 2X$.** It's the triangle with corners $(0, 0)$, $(0, 1)$ and $\left(\frac12, 1\right)$, with area $\frac14$.

**Answer:** $P(Y > X) = \frac12$ and $P(Y > 2X) = \frac14$.
:::
:::

::: check
given: p00 = 0.4 | 0.45; p01 = 0.05 | 0.08; p10 = 0.03 | 0.04; let p11 = 1 - p00 - p01 - p10
answer: p01 + p10
tolerance: 0.5%

## A channel's input and output have joint PMF $p(0,0)$ = {p00}, $p(0,1)$ = {p01}, $p(1,0)$ = {p10}, and $p(1,1)$ the rest. What is the error rate?

::: right
Right. The two cells where input and output differ: {answer}.
:::

::: misses
- [p01] Errors happen both ways; include $p(1, 0)$.
- [any] Not yet. Add $p(0,1)$ and $p(1,0)$.
:::
:::

::: check
given: p00 = 0.4 | 0.45; p01 = 0.05 | 0.08; p10 = 0.03 | 0.04; let p11 = 1 - p00 - p01 - p10
answer: p11/(p01 + p11)
tolerance: 0.5%

## Same channel: $p(0,0)$ = {p00}, $p(0,1)$ = {p01}, $p(1,0)$ = {p10}, $p(1,1)$ the rest. A 1 is received. What is the chance a 1 was sent?

::: right
Right. $\frac{p(1,1)}{P(Y = 1)}$ = {answer}.
:::

::: misses
- [p11] Divide by $P(Y = 1) = p(0,1) + p(1,1)$.
- [p11/(p10 + p11)] That's $P(Y = 1 \mid X = 1)$; condition on the output.
- [any] Not yet. Slice the table at $Y = 1$ and rescale.
:::
:::

::: check
given: l1 = 0.1 | 0.2; l2 = 0.3 | 0.5
answer: 1/(l1 + l2)
unit: years
tolerance: 0.5%

## Two parts with independent exponential lifetimes, failure rates {l1} and {l2} per year, are in series. What is the system's mean lifetime?

::: right
Right. The rates add: $\frac{1}{\lambda_1 + \lambda_2}$ = {answer}.
:::

::: misses
- [1/l1 + 1/l2] Means don't add here; the system stops at the first failure.
- [1/l2] The system is worse than its worst part.
- [any] Not yet. The first failure is exponential with rate $\lambda_1 + \lambda_2$.
:::
:::

::: check
given: l1 = 0.1 | 0.2; l2 = 0.3 | 0.5
answer: l1/(l1 + l2)
tolerance: 0.5%

## Same two parts, rates {l1} and {l2} per year. What is the chance that the first part fails first?

::: right
Right. $\frac{\lambda_1}{\lambda_1 + \lambda_2}$ = {answer}.
:::

::: misses
- [l2/(l1 + l2)] That's the chance the second part fails first. The part with the higher rate is likelier to go first.
- [any] Not yet. Integrate the joint density over $t_1 < t_2$.
:::
:::

::: check
given: l1 = 0.1 | 0.2; l2 = 0.3 | 0.5; t = 2 | 5
answer: (1 - exp(-l1*t))*(1 - exp(-l2*t))
tolerance: 0.5%

## The same two parts are now redundant: the system works while either does. What is the chance both have failed by {t} years?

::: right
Right. Independent failures by $t$ multiply: {answer}.
:::

::: misses
- [exp(-(l1 + l2)*t)] That's the chance both survive.
- [1 - exp(-(l1 + l2)*t)] That's the chance at least one has failed.
- [any] Not yet. $P(T_1 \le t)P(T_2 \le t)$.
:::
:::

::: check
given: x0 = 0.2 | 0.5 | 0.9
answer: x0 + 0.5
tolerance: 0.5%

## $X$ and $Y$ have joint density $x + y$ on the unit square. What is the marginal density $p_X$ at $x$ = {x0}?

::: right
Right. $\int_0^1 (x + y)\,dy = x + \frac12$ = {answer}.
:::

::: misses
- [x0] Integrate over $y$; the $y$ term contributes $\frac12$.
- [any] Not yet. Integrate out $y$.
:::
:::

::: check
kind: parts
given: k = 2 | 3 | 4

## $X$ and $Y$ are independent and uniform on $[0, 1]$.

::: part
answer: 1/(2*k)
tolerance: 0.5%

### What is $P(Y > \given{k}X)$?

::: misses
- [1/k] It's a triangle: half of the rectangle of width $\frac1k$.
- [any] The area of the triangle with corners $(0, 0)$, $(0, 1)$, $(1/k, 1)$.
:::
:::
:::

::: check
kind: derivation
vars: x = 0..1

## $X$ and $Y$ have joint density $x + y$ on the unit square.

::: step
answer: x + 0.5

### What is the marginal density of $X$, $\int_0^1(x + y)\,dy$?
:::

::: right
Right. $p_X(x) = x + \frac12$, which integrates to 1 over $[0, 1]$.
:::
:::

::: explain
## Why do failure rates add for parts in series?

::: model
A series system is still working at time $t$ only if every part is. With independent parts, that chance is the product of their survival chances, $e^{-\lambda_1t}e^{-\lambda_2t} = e^{-(\lambda_1 + \lambda_2)t}$. Multiplying exponentials adds their exponents, so the system behaves like a single part with failure rate $\lambda_1 + \lambda_2$. Each part adds its own chance per hour of stopping everything.
:::
:::

::: practice

::: check
given: s = 0.2 | 0.3 | 0.5 | 0.6 | 0.8 | 0.9 | 1
answer: s^2/2
tolerance: 0.5%

## $X$ and $Y$ are independent and uniform on $[0, 1]$. What is $P(X + Y < \given{s})$?

::: misses
- [s] The region below $x + y = s$ is a triangle of area $s^2/2$.
- [any] The area of the triangle under the line.
:::
:::

::: check
given: a = 2 | 4; b = 3 | 5
answer: 1/(a*b)
tolerance: 0.5%

## A point is uniform over a {a} by {b} rectangle. What is its joint density?

::: misses
- [a*b] The density times the area must be 1.
- [any] One over the area.
:::
:::

::: check
given: n = 3 | 5; l = 0.1 | 0.2
answer: 1/(n*l)
tolerance: 0.5%

## {n} identical parts with failure rate {l} per year are in series. What is the system's mean lifetime?

::: misses
- [any] Rates add: $\frac{1}{n\lambda}$.
:::
:::
:::
