pdfgam: Probability Density Function of the Gamma Distribution

pdfgamR Documentation

Probability Density Function of the Gamma Distribution

Description

This function computes the probability density function of the Gamma distribution given parameters (\alpha, shape, and \beta, scale) computed by pargam. The probability density function has no explicit form, but is expressed as an integral

f(x|\alpha, \beta)^{\mathrm{lmomco}} = \frac{1}{\beta^\alpha\,\Gamma(\alpha)}\, x^{\alpha - 1}\, \mathrm{exp}(-x/\beta) \mbox{,}

where f(x) is the probability density for the quantile x, \alpha is a shape parameter, and \beta is a scale parameter.

Alternatively, a three-parameter version is available for this package following the parameterization of the Generalized Gamma distribution used in the gamlss.dist package and is

f(x|\mu,\sigma,\nu)_{\mathrm{gamlss.dist}}^{\mathrm{lmomco}}=\frac{\theta^\theta\, |\nu|}{\Gamma(\theta)}\,\frac{z^\theta}{x}\,\mathrm{exp}(-z\theta)\mbox{,}

where z =(x/\mu)^\nu, \theta = 1/(\sigma^2\,|\nu|^2) for x > 0, location parameter \mu > 0, scale parameter \sigma > 0, and shape parameter -\infty < \nu < \infty. Note that for \nu = 0 the distribution is log-Normal. The three parameter version is automatically triggered if the length of the para element is three and not two.

Usage

pdfgam(x, para)

Arguments

x

A real value vector.

para

The parameters from pargam or vec2par.

Value

Probability density (f) for x.

Note

Two Parameter \equiv Three Parameter
For \nu = 1, the parameter conversion between the two gamma forms is \alpha = \sigma^{-2} and \beta = \mu\sigma^2 and this can be readily verified:

  mu <- 5; sig <- 0.7; nu <- 0
  x <- exp(seq(-3,3,by=.1))
  para2 <- vec2par(c(1/sig^2, (mu*sig^2)  ), type="gam")
  para3 <- vec2par(c(      mu,    sig,   1), type="gam")
  plot(x, pdfgam(x, para2), ylab="Gamma Density"); lines(x, pdfgam(x, para3))

Package flexsurv Generalized Gamma
The flexsurv package provides an “original” (GenGamma.orig) and “preferred” parameterization (GenGamma) of the Generalized Gamma distribution and discusses parameter conversion between the two. Here the parameterization of the preferred form is compared to that in lmomco. The probability density function of dgengamma() from flexsurv is

f(x|\mu_2, \sigma_2, Q)_{\mathrm{flexsurv}} = \frac{\eta^\eta|Q|}{\sigma_2\Gamma(\eta)}\frac{1}{x}\, \mathrm{exp}\bigr\{\eta\times[wQ - \mathrm{exp}(wQ)]\bigr\}\mbox{,}

where \eta = Q^{-2}, w = \log(g/\eta)/Q for g \sim \mathrm{Gamma}(\eta, 1) where \mathrm{Gamma} is the cumulative distribution function (presumably, need to verify this) of the Gamma distribution, and

x \sim \mathrm{exp}(\mu_2 + w\sigma_2)\mbox{,}

where \mu_2 > 0, \sigma_2 > 0, and -\infty < Q < \infty, and the log-Normal distribution results for Q=0. These definitions for flexsurv seem incomplete to this author and further auditing is needed.

Additional Generalized Gamma Comparison
The default gamlss.dist package version uses so-called log.links for \mu and \sigma, and so-called identity.link for \nu and these links are implicit for lmomco. The parameters can be converted to flexsurv package equivalents by \mu_2 = \log(\mu), \sigma_2 = \sigma, and Q = \sigma\nu, which is readily verified by

  mu <- 2; sig <- 0.8; nu <- 0.2; x <- exp(seq(-3,1,by=0.1))
  para <- vec2par(c(mu,sig,nu), type="gam")
  dGG <- gamlss.dist::dGG(x, mu=mu, sigma=sig, nu=nu)
  plot( x, dGG, ylab="density", lwd=0.8, cex=2)
  lines(x, flexsurv::dgengamma(x, log(mu), sig, Q=sig*nu), col=8, lwd=5)
  lines(x, pdfgam(x, para), col=2)

What complicates the discussion further is that seemingly only the log.link concept is manifested in the use of \log(mu) to provide the \mu_2 for flexsurv::dgengamma.

On the Log-Normal via Generalized Gamma
The gamlss.dist package uses an |\nu| < 1\mathrm{e{-}6} trigger for the log-Normal calls. Further testing and the initial independent origin of lmomco code suggests that a primary trigger though can be based on the finiteness of the lgamma(theta) for \theta. This is used in pdfgam as well as cdfgam and quagam.

Author(s)

W.H. Asquith

References

Hosking, J.R.M., 1990, L-moments—Analysis and estimation of distributions using linear combinations of order statistics: Journal of the Royal Statistical Society, Series B, v. 52, pp. 105–124.

Hosking, J.R.M. and Wallis, J.R., 1997, Regional frequency analysis—An approach based on L-moments: Cambridge University Press.

See Also

cdfgam, quagam, lmomgam, pargam

Examples

  lmr <- lmoms(c(123,34,4,654,37,78))
  gam <- pargam(lmr)
  x <- quagam(0.5,gam)
  pdfgam(x,gam)

## Not run: 
# 3-p Generalized Gamma Distribution and gamlss.dist package parameterization
gg <- vec2par(c(7.4, 0.2, 14), type="gam"); X <- seq(0.04,9, by=.01)
GGa <- gamlss.dist::dGG(X, mu=7.4, sigma=0.2, nu=14)
GGb <- pdfgam(X, gg) # We now compare the two densities.
plot( X, GGa, type="l", xlab="X", ylab="PROBABILITY DENSITY", col=3, lwd=6)
lines(X, GGb, col=2, lwd=2) #
## End(Not run)

## Not run: 
# 3-p Generalized Gamma Distribution and gamlss.dist package parameterization
gg <- vec2par(c(1.7, 3, -4), type="gam"); X <- seq(0.04,9, by=.01)
GGa <- gamlss.dist::dGG(X, mu=1.7, sigma=3, nu=-4)
GGb <- pdfgam(X, gg) # We now compare the two densities.
plot( X, GGa, type="l", xlab="X", ylab="PROBABILITY DENSITY", col=3, lwd=6)
lines(X, GGb, col=2, lwd=2) #
## End(Not run)

wasquith/lmomco documentation built on Nov. 13, 2024, 4:53 p.m.