ibetaReg function

double ibetaReg(
  1. double a,
  2. double b,
  3. double x
)

The regularized incomplete beta function. See: https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function

Implementation

double ibetaReg(double a, double b, double x) {
  if (x == 0.0) {
    return 0.0;
  }
  if (x == 1.0) {
    return 1.0;
  }
  final double lab = lgamma(a + b).lgamma;
  final double la = lgamma(a).lgamma;
  final double lb = lgamma(b).lgamma;
  final lbeta = lab - la - lb + (a * math.log(x)) + (b * math.log(1 - x));
  if (x < (a + 1) / (a + b + 2)) {
    return math.exp(lbeta) * _contFracBeta(a, b, x) / a;
  }
  return 1 - math.exp(lbeta) * _contFracBeta(b, a, 1 - x) / b;
}