GAMMA_POST_Q

This function returns a quantile from a Gamma posterior distribution parameterized by shape and rate. It is useful for extracting credible bounds for positive-rate parameters in conjugate Bayesian models such as Poisson-Gamma and Exponential-Gamma setups.

With shape \alpha, rate \beta, and probability level p, the quantile q_p satisfies:

P(X \le q_p) = p, \quad X \sim \text{Gamma}(\alpha, \text{rate}=\beta)

In SciPy, this is evaluated with scale \theta = 1/\beta.

Excel Usage

=GAMMA_POST_Q(shape, rate, prob)
  • shape (float, required): Gamma shape parameter (positive).
  • rate (float, required): Gamma rate parameter (positive, reciprocal of scale).
  • prob (float, required): Target cumulative probability level in [0, 1].

Returns (float): Gamma posterior quantile for the requested probability level.

Example 1: Median for Poisson-rate style posterior

Inputs:

shape rate prob
6 3 0.5

Excel formula:

=GAMMA_POST_Q(6, 3, 0.5)

Expected output:

1.89005

Example 2: Upper quantile for concentrated posterior

Inputs:

shape rate prob
25 10 0.95

Excel formula:

=GAMMA_POST_Q(25, 10, 0.95)

Expected output:

3.37524

Example 3: Lower quantile for dispersed posterior

Inputs:

shape rate prob
2.2 1.1 0.1

Excel formula:

=GAMMA_POST_Q(2.2, 1.1, 0.1)

Expected output:

0.579818

Example 4: Intermediate quantile with fractional shape

Inputs:

shape rate prob
3.5 2.7 0.7

Excel formula:

=GAMMA_POST_Q(3.5, 2.7, 0.7)

Expected output:

1.55249

Python Code

from scipy.stats import gamma as scipy_gamma

def gamma_post_q(shape, rate, prob):
    """
    Compute a Gamma posterior quantile from shape-rate parameters.

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

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

    Args:
        shape (float): Gamma shape parameter (positive).
        rate (float): Gamma rate parameter (positive, reciprocal of scale).
        prob (float): Target cumulative probability level in [0, 1].

    Returns:
        float: Gamma posterior quantile for the requested probability level.
    """
    try:
        shape = float(shape)
        rate = float(rate)
        prob = float(prob)

        if shape <= 0 or rate <= 0:
            return "Error: shape and rate must be positive"
        if prob < 0 or prob > 1:
            return "Error: prob must be between 0 and 1"

        return float(scipy_gamma.ppf(prob, a=shape, scale=1.0 / rate))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Gamma shape parameter (positive).
Gamma rate parameter (positive, reciprocal of scale).
Target cumulative probability level in [0, 1].