You are on page 1of 5

Connexions module: m11066 1

Functions of Random Variables ∗

Nick Kingsbury
This work is produced by The Connexions Project and licensed under the

Creative Commons Attribution License

Abstract
This module introduces functions of random variables.

1 Problem:

If the random variable Y is a monotonic increasing function of random variable X such that
Y = g (X)

and
X = g −1 (Y )
(inversion of g (.) requires it to be monotonic) then, given the cdf FX (x) and the function g (.), what are
FY (y) and fY (y), the cdf and pdf of Y ?

2 Solution:

If g (.) is monotonic increasing, the cdf of Y is given by

FY (y) = P r [Y ≤ y]
= P r [g (X) ≤ g (x)]
(1)
= P r [X ≤ x]
= FX (x)

where y = g (x).
The pdf of Y may be found as follows:
d
fY (y) = dy FY (y)
d
= dy FX (x)
d d
(2)
= dx FX (x) dy (x)
d
= fX (x) dy (x)
∗ Version 2.6: Jun 7, 2005 4:17 pm GMT-5
† http://creativecommons.org/licenses/by/1.0

http://cnx.org/content/m11066/2.6/
Connexions module: m11066 2

Dening
d
(y) = g 0 (x)
dx
and
fX (x)
fY (y) =
g 0 (x)
This relation is illustrated in Figure 1, using a geometric construction to relate fY to fX via Y = g (X). The
area under each of the pdfs between a given pair of dashed lines must be the same, because the probability
of being in a given range of X must be the same as the probability of being in the equivalent range of Y .

Figure 1: ◦
Illustration of monotonic mapping of pdfs by plotting fY (y) rotated by 90 . The non-linearity
2
in this case is g (X) = 0.4X + X − 0.4, which is monotonic for −1 ≤ X ≤ 1.

http://cnx.org/content/m11066/2.6/
Connexions module: m11066 3

If g (.) is monotonic decreasing (instead of increasing), then (1) becomes

FY (y) = P r [g (X) ≤ g (x)]


= P r [X ≥ x] (3)
= 1 − FX (x)

and by a similar argument we nd that


fX (x)
fY (y) = (4)
− (g 0 (x))
In principle, any non-monotonic function g (.) can be split into a nite number of monotonic sections and
in that case the pdf result can be generalized to
X  fX (x) 
fY (y) = |x=xi (5)
i
|g 0 (x) |

where the xi are all the solutions of g (x) = y at any given y . However care is needed in this case, because
if g (x) is smooth then g 0 (x) will become zero at the section boundaries and so fY (y) will tend to innity
at these points.

3 Example - Generation of a Gaussian pdf from a uniform pdf

If X has a uniform pdf from 0 to 1 (and zero elsewhere), and we wish to generate Y using Y = g (X) such
that Y has a Gaussian (normal) pdf of unit variance and zero mean, what is the required function g (.)?
(This function is often needed in computers, because standard random number generators tend to have
uniform pdfs, while simulation of noise from the real world requires Gaussian pdfs.)
For these pdfs: 
 1 if 0 ≤ x ≤ 1
fX (x) = (6)
 0 otherwise

1 − y2
“ ”
fY (y) = √ e 2
(7)

The corresponding cdfs are
Rx
FX (x) = f (u) du
−∞ X
 0 if x < 0
(8)


= x if 0 ≤ x ≤ 1

1 if x > 1


Z y
FY (y) = fY (u) du (9)
−∞

From our previous analysis, if 0 ≤ g −1 (y) ≤ 1

FX g −1 (y)

FY (y) =
(10)
= g −1 (y)

So, Z y
g −1 (y) = fY (u) du (11)
−∞

http://cnx.org/content/m11066/2.6/
Connexions module: m11066 4

This integral has no analytic solution, so we cannot easily invert this result to get g (.). However a numerical
(or graphical) solution is shown in Figure 2(a).

(a)

(b)

Figure 2: Conversion of uniform pdf to (a) a Gaussian pdf and (b) a Rayleigh pdf. A numerical solution
for g (X) was required for (a) in order to invert (11), whereas (b) uses the analytic solution for g (X),
given in (14).

We can get an analytic solution to this problem as follows. If we generate a 2-D Gaussian from polar
coordinates, we need to use two random variables to generate r and θ with the correct distributions. In
particular, r requires a Rayleigh distribution which can be integrated analytically and hence gives a relatively
simple analytic solution for g (.).
Assuming we start with a uniform pdf from 0 to 1 as before, generating θ is easy as we just scale the

http://cnx.org/content/m11066/2.6/
Connexions module: m11066 5

variable by 2π to get random phases uniformly distributed from 0 to 2π .


Once we have {r, θ}, we can convert to Cartesian components {x1 , x2 } to obtain two variables with
Gaussian pdfs.
To generate r correctly, we need a Rayleigh pdf
 “ 2”
 re− r2 if r ≥ 0
fR (r) = (12)
 0 otherwise

So,
Ry
g −1 (y) = f (r) dr
−∞ R“ ”
R y − r22
= 0 re dr
(13)
 “ 2 ”
− r2
= − e |y0
“ 2”
− y2
= 1−e
To get y = g (x), we just invert the formula for x = g −1 (y). Hence
y2
“ ”

x=1−e 2

y2
 
− = ln (1 − x)
2
 
(14)
p
∀x, 0 ≤ x < 1 : y = g (x) = −2ln (1 − x)

This conversion is illustrated in Figure 2(b).


Summarizing the complete algorithm:
 T  T  T
1. Generate a 2-D random vector x = x1 x2 with uniform pdfs from 0 0 to 1 1 ,
by two calls to a standard random number generator function (e.g. rand() in Matlab; although this
whole procedure is unnecessary in Matlab as there is already a Gaussian random generator, randn()).
2. Convert x1 into r with Rayleigh pdf using

r = g (x1 )
p (15)
= −2ln (1 − x1 )

3. Convert x2 into θ with uniform pdf from 0 to 2π using


θ = 2πx2 (16)
4. Generate two independent random variables with Gaussian pdfs of unit variance and zero mean using
y1 = rcos (θ)

and
y2 = rsin (θ)
5. Repeat steps 1 to 4 for each new pair of variables required.
note: y1 and y2 may be scaled by σ to adjust their variance, and an oset may be added in order
to produce a non-zero mean.

http://cnx.org/content/m11066/2.6/

You might also like