
Density, distribution function, quantile function and random
generation for the Gamma distribution with parameters shape
and
scale
.
dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE)
pgamma(q, shape, rate = 1, scale = 1/rate, lower.tail = TRUE,
log.p = FALSE)
qgamma(p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE,
log.p = FALSE)
rgamma(n, shape, rate = 1, scale = 1/rate)
vector of quantiles.
vector of probabilities.
number of observations. If length(n) > 1
, the length
is taken to be the number required.
an alternative way to specify the scale.
shape and scale parameters. Must be positive,
scale
strictly.
logical; if TRUE
, probabilities/densities
logical; if TRUE (default), probabilities are
dgamma
gives the density,
pgamma
gives the distribution function,
qgamma
gives the quantile function, and
rgamma
generates random deviates.
Invalid arguments will result in return value NaN
, with a warning.
The length of the result is determined by n
for
rgamma
, and is the maximum of the lengths of the
numerical arguments for the other functions.
The numerical arguments other than n
are recycled to the
length of the result. Only the first elements of the logical
arguments are used.
If scale
is omitted, it assumes the default value of 1
.
The Gamma distribution with parameters shape
scale
gamma()
and defined in its help. Note that
The mean and variance are
The cumulative hazard
-pgamma(t, ..., lower = FALSE, log = TRUE)
Note that for smallish values of shape
(and moderate
scale
) a large parts of the mass of the Gamma distribution is
on values of rgamma
may well return values
which will be represented as zero. (This will also happen for very
large values of scale
since the actual generation is done for
scale = 1
.)
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. 10.2307/2347328.
Abramowitz, M. and Stegun, I. A. (1972) Handbook of Mathematical Functions. New York: Dover. Chapter 6: Gamma and Related Functions.
NIST Digital Library of Mathematical Functions. http://dlmf.nist.gov/, section 8.2.
gamma
for the gamma function.
Distributions for other standard distributions, including
dbeta
for the Beta distribution and dchisq
for the chi-squared distribution which is a special case of the Gamma
distribution.
# NOT RUN {
-log(dgamma(1:4, shape = 1))
p <- (1:9)/10
pgamma(qgamma(p, shape = 2), shape = 2)
1 - 1/exp(qgamma(p, shape = 1))
# }
# NOT RUN {
# even for shape = 0.001 about half the mass is on numbers
# that cannot be represented accurately (and most of those as zero)
pgamma(.Machine$double.xmin, 0.001)
pgamma(5e-324, 0.001) # on most machines 5e-324 is the smallest
# representable non-zero number
table(rgamma(1e4, 0.001) == 0)/1e4
# }
Run the code above in your browser using DataLab