| Title: | Generalized Gamma Probability Distribution |
|---|---|
| Description: | Density, distribution function, quantile function and random generation for the Generalized Gamma proposed in Stacy, E. W. (1962) <doi:10.1214/aoms/1177704481>. |
| Authors: | Matheus H. J. Saldanha [aut, cre], Adriano K. Suzuki [aut] |
| Maintainer: | Matheus H. J. Saldanha <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.2 |
| Built: | 2026-06-05 07:47:32 UTC |
| Source: | https://github.com/matheushjs/ggamma |
Density, distribution function, quantile function and random generation for the Generalized Gamma lifetime distributions.
This package follows naming convention that is consistent with base R,
where density (or probability mass) functions, distribution functions,
quantile functions and random generation functions names are followed by
d, p, q, and r prefixes.
Behaviour of the functions is consistent with base R, where for
not valid parameters values NaN's are returned, while
for values beyond function support 0's are returned
(e.g. for non-integers in discrete distributions, or for
negative values in functions with non-negative support).
C++ was not used, as the R code proved itself most efficient. See the package website page for more details.
Maintainer: Matheus H. J. Saldanha [email protected]
Authors:
Adriano K. Suzuki [email protected]
Useful links:
Fast implementation of density, distribution function, quantile function and random generation for the Generalized Gamma probability distribution.
dggamma(x, a, b, k, log = F) pggamma(q, a, b, k, lower.tail = TRUE, log.p = FALSE) qggamma(p, a, b, k, lower.tail = TRUE, log.p = FALSE) rggamma(n, a, b, k)dggamma(x, a, b, k, log = F) pggamma(q, a, b, k, lower.tail = TRUE, log.p = FALSE) qggamma(p, a, b, k, lower.tail = TRUE, log.p = FALSE) rggamma(n, a, b, k)
x, q
|
vector of quantiles. |
a, b, k
|
Parameters of the distribution, all of which must be positive. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of observations. If |
The generalized gamma distribution proposed by Stacy (1962) has parameters
, but here we adopt the reparametrization
as is used by the R package *flexsurv*.
Probability density function
Cumulative density function
The above function can be written in terms of a .
Let and its cumulative distribution be denoted as ,
then the cumulative density function of the generalized gamma distribution can be
written as
which allows us to write the quantile function of the generalized gamma in terms of
the gamma one ( is the quantile function of )
from which random numbers can be drawn.
Stacy, E. W. (1962). A generalization of the gamma distribution. The Annals of mathematical statistics, 33(3), 1187-1192.
x = seq(0.001, 5, length=1000); plot(x, dggamma(x, 3, 1.8, 0.5), col=2, type="l", lwd=4, ylim=c(0, 1)); lines(x, pggamma(x, 3, 1.8, 0.5), col=4, type="l", lwd=4, ylim=c(0, 1)); legend("right", c("PDF", "CDF"), col=c(2, 4), lwd=4); r = rgamma(n = 100, 2, 2); lik = function(params) -sum(dggamma(r, params[1], params[2], params[3], log=TRUE)); optPar = optim(lik, par=c(1, 1, 1), method="L-BFGS", lower=0.00001, upper=Inf)$par; x = seq(0.001, 5, length=1000); plot(x, dgamma(x, 2, 2), type="l", col=2, lwd=4, ylim=c(0, 1)); lines(x, dggamma(x, optPar[1], optPar[2], optPar[3]), col=4, lwd=4); legend("topright", c("Gamma(shape=2, rate=2)", "MLE Gen. Gamma"), col=c(2, 4), lwd=4);x = seq(0.001, 5, length=1000); plot(x, dggamma(x, 3, 1.8, 0.5), col=2, type="l", lwd=4, ylim=c(0, 1)); lines(x, pggamma(x, 3, 1.8, 0.5), col=4, type="l", lwd=4, ylim=c(0, 1)); legend("right", c("PDF", "CDF"), col=c(2, 4), lwd=4); r = rgamma(n = 100, 2, 2); lik = function(params) -sum(dggamma(r, params[1], params[2], params[3], log=TRUE)); optPar = optim(lik, par=c(1, 1, 1), method="L-BFGS", lower=0.00001, upper=Inf)$par; x = seq(0.001, 5, length=1000); plot(x, dgamma(x, 2, 2), type="l", col=2, lwd=4, ylim=c(0, 1)); lines(x, dggamma(x, optPar[1], optPar[2], optPar[3]), col=4, lwd=4); legend("topright", c("Gamma(shape=2, rate=2)", "MLE Gen. Gamma"), col=c(2, 4), lwd=4);