betaincinv

mpsci.fun.betaincinv(a, b, y, method='findroot', complement=False)

Inverse of the regularized incomplete beta function.

If complement is True, the inverse of the complement of the regularized incomplete beta function is computed.

The function name and first three parameters match those of scipy.special.betaincinv. With complement=True, the function computes the equivalent of scipy.special.betainccinv.

The method parameter has several options:

  • “findroot”:

    Use mpmath.mp.findroot, with initial guess 0.5.

  • (“findroot”, x0):

    Use mpmath.mp.findroot, with initial guess x0.

  • “bisect”:

    Use a bisection method, starting with the root bracket [0, 1].

  • (“bisect”, [xa, xb]):

    Use a bisection method; start the bisection with the bracket [xa, xb]. xa and xb must be chosen so that the inverse is in the interval [xa, xb].

The numerical method that is used to find the root (either mpmath.mp.findroot or the bisection method) might fail for some inputs. If that happens, try changing the method, or try changing the initial guess or initial bracket.

Examples

>>> from mpmath import mp
>>> from mpsci.fun import betaincinv
>>> mp.dps = 125
>>> a = mp.mpf('0.001')
>>> b = mp.mpf(2500)
>>> y = mp.mpf('0.995')
>>> x = betaincinv(a, b, y, method='bisect)
>>> with mp.workdps(50):
...     print(x)
0.0000015015140517221501171052646134215218978294984794701

Verify the inverse:

>>> y1 = mp.betainc(a, b, 0, x, regularized=True)
>>> with mp.workdps(50):
...    print(y1)
...
0.995