invgamma {invgamma} | R Documentation |
The Inverse Gamma Distribution
Description
Density, distribution function, quantile function and random generation for the inverse gamma distribution.
Usage
dinvgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE)
pinvgamma(q, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE)
qinvgamma(p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE)
rinvgamma(n, shape, rate = 1, scale = 1/rate)
Arguments
x , q |
vector of quantiles. |
shape , rate , scale |
|
log , log.p |
logical; if |
lower.tail |
logical; if |
p |
vector of probabilities. |
n |
number of observations. If length(n) > 1, the length is taken to be the number required. |
Details
The inverse gamma distribution with parameters shape and rate has density
f(x) = \frac{rate^{shape}}{\Gamma(shape)} x^{-1-shape} e^{-rate/x}
it
is the inverse of the standard gamma parameterization in R. If X \sim
InvGamma(shape, rate)
,
E[X] = \frac{rate}{shape-1}
when shape > 1
and
Var(X) = \frac{rate^2}{(shape - 1)^2(shape - 2)}
for shape >
2
.
The functions (d/p/q/r)invgamma()
simply wrap those of the standard
(d/p/q/r)gamma()
R implementation, so look at, say, stats::dgamma()
for
details.
See Also
stats::dgamma()
; these functions just wrap the (d/p/q/r)gamma()
functions.
Examples
s <- seq(0, 5, .01)
plot(s, dinvgamma(s, 7, 10), type = 'l')
f <- function(x) dinvgamma(x, 7, 10)
q <- 2
integrate(f, 0, q)
(p <- pinvgamma(q, 7, 10))
qinvgamma(p, 7, 10) # = q
mean(rinvgamma(1e5, 7, 10) <= q)
shape <- 3; rate <- 7
x <- rinvgamma(1e6, shape, rate)
mean(x) # = rate / (shape - 1)
var(x) # = rate^2 / ( (shape - 1)^2 * (shape - 2) )
shape <- 7; rate <- 2.01
x <- rinvgamma(1e6, shape, rate)
mean(x) # = rate / (shape - 1)
var(x) # = rate^2 / ( (shape - 1)^2 * (shape - 2) )
qnorm(log(.25), log.p = TRUE)
qnorm(.25)
qinvgamma(log(.25), shape = shape, rate = rate, log.p = TRUE)
qinvgamma(.25, shape = shape, rate = rate)
## Not run: `rinvgamma()` warns when shape <= .01
rinvgamma(10, .01, rate) # warns
## End(Not run)