Page 96 - Computational Statistics Handbook with MATLAB
P. 96
Chapter 4: Generating Random Variables 83
We illustrate this procedure using a simple example.
Example 4.2
We would like to simulate a discrete random variable X that has probability
mass function given by
(
PX = 0) = 0.3,
(
PX = 1) = 0.2,
(
PX = 2) = 0.5.
The cumulative distribution function is
0; x < 0
0.3; 0 ≤ x < 1
Fx() =
0.5; 1 ≤ x < 2
2 ≤
1.0; x.
We generate random variables for X according to the following scheme
0; U ≤ 0.3
X = 1; 0.3 < U ≤ 0.5
2; 0.5 < U ≤ 1.
This is easily implemented in MATLAB and is left as an exercise. The proce-
dure is illustrated in Figure 4.2, for the situation where a uniform random
variable 0.73 was generated. Note that this would return the variate x = 2 .
We now outline the algorithmic technique for this procedure. This will be
useful when we describe a method for generating Poisson random variables.
PROCEDURE - INVERSE TRANSFORM (DISCRETE)
,
,
1. Define a probability mass function for x i i = 1 … k . Note that k
,
could grow infinitely.
2. Generate a uniform random number U.
3. If U ≤ p 0 deliver X = x 0
4. else if U ≤ p 0 + p 1 deliver X = x 1
5. else if U ≤ p 0 + p 1 + p 2 deliver X = x 2
© 2002 by Chapman & Hall/CRC