scipy.special.nbdtrin#
- scipy.special.nbdtrin(k, y, p, out=None) = <wrapped_ufunc 'nbdtrin'>#
Inverse of
nbdtrvs n.Returns the inverse with respect to the parameter n of
y = nbdtr(k, n, p), the negative binomial cumulative distribution function.- Parameters:
- karray_like
The maximum number of allowed failures (nonnegative int).
- yarray_like
The probability of k or fewer failures before n successes (float).
- parray_like
Probability of success in a single event (float).
- outndarray, optional
Optional output array for the function results
- Returns:
- nscalar or ndarray
The number of successes n such that nbdtr(k, n, p) = y.
See also
Notes
This function wraps routines from the Boost Math C++ library [1].
Formula 26.5.26 of [2] or [3],
\[\sum_{j=k + 1}^\infty {{n + j - 1} \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),\]is used to reduce calculation of the cumulative distribution function to that of a regularized incomplete beta \(I\).
Computation of n involves a search for a value that produces the desired value of y. The search relies on the monotonicity of y with n.
Array API Standard Support
nbdtrinhas support for Python Array API Standard compatible backends in addition to NumPy. 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
For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support
out, but typically none of the other ufunc kwargs.outis typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend.outis never supported for JAX because JAX arrays are immutable.nbdtrindoes not currently supportoutfor the PyTorch backend.See Array API coverage for more information.
References
[1]The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.
[2]Milton Abramowitz and Irene A. Stegun, eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972.
[3]NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/8.17.E24
Examples
Compute the negative binomial cumulative distribution function for an exemplary parameter set.
>>> from scipy.special import nbdtr, nbdtrin >>> k, n, p = 5, 2, 0.5 >>> cdf_value = nbdtr(k, n, p) >>> cdf_value 0.9375
Verify that
nbdtrinrecovers the original value for n up to floating point accuracy.>>> nbdtrin(k, cdf_value, p) 2.0