INVGAMMA_CI_BOUNDS

This function computes posterior credible interval endpoints for a positive parameter modeled with an Inverse-Gamma posterior distribution.

If \theta \mid \text{data} \sim \mathrm{InvGamma}(\alpha, \beta) with shape \alpha and scale \beta, interval bounds are extracted from posterior quantiles at equal tails.

For confidence level c, the interval is:

[\theta_L, \theta_U] = [Q((1-c)/2),\; Q(1-(1-c)/2)]

where Q is the Inverse-Gamma quantile function.

Excel Usage

=INVGAMMA_CI_BOUNDS(shape, scale, confidence)
  • shape (float, required): Posterior Inverse-Gamma shape parameter alpha (unitless).
  • scale (float, required): Posterior Inverse-Gamma scale parameter beta (squared unit).
  • confidence (float, optional, default: 0.95): Credible interval probability level (0 to 1).

Returns (list[list]): 2D table with posterior mean when defined and lower/upper credible bounds.

Example 1: Typical inverse-gamma posterior interval

Inputs:

shape scale confidence
6 9 0.95

Excel formula:

=INVGAMMA_CI_BOUNDS(6, 9, 0.95)

Expected output:

Mean Lower Upper
1.8 0.771318 4.08739
Example 2: Tighter interval with higher shape

Inputs:

shape scale confidence
20 30 0.9

Excel formula:

=INVGAMMA_CI_BOUNDS(20, 30, 0.9)

Expected output:

Mean Lower Upper
1.57895 1.07607 2.26336
Example 3: Shape above one keeps finite posterior mean

Inputs:

shape scale confidence
1.2 2.5 0.95

Excel formula:

=INVGAMMA_CI_BOUNDS(1.2, 2.5, 0.95)

Expected output:

Mean Lower Upper
12.5 0.610148 48.7319
Example 4: High-confidence inverse-gamma interval

Inputs:

shape scale confidence
10 8 0.99

Excel formula:

=INVGAMMA_CI_BOUNDS(10, 8, 0.99)

Expected output:

Mean Lower Upper
0.888889 0.400032 2.15232

Python Code

from scipy.stats import invgamma as scipy_invgamma

def invgamma_ci_bounds(shape, scale, confidence=0.95):
    """
    Compute an equal-tailed Bayesian credible interval for a positive scale or variance parameter using Inverse-Gamma quantiles.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.invgamma.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        shape (float): Posterior Inverse-Gamma shape parameter alpha (unitless).
        scale (float): Posterior Inverse-Gamma scale parameter beta (squared unit).
        confidence (float, optional): Credible interval probability level (0 to 1). Default is 0.95.

    Returns:
        list[list]: 2D table with posterior mean when defined and lower/upper credible bounds.
    """
    try:
        if shape <= 0:
            return "Error: shape must be greater than 0"

        if scale <= 0:
            return "Error: scale must be greater than 0"

        if not (0 < confidence < 1):
            return "Error: confidence must be between 0 and 1"

        tail_probability = (1 - confidence) / 2

        lower = float(scipy_invgamma.ppf(tail_probability, a=shape, scale=scale))
        upper = float(scipy_invgamma.ppf(1 - tail_probability, a=shape, scale=scale))
        mean = float(scale / (shape - 1)) if shape > 1 else ""

        return [
            ["Mean", "Lower", "Upper"],
            [mean, lower, upper]
        ]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Posterior Inverse-Gamma shape parameter alpha (unitless).
Posterior Inverse-Gamma scale parameter beta (squared unit).
Credible interval probability level (0 to 1).