Functions of Random Variables
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:
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
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.
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)
2π
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)
−∞
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
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)
r = g (x1 )
p (15)
= −2ln (1 − x1 )
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/