invgammaUC: The Inverse Gamma Distribution

invgammaDistR Documentation

The Inverse Gamma Distribution

Description

Density, distribution function, quantile function and random numbers generator for the Inverse Gamma Distribution.

Usage

dinvgamma(x, scale = 1/rate, shape, rate = 1, log = FALSE)
pinvgamma(q, scale = 1/rate, shape, rate = 1, lower.tail = TRUE, log.p = FALSE)
qinvgamma(p, scale = 1/rate, shape, rate = 1, lower.tail = TRUE, log.p = FALSE)
rinvgamma(n, scale = 1/rate, shape, rate = 1)

Arguments

x, q, p, n

Same as GammaDist.

scale, shape

Scale and shape parameters, same as GammaDist. Both must be positive.

rate

Same as GammaDist.

log, log.p, lower.tail

Same as GammaDist.

Details

The Inverse Gamma density with parameters scale = b and shape = s is given by

f(y) = \frac{b^{s}}{\Gamma(s)} y^{-s-1} e^{-b/y},

for y > 0, b > 0, and s > 0. Here, \Gamma(\cdot) is the gamma function as in gamma

The relation between the Gamma Distribution and the Inverse Gamma Distribution is as follows:

Let X be a random variable distributed as Gamma (b, s), then Y = 1 / X is distributed as Inverse Gamma (1/b, s). It is worth noting that the math relation between the scale paramaters of both, the Inverse Gamma and Gamma distributions, is inverse.

Thus, algorithms of dinvgamma(), pinvgamma(), qinvgamma() and rinvgamma() underlie on the algorithms GammaDist.

Let Y distributed as Inverse Gamma (b, s). Then the k^{th} moment of Y exists for -\infty < k < s and is given by

E[Y^k] = \frac{\Gamma(s - k)}{\Gamma(s)} b^k.

The mean (if s > 1) and variance (if s > 2) are

E[Y] = \frac{b}{(s - 1)}; \ \ \ Var[Y] = \frac{b^2}{(s - 1)^2 \times (s - 2)}.

Value

dinvgamma() returns the density, pinvgamma() gives the distribution function, qinvgamma() gives the quantiles, and rinvgamma() generates random deviates.

Warning

The order of the arguments scale and shape does not match GammaDist.

Note

Unlike the GammaDist, small values of a (plus modest \mu) or very large values of \mu (plus moderate a > 2), generate Inverse Gamma values so near to zero. Thus, rinvgamma in invgammaDist may return either values too close to zero or values represented as zero in computer arithmetic.

In addition, function dinvgamma will return zero for x = 0, which is the limit of the Inverse Gamma density when 'x' tends to zero.

Author(s)

V. Miranda and T. W. Yee.

References

Kleiber, C. and Kotz, S. (2003) Statistical Size Distributions in Economics and Actuarial Sciences. Wiley Series in Probability and Statistics. Hoboken, New Jersey, USA.

See Also

GammaDist, gamma.

Examples


  # Example 1.______________________
  n        <- 20
  scale    <- exp(2)
  shape    <- exp(1)
  data.1   <- runif(n, 0, 1)
  data.q   <- qinvgamma(-data.1, scale = scale, shape = shape, log.p = TRUE)  
  data.p   <- -log(pinvgamma(data.q, scale = scale, shape = shape)) 
  arg.max  <- max(abs(data.p - data.1))     # Should be zero
  
  
  # Example 2.______________________
  scale <- exp(1.0)
  shape <- exp(1.2)
  xx    <- seq(0, 3.0, len = 201)
  yy    <- dinvgamma(xx, scale = scale, shape = shape)
  qtl   <- seq(0.1, 0.9, by = 0.1)
  d.qtl <- qinvgamma(qtl, scale = scale, shape = shape)
  plot(xx, yy, type = "l", col = "orange", 
       main = "Orange is density, blue is cumulative distribution function",
       sub  = "Brown dashed lines represent the 10th, ... 90th percentiles",
       las = 1, xlab = "x", ylab = "", ylim = c(0, 1))
  abline(h = 0, col= "navy", lty = 2)
  lines(xx, pinvgamma(xx, scale = scale, shape = shape), col = "blue")
  lines(d.qtl, dinvgamma(d.qtl, scale = scale, shape = shape), 
        type ="h", col = "brown", lty = 3)
        

VGAMextra documentation built on Nov. 2, 2023, 5:59 p.m.