BB_QBETA
This function returns the quantile of a Beta distribution using posterior hyperparameters from a Beta-Binomial model. It is useful for converting posterior parameters into a percentile-based summary such as a credible bound.
Given posterior parameters \alpha and \beta, and probability level p \in [0,1], it computes x such that:
I_x(\alpha, \beta) = p
where I_x is the regularized incomplete beta function.
Excel Usage
=BB_QBETA(alpha, beta, prob)
alpha(float, required): Posterior alpha hyperparameter (positive).beta(float, required): Posterior beta hyperparameter (positive).prob(float, required): Target cumulative probability level in [0, 1].
Returns (float): Quantile value in [0, 1] for the specified posterior probability level.
Example 1: Median quantile for balanced posterior
Inputs:
| alpha | beta | prob |
|---|---|---|
| 5 | 5 | 0.5 |
Excel formula:
=BB_QBETA(5, 5, 0.5)
Expected output:
0.5
Example 2: Upper credible bound quantile
Inputs:
| alpha | beta | prob |
|---|---|---|
| 12 | 8 | 0.95 |
Excel formula:
=BB_QBETA(12, 8, 0.95)
Expected output:
0.770279
Example 3: Quantile for left-skewed posterior
Inputs:
| alpha | beta | prob |
|---|---|---|
| 2 | 10 | 0.8 |
Excel formula:
=BB_QBETA(2, 10, 0.8)
Expected output:
0.248602
Example 4: Quantile for right-skewed posterior
Inputs:
| alpha | beta | prob |
|---|---|---|
| 10 | 2 | 0.2 |
Excel formula:
=BB_QBETA(10, 2, 0.2)
Expected output:
0.751398
Python Code
from scipy.special import betaincinv as scipy_betaincinv
def bb_qbeta(alpha, beta, prob):
"""
Compute a Beta posterior quantile for Beta-Binomial models.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.betaincinv.html
This example function is provided as-is without any representation of accuracy.
Args:
alpha (float): Posterior alpha hyperparameter (positive).
beta (float): Posterior beta hyperparameter (positive).
prob (float): Target cumulative probability level in [0, 1].
Returns:
float: Quantile value in [0, 1] for the specified posterior probability level.
"""
try:
alpha = float(alpha)
beta = float(beta)
prob = float(prob)
if alpha <= 0 or beta <= 0:
return "Error: alpha and beta must be positive"
if prob < 0 or prob > 1:
return "Error: prob must be between 0 and 1"
return float(scipy_betaincinv(alpha, beta, prob))
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Posterior alpha hyperparameter (positive).
Posterior beta hyperparameter (positive).
Target cumulative probability level in [0, 1].