next up previous
Next: Examples Up: Simulation of random variables Previous: Simulation of random variables

Additional notes: simulation of the Gamma distribution

The Gamma distribution is a two-parameter family with alternative parameterizations. The density function is

f(x) &=& \frac{1}{\beta^\alpha \Gamma(\alpha)} x^{\alpha - 1}e...
...pha)} x^{\alpha - 1}e^{-\lambda x},
\ \ x>0,\ \alpha,\lambda > 0

where $\alpha$ is called the shape parameter, $\beta$ is called the scale parameter, and $\lambda = 1/\beta$ is called the rate parameter. The expected value and standard deviation of the gamma distribution are,

E(X) &=& \alpha\beta = \frac{\alpha}{\lambda}\\
SD(X) &=& \sqrt{\alpha}\beta = \frac{\sqrt{\alpha}}{\lambda}.

It usually is more natural to specify the distribution in terms of its mean and s.d., $\mu,\sigma$. The relationship between $\alpha,\beta$ and $\mu,\sigma$ can be inverted to obtain the natural parameters of this distribution in terms of its mean and s.d. That is,

\alpha = \frac{\mu^2}{\sigma^2},\ \ \beta = \frac{\sigma^2}{\mu}.

The plot below shows why $\alpha$ is called the shape parameter.

Image GammaDens

This plot was generated by the following R code.

n = 100 # sample size
N = 400 # num x-values
mu = c(.75,1,5) # means
Gam.col = c("red","ForestGreen","blue")
sig = 1 # s.d.'s
alpha = (mu/sig)^2
beta = (sig^2)/mu
x = seq(0.05,8,length=N)
y1 = dgamma(x,alpha[1],scale=beta[1])
%y2 = dgamma(x,alpha[2],scale=beta[2])
%y3 = dgamma(x,alpha[3],scale=beta[3])
%Y = cbind(y1,y2,y3)
%for(k in seq(mu)) {
%  lines(x,Y[,k],col=Gam.col[k],lwd=1.5)
%legend(x[N],max(Y),legend=paste("Mean =",mu),
%       lty=1,col=Gam.col,xjust=1)
%title("Gamma Densities")
%mtext(paste("SD =",sig[1]),side=1,line=2)

Note that the Chi-square distribution is a special case of the gamma distribution with

shape = df/2
scale = 2 (rate = 1/2).