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

InvChiSqR Documentation

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. The implementation uses a non-standard linear scale parameterization of \tau; see Details for the precise definition and its relation to the standard \tau^2 formulation.

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=\frac{\nu}{2} and \beta=\frac{1}{2}; or \alpha=\frac{\nu}{2} and \beta=\frac{\nu\tau}{2}.

Note on parameterization: this implementation uses a linear scaling parameter \tau. The scaled inverse chi-squared distribution is defined via the equivalent inverse-gamma form

X \sim \text{InvGamma}\left(\frac{\nu}{2}, \frac{\nu\tau}{2}\right),

where \tau enters linearly in the second parameter.

This differs from the most common statistical convention, which uses a squared scale parameter \tau^2:

X \sim \text{InvGamma}\left(\frac{\nu}{2}, \frac{\nu\tau^2}{2}\right),

The two parameterizations are related by

\tau_{this implementation} = \tau_{standard}^2.

Users familiar with the standard scaled inverse chi-squared distribution should be aware that \tau here corresponds to a variance-scale parameter rather than a standard-deviation-type parameter.

See Also

Chisquare, GammaDist

Examples


x <- rinvchisq(1e5, 20)
hist(x, 100, freq = FALSE)
curve(dinvchisq(x, 20), 0, 1, n = 501, col = "red", add = TRUE)
hist(pinvchisq(x, 20))
plot(ecdf(x))
curve(pinvchisq(x, 20), 0, 1, n = 501, col = "red", lwd = 2, add = TRUE)

# scaled

x <- rinvchisq(1e5, 10, 5)
hist(x, 100, freq = FALSE)
curve(dinvchisq(x, 10, 5), 0, 150, n = 501, col = "red", add = TRUE)
hist(pinvchisq(x, 10, 5))
plot(ecdf(x))
curve(pinvchisq(x, 10, 5), 0, 150, n = 501, col = "red", lwd = 2, add = TRUE)


extraDistr documentation built on May 18, 2026, 5:10 p.m.