# Connexions

You are here: Home » Content » Functions of Random Variables

### Recently Viewed

This feature requires Javascript to be enabled.

# Functions of Random Variables

Module by: Nick Kingsbury. E-mail the author

Summary: This module introduces functions of random variables.

## Problem:

If the random variable YY is a monotonic increasing function of random variable XX such that Y=gX Y g X and X=g-1Y X g Y (inversion of g. g . requires it to be monotonic) then, given the cdf F X x F X x and the function g. g . , what are F Y y F Y y and f Y y f Y y , the cdf and pdf of Y Y?

## Solution:

If g. g . is monotonic increasing, the cdf of YY is given by

F Y y=PrYy=PrgXgx=PrXx= F X x F Y y Y y g X g x X x F X x
(1)
where y=gx y g x .

The pdf of YY may be found as follows:

f Y y=dd y F Y y=dd y F X x=d F X xd x dxd y = f X xdxd y f Y y y F Y y y F X x x F X x y x f X x y x
(2)
Defining dd x y=gx x y g x and f Y y= f X xgx f Y y f X x g x This relation is illustrated in Figure 1, using a geometric construction to relate f Y f Y to f X f X via Y=gX 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 XX must be the same as the probability of being in the equivalent range of YY.

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

F Y y=PrgXgx=PrXx=1 F X x F Y y g X g x X x 1 F X x
(3)
and by a similar argument we find that
f Y y= f X xdgxd f Y y f X x g x
(4)
In principle, any non-monotonic function g. g . can be split into a finite number of monotonic sections and in that case the pdf result can be generalized to
f Y y=i f X x|dgxd|| x = x i f Y y i x x i f X x g x
(5)
where the x i x i are all the solutions of gx=y g x y at any given y y. However care is needed in this case, because if gx g x is smooth then gx g x will become zero at the section boundaries and so f Y y f Y y will tend to infinity at these points.

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

If XX has a uniform pdf from 00 to 11 (and zero elsewhere), and we wish to generate YY using Y=gX Y g X such that YY has a Gaussian (normal) pdf of unit variance and zero mean, what is the required function g. 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:

f X x={1  if  0x10  otherwise   f X x 1 0 x 1 0
(6)
f Y y=12πey22 f Y y 1 2 y 2 2
(7)
The corresponding cdfs are
F X x=x f X ud u ={0  if  x<0x  if  0x11  if  x>1 F X x u x f X u 0 x 0 x 0 x 1 1 x 1
(8)
F Y y=y f Y ud u F Y y u y f Y u
(9)
From our previous analysis, if 0g-1y1 0 g y 1
F Y y= F X g-1y=g-1y F Y y F X g y g y
(10)
So,
g-1y=y f Y ud u g y u y f Y u
(11)
This integral has no analytic solution, so we cannot easily invert this result to get g. g . . However a numerical (or graphical) solution is shown in Figure 2(a).

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 rr and θθ with the correct distributions. In particular, rr requires a Rayleigh distribution which can be integrated analytically and hence gives a relatively simple analytic solution for g. g . .

Assuming we start with a uniform pdf from 00 to 11 as before, generating θθ is easy as we just scale the variable by 2π 2 to get random phases uniformly distributed from 00 to 2π 2 .

Once we have rθ r θ , we can convert to Cartesian components x 1 x 2 x 1 x 2 to obtain two variables with Gaussian pdfs.

To generate rr correctly, we need a Rayleigh pdf

f R r={rer22  if  r00  otherwise   f R r r r 2 2 r 0 0
(12)
So,
g-1y=y f R rd r =0yrer22d r =er22|0y=1ey22 g y r y f R r r 0 y r r 2 2 0 y r 2 2 1 y 2 2
(13)
To get y=gx y g x , we just invert the formula for x=g-1y x g y . Hence x=1ey22 x 1 y 2 2 y22=ln1x y 2 2 1 x
x ,0x<1:y=gx=-2ln1x x 0 x 1 y g x -2 1 x
(14)
This conversion is illustrated in Figure 2(b).

Summarizing the complete algorithm:

1. Generate a 2-D random vector x=( x 1 x 2 )T x x 1 x 2 with uniform pdfs from ( 00 )T 0 0 to ( 11 )T 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 x 1 x 1 into rr with Rayleigh pdf using
r=g x 1 =-2ln1 x 1 r g x 1 -2 1 x 1
(15)
3. Convert x 2 x 2 into θθ with uniform pdf from 00 to 2π 2 using
θ=2π x 2 θ 2 x 2
(16)
4. Generate two independent random variables with Gaussian pdfs of unit variance and zero mean using y 1 =rcosθ y 1 r θ and y 2 =rsinθ y 2 r θ
5. Repeat steps 1 to 4 for each new pair of variables required.

### note:

y 1 y 1 and y 2 y 2 may be scaled by σσ to adjust their variance, and an offset may be added in order to produce a non-zero mean.

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks