# naginterfaces.library.univar.ci_​binomial¶

naginterfaces.library.univar.ci_binomial(n, k, clevel)[source]

ci_binomial computes a confidence interval for the parameter (the probability of a success) of a binomial distribution.

For full information please refer to the NAG Library document for g07aa

https://support.nag.com/numeric/nl/nagdoc_30/flhtml/g07/g07aaf.html

Parameters
nint

, the number of trials.

kint

, the number of successes.

clevelfloat

The confidence level, , for two-sided interval estimate. For example will give a confidence interval.

Returns
plfloat

The lower limit, , of the confidence interval.

pufloat

The upper limit, , of the confidence interval.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

When using the relationship with the gamma distribution the series to calculate the gamma probabilities has failed to converge.

Notes

Given the number of trials, , and the number of successes, , this function computes a confidence interval for , the probability parameter of a binomial distribution with probability function,

where is in the interval .

Let the confidence interval be denoted by [].

The point estimate for is .

The lower and upper confidence limits and are estimated by the solutions to the equations;

Three different methods are used depending on the number of trials, , and the number of successes, .

1. If .

The relationship between the beta and binomial distributions (see page 38 of Hastings and Peacock (1975)) is used to derive the equivalent equations,

where is the deviate associated with the lower tail probability, , of the beta distribution with parameters and . These beta deviates are computed using stat.inv_cdf_beta.

2. If and .

The binomial variate with parameters and is approximated by a Poisson variate with mean , see page 38 of Hastings and Peacock (1975).

The relationship between the Poisson and -distributions (see page 112 of Hastings and Peacock (1975)) is used to derive the following equations;

where is the deviate associated with the lower tail probability, , of the -distribution with degrees of freedom.

In turn the relationship between the -distribution and the gamma distribution (see page 70 of Hastings and Peacock (1975)) yields the following equivalent equations;

where is the deviate associated with the lower tail probability, , of the gamma distribution with shape parameter and scale parameter . These deviates are computed using stat.inv_cdf_gamma.

3. If and .

The binomial variate with parameters and is approximated by a Normal variate with mean and variance , see page 38 of Hastings and Peacock (1975).

The approximate lower and upper confidence limits and are the solutions to the equations;

where is the deviate associated with the lower tail probability, , of the standard Normal distribution. These equations are solved using a quadratic equation solver (zeros.quadratic_real).

References

Hastings, N A J and Peacock, J B, 1975, Statistical Distributions, Butterworth

Snedecor, G W and Cochran, W G, 1967, Statistical Methods, Iowa State University Press