Binomial distribution

mpsci.distributions.binomial.cdf(k, n, p, method='incbeta')

Cumulative distribution function of the binomial distribution.

method must be either “sumpmf” or “incbeta”. When method is “sumpmf”, the CDF is computed with a simple sum of the PMF values. When method is “incbeta”, the incomplete beta function is used. This method is generally faster than the “sumpmf” method, but for large values of k or n, the incomplete beta function of mpmath might fail.

mpsci.distributions.binomial.logpmf(k, n, p)

Natural log of the probability mass function of the binomial distribution.

mpsci.distributions.binomial.mean(n, p)

Mean of the binomial distribution.

mpsci.distributions.binomial.mle(x, *, counts=None, n=None, p=None)

Maximum likelihood estimation for the binomial distribution.

x must be a sequence of nonnegative integers.

Returns n (an integer) and p (a probability).

Note

When the parameter n is not fixed, the robustness of the numerical solution depends on the input data x. For some x, the solver is likely to fail.

Examples

>>> from mpmath import mp
>>> from mpsci.distributions import binomial
>>> mp.dps = 50
>>> x = [7, 9, 10, 10, 11, 12, 12, 13, 13, 14, 15, 15]
>>> n, p = binomial.mle(x, n=16)
>>> p
mpf('0.734375')
mpsci.distributions.binomial.nll(x, n, p, *, counts=None)

Negative log-likelihood of the binomial distribution.

x must be a sequence of nonnegative integers, with 0 <= x[i] <= n.

mpsci.distributions.binomial.pmf(k, n, p)

Probability mass function of the binomial distribution.

mpsci.distributions.binomial.sf(k, n, p, method='incbeta')

Survival function of the binomial distribution.

method must be either “sumpmf” or “incbeta”. When method is “sumpmf”, the survival function is computed with a simple sum of the PMF values. When method is “incbeta”, the incomplete beta function is used. This method is generally faster than the “sumpmf” method, but for large values of k or n, the incomplete beta function of mpmath might fail.

mpsci.distributions.binomial.support(n, p)

Support of the binomial distribution.

The support is the integers 0, 1, 2, …, n; this is implemented by returning range(n + 1). That is, the return value is the range instance, not a sequence.

Examples

>>> from mpsci.distributions import binomial
>>> sup = binomial.support(5, 0.25)
>>> [k for k in sup]
[0, 1, 2, 3, 4, 5]
mpsci.distributions.binomial.var(n, p)

Variance of the binomial distribution.