ProbabilityContinuous Random Variables

Densities of Functions of a Variable

Find the density of Y = g(X) through its CDF: work out F_Y(y) = P(g(X) ≤ y), then differentiate.

Not started Jump to practice

If $X$ has a known density, what is the density of $Y = X^{2}$, or $Y = e^{X}$? The reliable route goes through the CDF: find $F_Y$ by solving an inequality, then differentiate with the chain rule.

Key idea

The CDF method: write $F_Y(y) = P(g(X) \le y)$ as a statement about $X$, compute it with $F_X$, then $f_Y = F_Y'$. For increasing (or decreasing) $g$ this gives $$f_Y(y) = f_X\left(g^{-1}(y)\right)\left\lvert \frac{d}{dy}g^{-1}(y) \right\rvert.$$

Why it works

For increasing $g$: $g(X) \le y$ exactly when $X \le g^{-1}(y)$, so $F_Y(y) = F_X(g^{-1}(y))$, and the chain rule gives $$f_Y(y) = f_X(g^{-1}(y)) \cdot \frac{d}{dy}g^{-1}(y)$$ For decreasing $g$ the inequality flips, $F_Y = 1 - F_X(g^{-1}(y))$, and the derivative brings a minus sign that the absolute value absorbs. The derivative factor has a picture: a thin strip of width $dx$ near $x$ carries probability $f_X(x)\,dx$, and $g$ stretches it to width $\lvert g'(x) \rvert\,dx$. The same probability over a wider strip means a lower density.
Top: X uniform on 0 to 1, with a thin strip. Bottom: the density of Y equal to X squared, with the strip where it lands. Drag the strip: near 0 squaring squeezes the strip, so the density of Y is high there.

Worked examples

Worked example: Squaring a uniform

$X$ is uniform on $[0, 1]$ and $Y = X^{2}$. Find $f_Y$.
  1. For $0 < y < 1$: $$F_Y(y) = P(X^{2} \le y) = P(X \le \sqrt{y}) = \sqrt{y}$$
  2. $f_Y(y) = \frac{d}{dy}\sqrt{y} = \frac{1}{2\sqrt{y}}$ on $(0, 1)$.
  3. Check: $\int_{0}^{1} \frac{1}{2\sqrt{y}}\,dy = 1$.

Answer: $f_Y(y) = \frac{1}{2\sqrt{y}}$ for $0 < y < 1$.

Worked example: A logarithm

$X$ is uniform on $(0, 1)$ and $Y = -\ln X$. Find $f_Y$.
  1. $-\ln X \le y$ means $X \ge e^{-y}$, so $F_Y(y) = 1 - e^{-y}$ for $y > 0$.
  2. $f_Y(y) = e^{-y}$: exponential with rate 1. (This is how computers turn uniform random numbers into exponential ones.)

Answer: $f_Y(y) = e^{-y}$ for $y > 0$.

Worked example: A linear change

$f_X(x) = 2x$ on $[0, 1]$ and $Y = 2X + 3$. Find $f_Y$.
  1. $Y$ runs over $[3, 5]$, and $X = \frac{Y - 3}{2}$.
  2. $$f_Y(y) = f_X\left(\frac{y - 3}{2}\right) \cdot \frac{1}{2} = 2 \cdot \frac{y - 3}{2} \cdot \frac{1}{2} = \frac{y - 3}{2}$$ on $[3, 5]$.
  3. Check: $\int_{3}^{5} \frac{y - 3}{2}\,dy = 1$.

Answer: $f_Y(y) = \frac{y - 3}{2}$ on $[3, 5]$.

When $g$ is not one-to-one, add over every $x$ that maps to $y$. If $X$ is uniform on $[-1, 1]$ and $Y = X^{2}$, both $\sqrt{y}$ and $-\sqrt{y}$ map to $y$, each contributing $\frac{1/2}{2\sqrt{y}}$, so $f_Y(y) = \frac{1}{2\sqrt{y}}$ on $(0, 1)$. The CDF method handles this automatically: $F_Y(y) = P(-\sqrt{y} \le X \le \sqrt{y})$.

Common mistake

Substituting into the density, $f_Y(y) = f_X(g^{-1}(y))$, and dropping the derivative factor. For $Y = 2X + 3$ above, that would give $y - 3$ on $[3, 5]$, which has area 2. Check: every density you produce must have total area 1.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Probability.

Sources and further reading

  • Grinstead and Snell, Introduction to Probability (2nd revised edition, American Mathematical Society; free from Dartmouth College), chapter 5 (Distributions and Densities), section 5.2, functions of a random variable
  • MIT OpenCourseWare 18.05, Introduction to Probability and Statistics (Spring 2014), readings on manipulating continuous random variables
@teddyrookbook GitHub