binomialCdf

Evaluates the binomial distribution function.

Synopsis

binomialCdf (k, n, p)

Required Arguments

int k (Input)
Argument for which the binomial distribution function is to be evaluated.
int n (Input)
Number of Bernoulli trials.
float p (Input)
Probability of success on each trial.

Return Value

The probability that k or fewer successes occur in n independent Bernoulli trials, each of which has a probability p of success.

Description

The binomialCdf function evaluates the distribution function of a binomial random variable with parameters n and p. It does this by summing probabilities of the random variable taking on the specific values in its range. These probabilities are computed by the recursive relationship:

\[\Pr(X=j) = \frac{(n+1-j)p}{j(1-p)} \Pr(X=j-1)\]

such that:

\[F(k|n,p) = \sum_{i=0}^{k} \Pr(X=j)\]

To avoid the possibility of underflow, the probabilities are computed forward from 0 if k is not greater than n × p; otherwise, they are computed backward from n. The smallest positive machine number, ɛ, is used as the starting value for summing the probabilities, which are rescaled by \((1-\text{p})^n \varepsilon\) if forward computation is performed and by \(\text{p}^n \varepsilon\) if backward computation is used.

For the special case of p = 0, binomialCdf is set to 1; for the case p = 1, binomialCdf is set to 1 if k = n and is set to 0 otherwise.

Example

Suppose X is a binomial random variable with \(n=5\) and \(p=0.95\). In this example, the function finds the probability that X is less than or equal to 3.

from __future__ import print_function
from numpy import *
from pyimsl.stat.binomialCdf import binomialCdf

k = 3
n = 5
p = 0.95
pr = binomialCdf(k, n, p)
print("Pr(x <= 3) = %6.4f" % pr)

Output

Pr(x <= 3) = 0.0226

Informational Errors

IMSLS_LESS_THAN_ZERO Since “k” = # is less than zero, the distribution function is set to zero.
IMSLS_GREATER_THAN_N The input argument, k, is greater than the number of Bernoulli trials, n.