Skip to contents

Computes the log of the Beta function, \(\log B(a, b) = \log\Gamma(a) + \log\Gamma(b) - \log\Gamma(a+b)\), elementwise, via three calls into fast_lgamma_vec_cpp's kernel rather than R's own lgamma dispatch — faster than base R's lbeta — measured at 2.43x on a length-5000 vector (see the "Utility / Math Kernel Performance" benchmark report) — while returning numerically identical values (up to the Lanczos/Stirling approximation's own precision). Used internally inside the package's beta-regression and beta-distribution-based (zero-one-inflated beta) likelihood, score, and Hessian kernels, wherever a Beta-density normalizing constant is required.

Usage

fast_lbeta_vec_cpp(a, b)

Arguments

a

Numeric vector of first shape arguments (should be positive; not validated by this function).

b

Numeric vector of second shape arguments (should be positive; not validated), recycled against a elementwise — must be the same length as a; unlike R's own vectorized arithmetic, this function does not perform R-style shorter-vector recycling.

Value

A numeric vector of \(\log B(a, b)\) values, the same length as a/b.

References

Beta function for orientation. Analogous Python API: SciPy betaln.

See also

fast_lgamma_vec_cpp, whose kernel this function calls.