Page 122 - Computational Statistics Handbook with MATLAB
P. 122
Chapter 4: Generating Random Variables 109
Exercises
4.1. Repeat Example 4.3 using larger sample sizes. What happens to the
estimated probability mass function (i.e., the relative frequencies from
the random samples) as the sample size gets bigger?
4.2. Write the MATLAB code to implement Example 4.5. Generate 500
random variables from this distribution and construct a histogram
(hist function) to verify your code.
4.3. Using the algorithm implemented in Example 4.3, write a MATLAB
function that will take any probability mass function (i.e., a vector of
probabilities) and return the desired number of random variables
generated according to that probability function.
4.4. Write a MATLAB function that will return random numbers that are
uniformly distributed over the interval ab,( . )
4.5. Write a MATLAB function that will return random numbers from the
normal distribution with mean and variance σ 2 . The user should
µ
be able to set values for the mean and variance as input arguments.
4.6. Write a function that will generate chi-square random variables with
ν degrees of freedom by generating standard normals, squaring
ν
them and then adding them up. This uses the fact that
2 2
X = Z 1 + … + Z ν
is chi-square with ν degrees of freedom. Generate some random
variables and plot in a histogram. The degrees of freedom should be
an input argument set by the user.
4.7. An alternative method for generating beta random variables is
⁄
1 α
described in Rubinstein [1981]. Generate two variates Y 1 = U 1 and
1 β
⁄
Y 2 = U 2 , where the U i are from the uniform distribution. If
Y 1 + Y 2 ≤ 1 , then
Y
1
X = ------------------ ,
Y 1 + Y 2
α
is from a beta distribution with parameters and β. Implement this
algorithm.
4.8. Run Example 4.4 and generate 1000 random variables. Determine the
number of variates that were rejected and the total number generated
to obtain the random sample. What percentage were rejected? How
efficient was it?
© 2002 by Chapman & Hall/CRC