pdf of a function of a random variable X
- Fātih Teoman
- 3 days ago
- 4 min read
Updated: 5 minutes ago
If X is a continuous random variable and Y = g(X), then Y is also a random variable. (Y may or may not be continuous.) Thus, we should be able to find the probability density function (pdf) and cumulative distribution function (cdf) of Y. (If Y is discrete, finding the probability mass function of it is easy.)
general approach
The cdf of Y is
Fy(y) = P(Y ≤ y) = P(g(X) ≤ y).
To compute this, we need to express the event {g(X) ≤ y} in terms of X. So we will solve the inequality g(X) ≤ y to find the set of x values such that g(x) ≤ y. Then
Fy(y) = P(X ∈ {x: g(x) ≤ y}).
monotonic case
Let X be a random variable with the pdf fx(x) and cdf Fx(x), and let Y = g(X). Now let's find Fy(y) and fy(y).
If g is increasing, then it has an inverse g⁻¹ and we can write
Fy(y) = P(Y ≤ y) = P(g(X) ≤ y) = P(X ≤ g⁻¹(y)) = Fx(g⁻¹(y)), and therefore
fy(y) = dFy(y)/dy = fx(g⁻¹(y))⋅(dg⁻¹(y)/dy). (Remember the chain rule.)
If g is decreasing, again it has an inverse g⁻¹ and we can write
Fy(y) = P(Y ≤ y) = P(g(X) ≤ y) = P(X ≥ g⁻¹(y)) = 1 − Fx(g⁻¹(y)), and therefore
fy(y) = dFy(y)/dy = −fx(g⁻¹(y))⋅(dg⁻¹(y)/dy).
Since dg⁻¹(y)/dy is positive when g is increasing and negative when it is decreasing, we can safely write
fy(y) = fx(g⁻¹(y))⋅|dg⁻¹(y)/dy|
if g is monotonic.
Let X ~ U(0, 1) and let Y = 1/X. Find the cdf and pdf of Y.
g(x) = 1/x is decreasing on (0, 1).
Fy(y) = P(Y ≤ y) = P(1/X ≤ y) = P(X ≥ 1/y) = 1 − Fx(1/y), and therefore
fy(y) = dFy(y)/dy = −fx(g⁻¹(y))⋅(dg⁻¹(y)/dy) = 1/y².
You will find E(Y) is infinite. Yes, not every random variable has a finite expectation!
non-monotonic case
What if g is not monotonic? This case is not straightforward. We can find the cdf of Y in three steps.
1- Divide the domain of g into parts such that each part contains exactly one monotonic part of g. Then find g⁻¹ for each monotonic part of g. This is horizontal partitioning: breaks the domain into monotonic chunks.
2- Divide the range of g into parts such that each part contains a fixed number of monotonic parts of g throughout the part (g(x) = y has a fixed number of roots throughout the part). This is vertical partitioning: groups y values by how many pre-images they have.
3- For each vertical part, add Fy(y)s contributed by the monotonic parts of g in that part to obtain the overall Fy(y) of that part.
Let's look at a challenging problem. Let X ∼ U(0, 3π/2) and Y = sin X. Find the cdf and pdf of Y.
We know fx(x) = 2/3π and Fx(x) = 2x/3π. Now let's find the cdf of Y following the steps outlined above.
1-
On [0, π/2] g is monotonic with g⁻¹ = arcsin y. On [π/2, 3π/2] g is monotonic with g⁻¹ = π - arcsin y. There are two horizontal parts.
2-
For y ∈ [-1, 0), there is only one monotonic part of g with g⁻¹ = π - arcsin y. For y ∈ [0, 1], there are two monotonic parts of g with g⁻¹ = arcsin y and g⁻¹ = π - arcsin y. There are two vertical parts.
3-
For y ∈ [-1, 0), Fy(y) = 1 - Fx(π - arcsin y) = (π + 2arcsin y)/3π.
For y ∈ [0, 1]
Fy(y) = Fx(arcsin y) = 2arcsin y/3π... from the first monotonic part
Fy(y) = 1 - Fx(π - arcsin y) = (π + 2arcsin y)/3π... from the second monotonic part
So, for y ∈ [0, 1], Fy(y) = (π + 4arcsin y)/3π.
To summarize
Fy(y) = 0 y < -1
(π + 2arcsin y)/3π -1 ≤ y < 0
(π + 4arcsin y)/3π 0 ≤ y ≤ 1
1 y > 1
Now you can easily find the pdf of Y from the cdf of it.
When you look at the graph below, you will notice that there are two horizontal and two vertical parts. From point A to K, g is increasing and from point K to F, g is decreasing. For y ∈ [-1, 0), sin x ≤ y only between points E and F. For y ∈ [0, 1], sin x ≤ y between points A and B, and points C and D.

Let X ∼ N(0, 1) and Y = X². Find the cdf and pdf of Y. (Hint: There are two horizontal parts and there is only one vertical part.)
I wrote this article because I could not find a correct and clear explanation of this subject in any book, website or forum. I hope this is useful.
Comments