InvGamma_ct: The Central Inverse-Gamma Distribution

InvGamma_ctR Documentation

The Central Inverse-Gamma Distribution

Description

Distribution function, quantile function, and random generation for the inverse-Gamma distribution on the dispersion scale. These functions provide numerically stable evaluation and sampling when the dispersion parameter is restricted to lie between a lower and an upper bound.

Usage

pinvgamma_ct(dispersion, shape, rate)

qinvgamma_ct(p, shape, rate, disp_upper, disp_lower)

rinvgamma_ct(n, shape, rate, disp_upper, disp_lower)

Arguments

dispersion

Value(s) at which the inverse-Gamma distribution function is evaluated.

shape

Shape parameter of the inverse-Gamma distribution.

rate

Rate parameter of the inverse-Gamma distribution.

p

Probability value(s) for the quantile function.

disp_upper

Upper bound of the dispersion parameter.

disp_lower

Lower bound of the dispersion parameter.

n

Number of random draws to generate. If length(n) > 1, the length is taken to be the number required.

Details

The inverse-Gamma distribution is defined by the transformation D = 1 / X, where X follows a Gamma distribution with the same shape and rate parameters. The functions pinvgamma_ct and qinvgamma_ct therefore compute probabilities and quantiles by mapping the dispersion value D to the corresponding Gamma scale and applying the Gamma CDF or quantile function.

The function rinvgamma_ct generates random draws from a truncated inverse-Gamma distribution by sampling a uniform probability and inverting the truncated CDF on the Gamma scale. This approach avoids numerical instability when the truncation interval is narrow or when the dispersion parameter is close to zero.

These functions are primarily intended for hierarchical Bayesian models in which dispersion parameters are updated under tight truncation constraints. They provide a stable alternative to direct manipulation of the Gamma distribution when working on the dispersion scale is more natural or more numerically robust. They are used in envelope-based dispersion sampling \insertCiteNygren2006glmbayes.

Value

For pinvgamma_ct, a vector of distribution function values evaluated at dispersion. For qinvgamma_ct, a vector of quantiles corresponding to the probabilities p. For rinvgamma_ct, a vector of length n containing random draws from the inverse-Gamma distribution restricted to the interval [disp_lower, disp_upper].

References

\insertAllCited

See Also

Gamma_ct, Normal_ct, EnvelopeDispersionBuild

Examples

############################### Start of InvGamma_ct example ####################

## pinvgamma_ct: CDF on the dispersion scale
shape <- 2
rate  <- 1
pinvgamma_ct(1.5, shape, rate)

## Equivalent via pgamma on the precision scale
1 - pgamma(1 / 1.5, shape, rate)

## Example where interval mass pinvgamma_ct(disp_upper) - pinvgamma_ct(disp_lower)
## fails due to catastrophic cancellation when bounds are very close
disp_lower <- 0.999
disp_upper <- 0.999 + 1e-14
pinvgamma_ct(disp_upper, shape, rate) - pinvgamma_ct(disp_lower, shape, rate)

## On the precision scale this is pgamma(1/disp_lower) - pgamma(1/disp_upper);
## the same cancellation affects the Gamma CDF when precision bounds are close

## rinvgamma_ct samples from truncated inverse-Gamma on the dispersion scale
disp_lower <- 0.99
disp_upper <- 1.01
set.seed(42)
y <- rinvgamma_ct(100, shape = 2, rate = 1,
                  disp_upper = disp_upper, disp_lower = disp_lower)
range(y)
mean(y)

###############################################################################
## End of InvGamma_ct example
###############################################################################

glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.

Related to InvGamma_ct in glmbayes...