As can be seen in the inverse transform method, as long as the functional form of the pdf (from which a random variable needs to be generated) is specified, one can use the method to either analytically or numerically invert the generated uniform number. Sometimes, however, despite the existence of such a pdf, the inverse transform method may not provide the best way to extract the available random numbers. The reason is that when millions of random numbers are needed, the cumulative time taken by Newton's method to converge to the respective solutions can be excessive. In this instance, it is of great value to exploit the functional relationships between easily generable random variables and those that need to be generated – so that the

TABLE 4.7 Generation of a Gamma Random Number

computational time can be drastically reduced. However, unlike the inverse transform method, it is difficult to identify a series of steps one has to methodically step through to arrive at the required result. Despite this minor drawback, the related distribution method provides a powerful way of generating random variables.

Simulating a Gamma Random Variable To simulate a gamma random variable^{[1]} with a shape parameter of 2 and rate parameter of 3, one first needs to observe that a gamma random variable with a shape parameter α and rate parameter β can be created by adding α independent and identical exponential random variables (each with a rate β).^{[2]} As long as one is able to simulate an exponential variate with rate β, it is straightforward to independently generate another (α – 1) identical random variable and then add them up to arrive at the gamma random variable.^{[3]}

Consider for example the generation of a gamma random variable with shape parameter 2 and rate parameter 3. To do this, one only needs to generate two independent and identical exponential random variables (with a rate of 3). Table 4.7 shows the implementation of generation of the gamma variate.

TABLE 4.8 Generation of a Standard Normal Random Number Using Box-Muller Transformation

Simulating a Standard Normal Random Variable Earlier, I discussed the generation of a standard normal variable using the inverse transform method. I will now revisit the same problem using another method. In 1958, Box and Muller showed that by using two independent uniform variates, one can generate two independent standard normal variates by using the transformation^{[4]}

where and are the two independent uniform variables.

Table 4.8 illustrates the implementation of the Box-Muller transformation.

Simulating a Beta Random Variable To simulate a random variable from beta pdf^{[5]} with shape parameters 2 and 3 (i.e., for ), the reader has to first observe that if X has a gamma pdf (with shape parameter a and rate parameter) and Yhas an independent gamma pdf (with a shape parameterand rate) then has a Beta pdf with shape parametersandwhen both X and Y are independent.^{[6]} As a consequence,

TABLE 4.9 Generation of a Beta Random Number

it suffices for one to be able to generate the two independent gamma variates and then apply the relationship.

In the context of the example, a beta pdf with shape parameters 2 and 3 can be generated using a gamma pdf (with shape parameter 2 and rate parameter 1) and another independent gamma pdf (with shape parameter 3 and rate parameter 1). The implementation of this is given in Table 4.9.^{[7]}

[1] If X has a gamma pdf with a shape parameterand rate parameter, X takes the form where and:

[2] "This can be easily seen by noting that the moment-generating function of a gamma pdf (with a shape parameter α and rate parameter β) is the same as the product of α identical moment-generating functions of an exponential pdf (each with a rate β).

[3] The reader should note that this approach works well when α is an integer. In the event that α is not an integer (e.g., 7.3), one can easily decompose such α values into a sum of two components which are integers (i.e., 7) and nonintegral terms lying in the interval (0,1) (i.e., 0.3). The generation of gamma variates when 0 < α < 1 is, however, a big challenge due to the instability in gamma pdf for values of α in this interval. See for example Devroye (1986).

[4] To see this, first observe that the joint pdf of and is given by the expression where. Making the appropriate substitution and taking the Jacobean, one can show that the joint pdf in and becomes

[5] If X has a beta pdf with shape parametersandtakes the form whereand

[6] This can be easily observed by first writingthe joint pdf of X and Y and then making the transformationandso as to obtain a joint pdf of U and V. To arrive at the desired pdf of 17, one needs to integrate out V from the joint pdf of U and V.

[7] While this is true for all values of α and Θ, the reader should recall the difficulty associated with generating gamma variates when values of α and Θ are not integers.

Found a mistake? Please highlight the word and press Shift + Enter