Functions of a Random Variable
To find the distribution of a function of a random variable Y = g(X), use the CDF method. Write F_Y(y) = P(g(X) ≤ y), turn it into an inequality about X, use the CDF of X, then differentiate to get the density of Y. When g is always increasing or always decreasing, a change-of-variable formula does this in one step.
Before this lesson: Cumulative Distribution Functions, Probability Density Functions and Uniform Distribution
Same randomness, new variable
If X is the side of a random square, its area is Y = X². The randomness is the same, but the values are reshaped. A density can’t just be moved over, because squaring stretches some intervals and squeezes others.
Probabilities do carry over, though. Y ≤ 0.25 happens exactly when X ≤ 0.5 (for a positive side), so the two events have the same probability. The CDF method uses this idea: work with P(Y ≤ y), which you can rewrite as an event about X, and only differentiate at the end.
The CDF method and the change-of-variable formula
- Find the possible values of Y from the possible values of X.
- Write F_Y(y) = P(g(X) ≤ y).
- Solve the inequality g(X) ≤ y for X, and rewrite the probability using the CDF of X.
- Differentiate F_Y to get f_Y, and state the range where it holds.
If g is strictly increasing or strictly decreasing, with inverse x = h(y), these steps collapse into one formula.
f_Y(y) = f_X\big(h(y)\big)\,\left|h'(y)\right|
The absolute value matters when g is decreasing, because h'(y) is then negative. For a g that goes down and then up, like x² on an interval around 0, use the CDF method.
Functions of a random variable examples
Example 1: Squaring a uniform variable
X ~ U(0, 1) and Y = X². Find the CDF and density of Y, and P(Y ≤ 0.25).
F_Y(y) = P(X^2 \le y)
Start from the definition of the CDF of Y.
F_Y(y) = P(X \le \sqrt{y})X is nonnegative, so take square roots of both sides.
F_Y(y) = \sqrt{y} \text{ for } 0 \le y \le 1The CDF of U(0, 1) is F_X(x) = x.
f_Y(y) = \dfrac{d}{dy}\sqrt{y} = \dfrac{1}{2\sqrt{y}} \text{ for } 0 \lt y \le 1Differentiate (see power rule).
P(Y \le 0.25) = \sqrt{0.25} = 0.5Evaluate the CDF.
Answer: F_Y(y) = √y and f_Y(y) = 1/(2√y) on (0, 1], and P(Y ≤ 0.25) = 0.5. X was flat, but Y piles up near 0, since squaring pulls small numbers closer to 0.
Example 2: A linear function
X ~ Exp(2) and Y = 3X + 1. Find the CDF and density of Y.
F_Y(y) = P(3X + 1 \le y)
Start from the definition of the CDF of Y.
F_Y(y) = P\left(X \le \dfrac{y - 1}{3}\right)Subtract 1 from both sides and divide by 3.
F_Y(y) = 1 - e^{-2(y - 1)/3} \text{ for } y \ge 1Use the exponential CDF 1 − e^(−2x); X ≥ 0 means y ≥ 1.
f_Y(y) = \dfrac{2}{3}e^{-2(y - 1)/3} \text{ for } y \ge 1Differentiate with the chain rule.
Answer: f_Y(y) = (2/3)e^(−2(y−1)/3) for y ≥ 1. Y is an exponential with rate 2/3, shifted to start at 1, and its mean is 3(1/2) + 1 = 2.5.
Example 3: A function that is not one-to-one
X ~ U(−1, 2), so f_X(x) = 1/3 on [−1, 2], and Y = X². Find the CDF and density of Y.
0 \le Y \le 4
X² is smallest at X = 0 and largest at X = 2.
F_Y(y) = P(-\sqrt{y} \le X \le \sqrt{y}) \text{ for } 0 \le y \le 1x² ≤ y means −√y ≤ x ≤ √y (see quadratic inequalities); both ends lie inside [−1, 2].
F_Y(y) = \dfrac{2\sqrt{y}}{3} \text{ for } 0 \le y \le 1Length 2√y divided by 3.
F_Y(y) = P(-1 \le X \le \sqrt{y}) = \dfrac{\sqrt{y} + 1}{3} \text{ for } 1 \lt y \le 4Now −√y is below −1, so the left end stops at −1.
f_Y(y) = \dfrac{1}{3\sqrt{y}} \text{ on } (0, 1), \qquad f_Y(y) = \dfrac{1}{6\sqrt{y}} \text{ on } (1, 4]Differentiate each piece.
Answer: the density is 1/(3√y) on (0, 1) and 1/(6√y) on (1, 4]. Check: F_Y(4) = (2 + 1)/3 = 1. Values of Y below 1 come from two parts of [−1, 2], so the density there is doubled.
Example 4: The change-of-variable formula
X has density f_X(x) = 2x on [0, 1], and Y = 1/X. Find the density of Y.
h(y) = \dfrac{1}{y}, \qquad h'(y) = -\dfrac{1}{y^2}Solve y = 1/x for x, then differentiate.
f_Y(y) = f_X\left(\dfrac{1}{y}\right)\left|-\dfrac{1}{y^2}\right|Use the change-of-variable formula; 1/x is decreasing, so keep the absolute value.
f_Y(y) = \dfrac{2}{y} \cdot \dfrac{1}{y^2} = \dfrac{2}{y^3} \text{ for } y \ge 1Substitute; x in (0, 1] gives y ≥ 1.
\int_1^\infty \dfrac{2}{y^3}\,dy = \Big[-\dfrac{1}{y^2}\Big]_1^\infty = 0 - (-1) = 1Check that the total area is 1 (see improper integrals).
Answer: f_Y(y) = 2/y³ for y ≥ 1.
Example 5: Area of a random circle (word problem)
A machine cuts disks whose radius R is uniform between 1 cm and 3 cm. Let A = πR² be the area. Find the density of A, the probability that the area is more than 4π cm², and the mean area.
F_A(a) = P(\pi R^2 \le a) = P\left(R \le \sqrt{a/\pi}\right)Divide both sides by π and take square roots (R is positive).
F_A(a) = \dfrac{\sqrt{a/\pi} - 1}{2} \text{ for } \pi \le a \le 9\piUse the CDF of U(1, 3), (r − 1)/2.
f_A(a) = \dfrac{1}{2} \cdot \dfrac{1}{2\sqrt{a/\pi}} \cdot \dfrac{1}{\pi} = \dfrac{1}{4\sqrt{\pi a}}Differentiate with the chain rule and simplify.
P(A \gt 4\pi) = 1 - F_A(4\pi) = 1 - \dfrac{2 - 1}{2} = 0.5Use the complement rule; √4 = 2.
E(A) = \pi E(R^2) = \pi \int_1^3 \dfrac{r^2}{2}\,drMultiply r² by the density 1/2 of R and integrate.
E(A) = \pi \cdot \dfrac{27 - 1}{6} = \dfrac{13\pi}{3} \approx 13.61Evaluate [r³/6] from 1 to 3.
Answer: f_A(a) = 1/(4√(πa)) for π ≤ a ≤ 9π, the probability is 0.5, and the mean area is 13π/3 ≈ 13.61 cm². The mean area is not π times the mean radius squared, which would be 4π ≈ 12.57.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Substituting into the density instead of the CDF | Saying f_Y(y) = f_X(√y) = 1 in Example 1 | Work with the CDF, or multiply by the derivative factor 1/(2√y). |
| Dropping the absolute value | Getting f_Y(y) = −2/y³ in Example 4 | A density can’t be negative; use the size of h'(y). |
| Using only one root for a non-one-to-one g | Saying P(Y ≤ y) = P(X ≤ √y) in Example 3 | Solve the whole inequality: −√y ≤ X ≤ √y. |
| Forgetting the new range | Using the density of Y for all y ≥ 0 in Example 2 | Map the range of X: x ≥ 0 gives y ≥ 1. |
| Assuming E(g(X)) = g(E(X)) | E(X²) = (1/2)² = 1/4 for X ~ U(0, 1) | Integrate: E(X²) = 1/3. |
Related ideas
Expected values without the new density
To find only E(g(X)), you don’t need the distribution of Y. Integrate g(x)f_X(x), as in Example 5 and the expected value of a continuous random variable lesson.
Simulation with the inverse CDF
If U ~ U(0, 1) and F is a CDF with inverse F⁻¹, then F⁻¹(U) has CDF F. Practice problem 10 builds an exponential variable this way. This is how computers turn uniform random numbers into any distribution.
Linear functions and discrete variables
For Y = aX + b, the mean and variance follow the rules in combining random variables, and the shape is just shifted and stretched. For a discrete X, add up the probabilities of all x values that give the same y.
Practice problems
- X ~ U(0, 2) and Y = 3X. Find the density of Y.
- X ~ U(0, 1) and Y = √X. Find the CDF and density of Y.
- X ~ Exp(1) and Y = 2X. Find the density of Y and name its distribution.
- X ~ U(0, 1) and Y = −ln X. Find the CDF of Y and name its distribution.
- X ~ U(−1, 1) and Y = X². Find the CDF and density of Y.
- X has density 3x² on [0, 1], and Y = X³. Find the distribution of Y.
- X ~ Exp(3) and Y = e^X. Find the CDF and density of Y.
- X ~ U(0, 4) and Y = (X − 2)². Find the density of Y.
- In Example 1, find E(Y) two ways: from X and from f_Y.
- X ~ U(0, 1). Show that Y = −ln(1 − X)/2 has an Exp(2) distribution.
Show answers
1.
F_Y(y) = P(3X \le y) = P\left(X \le \dfrac{y}{3}\right) = \dfrac{y/3}{2} = \dfrac{y}{6}Divide by 3 and use the CDF of U(0, 2).
f_Y(y) = \dfrac{1}{6} \text{ for } 0 \le y \le 6Differentiate.
Answer: Y ~ U(0, 6), with density 1/6 on [0, 6]
2.
F_Y(y) = P(\sqrt{X} \le y) = P(X \le y^2) = y^2Square both sides (both are nonnegative).
f_Y(y) = 2y \text{ for } 0 \le y \le 1Differentiate.
Answer: F_Y(y) = y² and f_Y(y) = 2y on [0, 1]
3.
F_Y(y) = P(2X \le y) = P\left(X \le \dfrac{y}{2}\right) = 1 - e^{-y/2}Divide by 2 and use the CDF of Exp(1).
f_Y(y) = \dfrac{1}{2}e^{-y/2} \text{ for } y \ge 0Differentiate.
Answer: Y ~ Exp(1/2), with mean 2
4.
F_Y(y) = P(-\ln X \le y) = P(\ln X \ge -y)
Multiply both sides by −1 and flip the inequality.
F_Y(y) = P(X \ge e^{-y}) = 1 - e^{-y} \text{ for } y \ge 0Exponentiate both sides; use the CDF of U(0, 1).
Answer: Y ~ Exp(1)
5.
F_Y(y) = P(-\sqrt{y} \le X \le \sqrt{y}) = \dfrac{2\sqrt{y}}{2} = \sqrt{y}Length 2√y divided by 2, for 0 ≤ y ≤ 1.
f_Y(y) = \dfrac{1}{2\sqrt{y}} \text{ for } 0 \lt y \le 1Differentiate.
Answer: F_Y(y) = √y and f_Y(y) = 1/(2√y), the same as Example 1
6.
F_Y(y) = P(X^3 \le y) = P(X \le y^{1/3})Take cube roots of both sides.
F_Y(y) = \int_0^{y^{1/3}} 3x^2\,dx = \left(y^{1/3}\right)^3 = yIntegrate the density of X.
Answer: Y ~ U(0, 1)
7.
F_Y(y) = P(e^X \le y) = P(X \le \ln y)
Take the natural log of both sides.
F_Y(y) = 1 - e^{-3\ln y} = 1 - y^{-3} \text{ for } y \ge 1Use the CDF of Exp(3) and e^(−3 ln y) = y^(−3).
f_Y(y) = 3y^{-4} \text{ for } y \ge 1Differentiate.
Answer: F_Y(y) = 1 − y⁻³ and f_Y(y) = 3/y⁴ for y ≥ 1
8.
F_Y(y) = P(2 - \sqrt{y} \le X \le 2 + \sqrt{y}) = \dfrac{2\sqrt{y}}{4} = \dfrac{\sqrt{y}}{2}For 0 ≤ y ≤ 4 both ends stay inside [0, 4].
f_Y(y) = \dfrac{1}{4\sqrt{y}} \text{ for } 0 \lt y \le 4Differentiate.
Answer: f_Y(y) = 1/(4√y) on (0, 4]
9.
E(Y) = E(X^2) = \int_0^1 x^2\,dx = \dfrac{1}{3}From X: integrate g(x) times the density 1.
E(Y) = \int_0^1 y \cdot \dfrac{1}{2\sqrt{y}}\,dy = \int_0^1 \dfrac{\sqrt{y}}{2}\,dy = \dfrac{1}{3}From f_Y: the antiderivative is y^(3/2)/3.
Answer: 1/3 both ways
10.
F_Y(y) = P\left(-\dfrac{\ln(1 - X)}{2} \le y\right) = P\big(\ln(1 - X) \ge -2y\big)Multiply both sides by −2 and flip the inequality.
F_Y(y) = P(1 - X \ge e^{-2y}) = P(X \le 1 - e^{-2y})Exponentiate, then solve for X.
F_Y(y) = 1 - e^{-2y} \text{ for } y \ge 0Use the CDF of U(0, 1).
Answer: this is the Exp(2) CDF, so Y ~ Exp(2)
Functions of a random variable FAQ
What is the CDF method?
It finds the distribution of Y = g(X) by writing P(Y ≤ y) as a probability about X, using the CDF of X, and then differentiating to get the density of Y.
When can I use the change-of-variable formula?
Use it when g is strictly increasing or strictly decreasing on the values of X. Then f_Y(y) = f_X(h(y))|h'(y)|, where h is the inverse of g. Otherwise, use the CDF method.
How do I find the range of Y = g(X)?
Find the smallest and largest values g takes on the possible values of X. For x² on [−1, 2], the smallest is 0 (at x = 0) and the largest is 4 (at x = 2).
Do I need the distribution of Y to find E(Y)?
No. E(g(X)) is the integral of g(x)f_X(x), so you can work with X directly. You need the distribution of Y for probabilities and percentiles of Y.
Summary
- Start from F_Y(y) = P(g(X) ≤ y) and rewrite it as an event about X.
- Differentiate F_Y to get f_Y, and state the range of Y.
- For a one-to-one g, use f_Y(y) = f_X(h(y))|h'(y)|.
- For a g that is not one-to-one, include every part of the X range that maps below y.
- E(g(X)) usually differs from g(E(X)).
Previous lesson: Gamma Distribution
Next lesson: Joint Probability Distributions
Back to the Probability Theory Index