BB_LOGBETA
This function computes the natural logarithm of the Beta function for positive shape parameters. In Bayesian conjugate analysis, log-Beta terms are commonly used to evaluate normalizing constants and marginal likelihood components in a numerically stable way.
For a > 0 and b > 0, the quantity is:
\log B(a,b) = \log\left(\frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}\right)
Computing this directly is often unstable for large parameters, so a specialized implementation is preferred.
Excel Usage
=BB_LOGBETA(alpha, beta)
alpha(float, required): First Beta-function shape parameter (positive).beta(float, required): Second Beta-function shape parameter (positive).
Returns (float): Natural logarithm of the Beta function for the supplied parameters.
Example 1: Log-Beta with symmetric shapes
Inputs:
| alpha | beta |
|---|---|
| 3 | 3 |
Excel formula:
=BB_LOGBETA(3, 3)
Expected output:
-3.4012
Example 2: Log-Beta with asymmetric shapes
Inputs:
| alpha | beta |
|---|---|
| 2.5 | 7 |
Excel formula:
=BB_LOGBETA(2.5, 7)
Expected output:
-4.8254
Example 3: Log-Beta for larger parameters
Inputs:
| alpha | beta |
|---|---|
| 40 | 60 |
Excel formula:
=BB_LOGBETA(40, 60)
Expected output:
-67.9686
Example 4: Log-Beta with fractional parameters
Inputs:
| alpha | beta |
|---|---|
| 0.8 | 1.4 |
Excel formula:
=BB_LOGBETA(0.8, 1.4)
Expected output:
-0.0645007
Python Code
from scipy.special import betaln as scipy_betaln
def bb_logbeta(alpha, beta):
"""
Compute the log-Beta term used in conjugate posterior calculations.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.betaln.html
This example function is provided as-is without any representation of accuracy.
Args:
alpha (float): First Beta-function shape parameter (positive).
beta (float): Second Beta-function shape parameter (positive).
Returns:
float: Natural logarithm of the Beta function for the supplied parameters.
"""
try:
alpha = float(alpha)
beta = float(beta)
if alpha <= 0 or beta <= 0:
return "Error: alpha and beta must be positive"
return float(scipy_betaln(alpha, beta))
except Exception as e:
return f"Error: {str(e)}"