Learn R Programming

Rlab (version 4.0)

Gamma: The Gamma Distribution

Description

Density, distribution function, quantile function and random generation for the Gamma distribution with parameters alpha (or shape) and beta (or scale or 1/rate).

This special Rlab implementation allows the parameters alpha and beta to be used, to match the function description often found in textbooks.

Usage

dgamma(x, shape, rate = 1, scale = 1/rate, alpha = shape,
       beta = scale, log = FALSE)
pgamma(q, shape, rate = 1, scale = 1/rate, alpha = shape,
       beta = scale, lower.tail = TRUE, log.p = FALSE)
qgamma(p, shape, rate = 1, scale = 1/rate, alpha = shape,
       beta = scale, lower.tail = TRUE, log.p = FALSE)
rgamma(n, shape, rate = 1, scale = 1/rate, alpha = shape,
       beta = scale)

Arguments

x, q

vector of quantiles.

p

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

rate

an alternative way to specify the scale.

alpha, beta

an alternative way to specify the shape and scale.

shape, scale

shape and scale parameters.

log, log.p

logical; if TRUE, probabilities p are given as log(p).

lower.tail

logical; if TRUE (default), probabilities are \(P[X \le x]\), otherwise, \(P[X > x]\).

Value

dgamma gives the density, pgamma gives the distribution function qgamma gives the quantile function, and rgamma generates random deviates.

Details

If beta (or scale or rate) is omitted, it assumes the default value of 1.

The Gamma distribution with parameters alpha (or shape) \(=\alpha\) and beta (or scale) \(=\sigma\) has density $$ f(x)= \frac{1}{{\sigma}^{\alpha}\Gamma(\alpha)} {x}^{\alpha-1} e^{-x/\sigma}% $$ for \(x > 0\), \(\alpha > 0\) and \(\sigma > 0\). The mean and variance are \(E(X) = \alpha\sigma\) and \(Var(X) = \alpha\sigma^2\).

pgamma() uses algorithm AS 239, see the references.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth \& Brooks/Cole.

Shea, B. L. (1988) Algorithm AS 239, Chi-squared and Incomplete Gamma Integral, Applied Statistics (JRSS C) 37, 466--473.

Abramowitz, M. and Stegun, I. A. (1972) Handbook of Mathematical Functions. New York: Dover. Chapter 6: Gamma and Related Functions.

See Also

gamma for the Gamma function, dbeta for the Beta distribution and dchisq for the chi-squared distribution which is a special case of the Gamma distribution.

Examples

Run this code
# NOT RUN {
-log(dgamma(1:4, alpha=1))
p <- (1:9)/10
pgamma(qgamma(p,alpha=2), alpha=2)
1 - 1/exp(qgamma(p, alpha=1))
# }

Run the code above in your browser using DataLab