scipy.special.bdtrin#
- scipy.special.bdtrin(k, y, p, out=None) = <ufunc 'bdtrin'>#
Inverse function to
bdtrwith respect to n.Finds the number of events n such that the sum of the terms 0 through k of the Binomial probability density for events with probability p is equal to the given cumulative probability y.
- Parameters:
- karray_like
Number of successes (float).
- yarray_like
Cumulative probability (probability of k or fewer successes in n events).
- parray_like
Success probability (float).
- outndarray, optional
Optional output array for the function values
- Returns:
- nscalar or ndarray
The number of events n such that bdtr(k, n, p) = y.
See also
Notes
This function uses the find_minimum_number_of_trials method of the binomial_distribution class of the Boost.Math C++ library [1].
References
[1]The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.
Examples
What is the largest number of times we can flip a fair coin and still have at least a 90% chance of getting 10 or fewer heads?
bdtrinanswers this question:>>> import scipy.special as sc >>> k = 10 # maximum number of heads >>> p = 0.5 # probability of flipping heads >>> y = 0.9 # cumulative probability >>> result = sc.bdtrin(k, y, p) >>> result np.float64(15.90442928275109)
To verify, compute the cumulative probability of getting 10 or fewer successes in 15 trials with probability 0.5 using the binomial distribution from
scipy.stats. Since the cumulative probability decreases as the number of trials increases, we round down to the nearest integer:>>> from scipy.stats import Binomial >>> Binomial(n=15, p=p).cdf(k) np.float64(0.940765380859375)