InvGammaDist: The Inverse Gamma Distribution

InvGammaDistR Documentation

The Inverse Gamma Distribution

Description

Density, distribution function, quantile function, and random generation for the inverse gamma distribution with parameters shape and scale. Note that the parameterization is consistent with Gelman et al. (2013) (see References) and that scale precedes rate in the argument list, which is the reverse of the GammaDist functions.

Usage

rinvgamma(n, shape, scale = 1, rate = 1/scale)

dinvgamma(x, shape, scale = 1, rate = 1/scale, log = FALSE)

pinvgamma(
  q,
  shape,
  scale = 1,
  rate = 1/scale,
  lower.tail = TRUE,
  log.p = FALSE
)

qinvgamma(
  p,
  shape,
  scale = 1,
  rate = 1/scale,
  lower.tail = TRUE,
  log.p = FALSE
)

Arguments

n

number of observations. If length(n) > 1, the length is taken to be the number required.

shape, scale

shape and scale parameters. Must be positive, scale strictly.

rate

an alternative way to specify the scale.

x, q

vector of quantiles.

log, log.p

logical; if TRUE, probabilities/densities p are returned as log(p).

lower.tail

logical; if TRUE (default), probabilities are P[X \le x], otherwise, P[X > x].

p

vector of probabilities.

Details

If scale is omitted, it assumes the default value of 1.

The inverse gamma distribution with parameters shape = a and scale = s has density

f(x)= s^a/Gamma(a) x^(-a-1) e^-(s/x)

for x \ge 0, a > 0 and s > 0. (Here Gamma(a) is the function implemented by R's gamma() and defined in its help. Note that a = 0 corresponds to the trivial distribution with all mass at point 0.)

The mean and variance are E(X) = s/(a - 1) for a>1 and Var(X) = s^2/(a-1)^2/(a-2) for a>2.

The cumulative hazard H(t) = - log(1 - F(t)) is -pinvgamma(t, ..., lower = FALSE, log = TRUE)

Value

dinvgamma gives the density, pinvgamma gives the distribution function, qinvgamma gives the quantile function, and rinvgamma generates random deviates.

Invalid arguments will result in return value NaN, with a warning.

The length of the result is determined by n for rinvgamma, 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.

References

Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis, 3rd edition. CRC press.

See Also

GammaDist

Examples

-log(dinvgamma(1:4, shape = 1))
p <- (1:9)/10
pinvgamma(qinvgamma(p, shape = 2), shape = 2)
1 - 1/exp(qinvgamma(p, shape = 1))

jfrench/bayesutils documentation built on April 10, 2023, 6:28 p.m.