top of page

pdf of a function of a random variable X

  • Writer: Fātih Teoman
    Fātih Teoman
  • May 4
  • 6 min read

Updated: Jun 4

If X is a continuous random variable with probability density function (pdf) fx(x) and cumulative distribution function (cdf) Fx(x), and if Y = g(X), then Y is also a random variable. Thus, we should be able to find its pdf and cdf. (If Y happens to be discrete, finding its probability mass function is easy.)


general approach


The cdf of Y is


Fy(y) = P(Y ≤ y) = P(g(X) ≤ y).


The pdf of Y is

fy(y) = dFy(y)/dy.


monotonic case


If g is monotonic, it has a unique inverse.


If g is increasing,


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,


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 write


fy(y) = fx(g⁻¹(y))⋅|dg⁻¹(y)/dy|


when g is monotonic.


Example: X ~ U(0, 1) and Y = 1/X. Find the cdf and pdf of Y.


fx(x) = 1 and Fx(x) = x.

g(x) = 1/x is decreasing on (0, 1), and g⁻¹(y) = 1/y.


Fy(y) = P(Y ≤ y) = P(1/X ≤ y) = P(X ≥ 1/y) = 1 − Fx(1/y) = 1 − 1/y = (y − 1)/y, and therefore

fy(y) = dFy(y)/dy = d((y − 1)/y)/dy = 1/y².

(Alternatively, fy(y) = −fx(g⁻¹(y))⋅(dg⁻¹(y)/dy) = 1/y².)


Note that E(Y) is infinite! Indeed, not every random variable has a finite expectation.


non-monotonic case


If g is non-monotonic with monotonic parts, it has multiple inverses. In this case, to find the cdf of Y:


  1. Divide g into monotonic parts and find g⁻¹ for each part.

  2. Divide the range of g into intervals over which the corresponding monotonic part(s) of g remain(s) the same. (Which monotonic parts of g are 'active' for different ranges of y values?)

  3. For each interval, compute Fy(y) = P(g(X) ≤ y) = P(X ∈ {x: g(x) ≤ y}).


Example: X ∼ U(0, 3π/2) and Y = sin X. Find the cdf and pdf of Y.


fx(x) = 2/and Fx(x) = 2x/3π. Now, let's find the cdf of Y following the steps outlined above.


1.

On [0, π/2], sin x is increasing and sin⁻¹ y = arcsin y.

On [π/2, 3π/2], sin x is decreasing and sin⁻¹ y = π arcsin y.


2.

Over [−1, 0), there is decreasing part of sin x with sin⁻¹ y = π arcsin y.

Over [0, 1], there are both parts of sin x with sin⁻¹ y = arcsin y and sin⁻¹ y = π arcsin y.


3.

For y ∈ [−1, 0), sin xy if x ∈ [π  arcsin y, 3π/2].

Fy(y) = P(sin X ≤ y) = P(X ≥ π  arcsin y) = 1 − Fx(π arcsin y) = (π + 2arcsin y)/3π.


For y ∈ [0, 1], sin x ≤ y if x ∈ [0, arcsin y] or x ∈ [π  arcsin y, 3π/2].

Fy(y) = P(sin X ≤ y) = P(X ≤ arcsin y or X ≥ π  arcsin y) = Fx(arcsin y) + (1 − Fx(π arcsin y)) = 2arcsin y/3π + (π + 2arcsin y)/3π = (π + 4arcsin y)/3π.


Finally:

Fy(y) = 0 y < −1,

(π + 2arcsin y)/3π 1 y < 0,

(π + 4arcsin y)/3π 0 y 1,

1 y > 1.


You can now easily find the pdf of Y from its cdf.


Examine the graph below. sin x on [0, 3π/2] has two monotonic parts: increasing from point A to K, and decreasing from point K to F. The range of sin x has two intervals: [−1, 0) with decreasing part and [0, 1] with both increasing and decreasing parts. For y ∈ [−1, 0), sin xy only between points E and F; for y ∈ [0, 1], sin xy between points A and B, and between points C and F.


y = sin x
y = sin x

Example: The support of X is [0, 2π] and g(X) = X + 2 sin X. Find the cdf of g.


1.

g(x) = x + 2 sin x
g(x) = x + 2 sin x

g is increasing on [0, 2π/3], decreasing on [2π/3, 4π/3], and increasing on [4π/3, 2π].

Since g doesn't have a closed-form inverse (g⁻¹ exists mathematically but can't be expressed in terms of elementary functions), let g1(y), g2(y), and g3(y) be the inverses for the monotonic parts of g.


2.

Over [0, 4π/3 3), there is first increasing part of g. 

Over [4π/3 3, 2π/3 + 3), there are all three monotonic parts of g.

Over [2π/3 + 3, 2π], there is second increasing part of g.


3.

For y ∈ [0, 4π/3 3), g(x) ≤ y if x ∈ [0, g1(y)].

Fy(y) = P(g(X) ≤ y) = P(X ≤ g1(y)) = Fx(g1(y)).


For y ∈ [4π/3 3, 2π/3 + 3), g(x) ≤ y if x ∈ [0, g1(y)] or x ∈ [g2(y), g3(y)].

Fy(y) = P(g(X) ≤ y) = P(X ≤ g1(y) or g2(y) ≤ X ≤ g3(y)) = Fx(g1(y)) + Fx(g3(y)) Fx(g2(y)).


For y ∈ [2π/3 + 3, 2π], g(x) ≤ y if x ∈ [0, g3(y)].

Fy(y) = P(g(X) ≤ y) = P(X ≤ g3(y)) = Fx(g3(y)).


Finally:

Fy(y) = 0 y < 0,

  Fx(g1(y)) 0  y < 4π/3 3,

Fx(g1(y)) + Fx(g3(y))  Fx(g2(y)) 4π/3 3  y < 2π/3 + 3,

Fx(g3(y)) 2π/3 + 3  y  2π,

1 y > 2π.


exercises


  1. Z ∼ N(0, 1) and Y = Z². Find the cdf and pdf of Y.

  2. What if g is non-monotonic with both monotonic and non-monotonic parts?

I wrote this article because I couldn't find an accurate and clear explanation of this topic in any book, website, or forum. I hope it proves helpful.

Comments


©2020 by blog. Proudly created with Wix.com

bottom of page