| Title: | The Inverse Gamma Distribution |
|---|---|
| Description: | Light weight implementation of the standard distribution functions for the inverse gamma distribution, wrapping those for the gamma distribution in the stats package. |
| Authors: | David Kahle [aut, cre, cph], James Stamey [aut, cph] |
| Maintainer: | David Kahle <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.900 |
| Built: | 2026-05-22 18:51:08 UTC |
| Source: | https://github.com/dkahle/invgamma |
Density, distribution function, quantile function and random generation for the inverse chi-squared distribution.
dinvchisq(x, df, ncp = 0, log = FALSE) pinvchisq(q, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) qinvchisq(p, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) rinvchisq(n, df, ncp = 0)dinvchisq(x, df, ncp = 0, log = FALSE) pinvchisq(q, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) qinvchisq(p, df, ncp = 0, lower.tail = TRUE, log.p = FALSE) rinvchisq(n, df, ncp = 0)
x, q
|
vector of quantiles. |
df |
degrees of freedom (non-negative, but can be non-integer). |
ncp |
non-centrality parameter (non-negative). |
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. |
The functions (d/p/q/r)invchisq() simply wrap those of the standard
(d/p/q/r)chisq() R implementation, so look at, say, stats::dchisq() for
details.
stats::dchisq(); these functions just wrap the (d/p/q/r)chisq()
functions.
s <- seq(0, 3, .01) plot(s, dinvchisq(s, 3), type = 'l') f <- function(x) dinvchisq(x, 3) q <- 2 integrate(f, 0, q) (p <- pinvchisq(q, 3)) qinvchisq(p, 3) # = q mean(rinvchisq(1e5, 3) <= q) f <- function(x) dinvchisq(x, 3, ncp = 2) q <- 1.5 integrate(f, 0, q) (p <- pinvchisq(q, 3, ncp = 2)) qinvchisq(p, 3, ncp = 2) # = q mean(rinvchisq(1e7, 3, ncp = 2) <= q)s <- seq(0, 3, .01) plot(s, dinvchisq(s, 3), type = 'l') f <- function(x) dinvchisq(x, 3) q <- 2 integrate(f, 0, q) (p <- pinvchisq(q, 3)) qinvchisq(p, 3) # = q mean(rinvchisq(1e5, 3) <= q) f <- function(x) dinvchisq(x, 3, ncp = 2) q <- 1.5 integrate(f, 0, q) (p <- pinvchisq(q, 3, ncp = 2)) qinvchisq(p, 3, ncp = 2) # = q mean(rinvchisq(1e7, 3, ncp = 2) <= q)
Density, distribution function, quantile function and random generation for the inverse exponential distribution.
dinvexp(x, rate = 1, log = FALSE) pinvexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE) qinvexp(p, rate = 1, lower.tail = TRUE, log.p = FALSE) rinvexp(n, rate = 1)dinvexp(x, rate = 1, log = FALSE) pinvexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE) qinvexp(p, rate = 1, lower.tail = TRUE, log.p = FALSE) rinvexp(n, rate = 1)
x, q
|
vector of quantiles. |
rate |
degrees of freedom (non-negative, but can be non-integer). |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
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. |
The functions (d/p/q/r)invexp() simply wrap those of the standard
(d/p/q/r)exp() R implementation, so look at, say, stats::dexp() for
details.
stats::dexp(); these functions just wrap the (d/p/q/r)exp()
functions.
s <- seq(0, 10, .01) plot(s, dinvexp(s, 2), type = 'l') f <- function(x) dinvexp(x, 2) q <- 3 integrate(f, 0, q) (p <- pinvexp(q, 2)) qinvexp(p, 2) # = q mean(rinvexp(1e5, 2) <= q) pinvgamma(q, 1, 2)s <- seq(0, 10, .01) plot(s, dinvexp(s, 2), type = 'l') f <- function(x) dinvexp(x, 2) q <- 3 integrate(f, 0, q) (p <- pinvexp(q, 2)) qinvexp(p, 2) # = q mean(rinvexp(1e5, 2) <= q) pinvgamma(q, 1, 2)
Density, distribution function, quantile function and random generation for the inverse gamma distribution.
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)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)
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. |
The inverse gamma distribution with parameters shape and rate has density
it
is the inverse of the standard gamma parameterization in R. If ,
when
and
for .
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.
stats::dgamma(); these functions just wrap the (d/p/q/r)gamma()
functions.
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)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)