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 function binomialCdf 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)\]

To avoid the possibility of underflow, the probabilities are computed forward from zero 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-p)^n \varepsilon\) if forward computation is performed and by \(p^n \varepsilon\) if backward computation is done.

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

Example

Suppose X is a binomial random variable with an \(n=5\) and a \(p=0.95\). This example finds the probability that X is less than or equal to three.

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

k = 3
n = 5
p = 0.95

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

Output

Pr(x <= 3) = 0.0226

Informational Errors

IMSL_LESS_THAN_ZERO The input argument, k, is less than zero.
IMSL_GREATER_THAN_N The input argument, k, is greater than the number of Bernoulli trials, n.