Skip to main content
`Ctrl`+`K`

# scipy.special.betainc

scipy.special.betainc(a, b, x, out=None) = <ufunc 'betainc'>

  Regularized incomplete beta function.

  Computes the regularized incomplete beta function, defined as [1]:

  \[I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x t^{a-1}(1-t)^{b-1}dt,\]

  for \(0 \leq x \leq 1\).

  This function is the cumulative distribution function for the beta distribution; its range is [0, 1].

  Parameters:
    a, b array_like

      Positive, real-valued parameters

    x array_like

      Real-valued such that \(0 \leq x \leq 1\), the upper limit of integration

    out ndarray, optional

      Optional output array for the function values

  Returns:
    scalar or ndarray

      Value of the regularized incomplete beta function

  See also

  `beta`

    beta function

  `betaincinv`

    inverse of the regularized incomplete beta function

  `betaincc`

    complement of the regularized incomplete beta function

  `scipy.stats.beta`

    beta distribution

  Notes

  The term regularized in the name of this function refers to the scaling of the function by the gamma function terms shown in the formula. When not qualified as regularized, the name incomplete beta function often refers to just the integral expression, without the gamma terms. One can use the function `beta` from `scipy.special` to get this “nonregularized” incomplete beta function by multiplying the result of `betainc(a, b, x)` by `beta(a, b)`.

  `betainc(a, b, x)` is treated as a two parameter family of functions of a single variable x, rather than as a function of three variables. This impacts only the limiting cases `a = 0`, `b = 0`, `a = inf`, `b = inf`.

  In general

  \[\lim_{(a, b) \rightarrow (a_0, b_0)} \mathrm{betainc}(a, b, x)\]

  is treated as a pointwise limit in `x`. Thus for example, `betainc(0, b, 0)` equals `0` for `b > 0`, although it would be indeterminate when considering the simultaneous limit `(a, x) -> (0+, 0+)`.

  This function wraps the `ibeta` routine from the Boost Math C++ library [2].

  `betainc` has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable `SCIPY_ARRAY_API=1` and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

  Library | CPU | GPU
  --- | --- | ---
  NumPy | ✅ | n/a
  CuPy | n/a | ✅
  PyTorch | ✅ | ⛔
  JAX | ✅ | ✅
  Dask | ✅ | n/a

  See Support for the array API standard for more information.

  References

  [1]

  NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/8.17

  [2]

  The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.

  Examples

  Let \(B(a, b)\) be the `beta` function.

      >>> import scipy.special as sc

  The coefficient in terms of `gamma` is equal to \(1/B(a, b)\). Also, when \(x=1\) the integral is equal to \(B(a, b)\). Therefore, \(I_{x=1}(a, b) = 1\) for any \(a, b\).

      >>> sc.betainc(0.2, 3.5, 1.0)
      1.0

  It satisfies \(I_x(a, b) = x^a F(a, 1-b, a+1, x)/ (aB(a, b))\), where \(F\) is the hypergeometric function `hyp2f1`:

      >>> a, b, x = 1.4, 3.1, 0.5
      >>> x**a * sc.hyp2f1(a, 1 - b, a + 1, x)/(a * sc.beta(a, b))
      0.8148904036225295
      >>> sc.betainc(a, b, x)
      0.8148904036225296

  This functions satisfies the relationship \(I_x(a, b) = 1 - I_{1-x}(b, a)\):

      >>> sc.betainc(2.2, 3.1, 0.4)
      0.49339638807619446
      >>> 1 - sc.betainc(3.1, 2.2, 1 - 0.4)
      0.49339638807619446