The log-gamma distribution
lgamma.RdDensity, distribution function and gradient of density for the
log-gamma distribution.
These are implemented in C
for speed and care is taken that the correct results are provided for
values of NA, NaN, Inf, -Inf or just
extremely small or large values.
The log-gamma is a flexible location-scale distribution on the real line with an extra parameter, \(\lambda\). For \(\lambda = 0\) the distribution equals the normal or Gaussian distribution, and for \(\lambda\) equal to 1 and -1, the Gumbel minimum and maximum distributions are obtained.
Details
If \(\lambda < 0\) the distribution is right skew, if \(\lambda = 0\) the distribution is symmetric (and equals the normal distribution), and if \(\lambda > 0\) the distribution is left skew.
These distribution functions, densities and gradients are used in the
Newton-Raphson algorithms in fitting cumulative link models with
clm2 and cumulative link mixed models with
clmm2 using the log-gamma link.
Value
plgamma gives the distribution function, dlgamma
gives the density and glgamma gives the gradient of the
density.
References
Genter, F. C. and Farewell, V. T. (1985) Goodness-of-link testing in ordinal regression models. The Canadian Journal of Statistics, 13(1), 37-44.
Examples
## Illustrating the link to other distribution functions:
x <- -5:5
plgamma(x, lambda = 0) == pnorm(x)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
all.equal(plgamma(x, lambda = -1), pgumbel(x)) ## TRUE, but:
#> [1] TRUE
plgamma(x, lambda = -1) == pgumbel(x)
#> [1] FALSE FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE
plgamma(x, lambda = 1) == pgumbel(x, max = FALSE)
#> [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
dlgamma(x, lambda = 0) == dnorm(x)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
dlgamma(x, lambda = -1) == dgumbel(x)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
dlgamma(x, lambda = 1) == dgumbel(x, max = FALSE)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
glgamma(x, lambda = 0) == gnorm(x)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
all.equal(glgamma(x, lambda = -1), ggumbel(x)) ## TRUE, but:
#> [1] TRUE
glgamma(x, lambda = -1) == ggumbel(x)
#> [1] TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE
all.equal(glgamma(x, lambda = 1), ggumbel(x, max = FALSE)) ## TRUE, but:
#> [1] TRUE
glgamma(x, lambda = 1) == ggumbel(x, max = FALSE)
#> [1] FALSE TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE TRUE
## There is a loss of accuracy, but the difference is very small:
glgamma(x, lambda = 1) - ggumbel(x, max = FALSE)
#> [1] -8.673617e-19 0.000000e+00 -1.387779e-17 -1.387779e-17 -2.775558e-17
#> [6] 0.000000e+00 0.000000e+00 0.000000e+00 1.058791e-22 -7.523164e-37
#> [11] 0.000000e+00
## More examples:
x <- -5:5
plgamma(x, lambda = .5)
#> [1] 0.0003729435 0.0023299245 0.0130924716 0.0621186950 0.2267546348
#> [6] 0.5665298796 0.8945151191 0.9945917346 0.9999813218 0.9999999993
#> [11] 1.0000000000
dlgamma(x, lambda = .5)
#> [1] 6.974573e-04 4.164869e-03 2.166083e-02 8.970337e-02 2.551632e-01
#> [6] 3.907336e-01 2.155388e-01 2.208500e-02 1.410374e-04 9.274904e-09
#> [11] 3.227334e-16
glgamma(x, lambda = .5)
#> [1] 1.280413e-03 7.202431e-03 3.365529e-02 1.134067e-01 2.007978e-01
#> [6] 0.000000e+00 -2.796492e-01 -7.589652e-02 -9.820967e-04 -1.185158e-07
#> [11] -7.217929e-15