e-Mathematics > Probability and Statistics
for 3470-001 student.

Gamma Distributions

The probability density function of gamma distribution is given by
pdf = dgamma(x,alpha,lambda)
with shape parameter $ \alpha$ and rate parameter $ \lambda$ (or equivalently scale parameter $ \beta = 1/\lambda$), and its cumulative distribution function is obtained by pgamma().

shape = 3
rate = 5
x = seq(0,shape/rate*3,length=30)
pdf = dgamma(x,shape,rate)
plot(x,pdf,type='l',col='blue',main='Gamma PDF')
cdf = pgamma(x,shape,rate)
plot(x,cdf,type='l',col='red',main='Gamma CDF')
lines(range(x),c(1,1),lty=2,col='green')

Programming Note. The function

x = seq(a,b,length=30)
generates a sequence x of equally distanced values from a to b which has the length of 30 values. The function range(x) returns the range of the data x, that is, the minimum and the maximum values.

Quantile function. Given a continuous and strictly increasing cdf $ F(x)$, we can define the quantile function $ Q(u) = F^{-1}(u)$. When $ F(x)$ is the cdf of a random variable $ X$, we can find

$\displaystyle x_p = Q(p)
\quad \Leftrightarrow \quad
P(X \le x_p) = p
$

for every $ p \in (0,1)$. The value $ x_{1/2} = Q(\frac{1}{2})$ is called the median of $ F$, and the values $ x_{1/4} = Q(\frac{1}{4})$ and $ x_{3/4} = Q(\frac{3}{4})$ are called the lower quartile and the upper quartile, respectively. The quantile function for gamma distribution is given by qgamma().

p = 0.25
xp = qgamma(p, shape, rate)
lines(c(-1,xp,xp),c(p,p,-0.1),lty=2,col='red')
text(0,p,p,pos=3)
text(xp,0,round(xp,digit=4),pos=4)

Sample R code. You can download gamma.R, and run it.

Chi-square distribution. The probability density function of $ \chi^2$ distribution is given by

pdf = dchisq(x, deg)
with degrees "deg" of freedom. The quantile function is obtained by qchisq(). When lower.tail=F is specified in qchisq(), it returns the critical point, the value corresponding to the upper tail probability. Chi-square distribution table contains the selected quantiles in a useful form of table.

deg=7;
prob = 0.95;
x = seq(0.0, qchisq(0.99,deg), length=50);
par(mfrow=c(1,1));
pdf = dchisq(x,deg);
plot(x, pdf, type='l', lwd=1);
range = seq(0, qchisq(prob,deg), length = 25);
curve = dchisq(range, deg);
polygon(c(range,max(range),min(range)), c(curve,0,0), col='yellow');
lines(x, dchisq(x,10), lty=2, col=2);
lines(x, dchisq(x,15), lty=2, col=3);
legend(max(x)*0.6, max(pdf)*.95, lty=c(1,2,2), col=c(1,2,3),
  legend=c(paste('df =', deg), 'df = 10', 'df = 15'));
text(range[25]/2,curve[25]/2,prob,pos=3)
text(range[25],curve[25],round(range[25],digit=4),pos=4)

Programming Note. The function paste(a,b,c,...) returns the string which concatenates a,b,c,... as strings.

Sample R code. You can download chisquare.R, and run it.


© TTU Mathematics