InvChisquare: The (scaled) Inverse Chi-squared Distribution

InvChisquareR Documentation

The (scaled) Inverse Chi-squared Distribution

Description

Density, distribution function, quantile function, and random generation for the (scaled) inverse chi-square distribution with df degrees of freedom and optional parameter scale. The parameterization is consistent with Gelman et al. (2013). By default, the scale is set to return results for the inverse chi-square distribution. If scale is changed, then the results are returned for the scaled inverse chi-squared distribution.

Usage

rinvchisq(n, df, scale = 1/df)

dinvchisq(x, df, scale = 1/df, log = FALSE)

pinvchisq(q, df, scale = 1/df, lower.tail = TRUE, log.p = FALSE)

qinvchisq(p, df, scale = 1/df, lower.tail = TRUE, log.p = FALSE)

Arguments

n

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

df

degrees of freedom (non-negative, but can be non-integer).

scale

a scale parameter.

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/df.

The scaled inverse chi-square distribution with parameters df = n and scale = s^2 has density

f(x)= (2^{-n/2}/Gamma(n/2)s^n x^(-n/2 - 1) e^(-n s^2/(2x))

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

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

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

Value

dinvchisq gives the density, pinvchisq gives the distribution function, qinvchisq gives the quantile function, and rinvchisq generates random deviates.

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

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

Chisquare

Examples

x = 1:10
## InvChisquare(df = n) is a special case of
## InvGamma(shape = n/2, scale = 1/2)
n = 3
all.equal(dinvchisq(x, df = n),
          dinvgamma(x, shape = n/2, scale = 1/2))
all.equal(pinvchisq(x, df = n),
          pinvgamma(x, shape = n/2, scale = 1/2))

## InvChisquare(df = n, scale = s^2) is a special case of
## InvGamma(shape = n/2, scale = n/2 * s^2)
s = 1.7
all.equal(dinvchisq(x, df = n, scale = s^2),
          dinvgamma(x, shape = n/2, scale = n/2 * s^2))
all.equal(pinvchisq(x, df = n, scale = s^2),
          pinvgamma(x, shape = n/2, scale = n/2 * s^2))

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