Learn R Programming

extraDistr (version 1.8.1)

InvChiSq: Inverse chi-squared and scaled chi-squared distributions

Description

Density, distribution function and random generation for the inverse chi-squared distribution and scaled chi-squared distribution.

Usage

dinvchisq(x, nu, tau, log = FALSE)
pinvchisq(q, nu, tau, lower.tail = TRUE, log.p = FALSE)
qinvchisq(p, nu, tau, lower.tail = TRUE, log.p = FALSE)
rinvchisq(n, nu, tau)

Arguments

x, q
vector of quantiles.
nu
positive valued shape parameter.
tau
positive valued scaling parameter; if provided it returns values for scaled chi-squared distributions.
log, log.p
logical; if TRUE, probabilities p are given as log(p).
lower.tail
logical; if TRUE (default), probabilities are $P[X \le x]$ otherwise, $P[X > x]$.
p
vector of probabilities.
n
number of observations. If length(n) > 1, the length is taken to be the number required.

Details

If $X$ follows $\chi^2 (\nu)$ distribution, then $1/X$ follows inverse chi-squared distribution parametrized by $\nu$. Inverse chi-squared distribution is a special case of inverse gamma distribution with parameters $\alpha=\nu/2$ and $\beta=1/2$; or $\alpha=\nu/2$ and $\beta=(\nu\tau^2)/2$ for scaled inverse chi-squared distribution.

See Also

Chisquare, GammaDist

Examples

Run this code

x <- rinvchisq(1e5, 20)
xx <- seq(0, 6, by = 0.001)
hist(x, 100, freq = FALSE)
lines(xx, dinvchisq(xx, 20), col = "red")
hist(pinvchisq(x, 20))
plot(ecdf(x))
lines(xx, pinvchisq(xx, 20), col = "red", lwd = 2)

# scaled

x <- rinvchisq(1e5, 10, 5)
xx <- seq(0, 700, by = 0.01)
hist(x, 100, freq = FALSE)
lines(xx, dinvchisq(xx, 10, 5), col = "red")
hist(pinvchisq(x, 10, 5))
plot(ecdf(x))
lines(xx, pinvchisq(xx, 10, 5), col = "red", lwd = 2)

Run the code above in your browser using DataLab