13.7 Gamma Variables (Optional)

Another continuous distribution that you may learn is called the Gamma distribution. This distribution is used for random variables that have some skewness and is not symmetrical, like the Normal Distribution.

The Gamma distribution requires a little more background to understand how to define the parameters.

There is a R function for simulating this random variable. Here in addition to the number of values to simulate, we just need two parameters, one for the shape and one for either the rate or the scale. The rate is the inverse of the scale. The general formula is: rgamma(n, shape, rate = 1, scale = 1/rate).

Given that \(\alpha\) is the shape parameter and \(\beta\) is the rate or scale parameter, then if you are thinking of a Gamma random variable, where the mean = \(\alpha * \beta\), then you use the scale for simulating. Otherwise, you use the rate.

We can verify these concepts with the following code.

set.seed(1)
rgamma(n = 5, shape = 3, scale = 2)

set.seed(1)
rgamma(n = 5, shape = 3, rate = 0.5)

And verifying the mean equal to 6 (shape*scale):

set.seed(1)
x <- rgamma(n = 1000, shape = 3, scale = 2)
mean(x)

Or verifying the mean equal to 6 (shape*1/rate):

set.seed(1)
x <- rgamma(n = 1000, shape = 3, rate = 0.5)
mean(x)