Gamma Distributions
The probability density function of gamma distribution is given bypdf = dgamma(x,alpha,lambda)with shape parameter



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 ,
we can define the quantile function
.
When
is the cdf of a random variable
,
we can find






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 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