nag_binomial_dist (g01bjc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_binomial_dist (g01bjc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_binomial_dist (g01bjc) returns the lower tail, upper tail and point probabilities associated with a binomial distribution.

2  Specification

#include <nag.h>
#include <nagg01.h>
void  nag_binomial_dist (Integer n, double p, Integer k, double *plek, double *pgtk, double *peqk, NagError *fail)

3  Description

Let X denote a random variable having a binomial distribution with parameters n and p (n0 and 0<p<1). Then
ProbX=k= n k pk1-pn-k,  k=0,1,,n.
The mean of the distribution is np and the variance is np1-p.
nag_binomial_dist (g01bjc) computes for given n, p and k the probabilities:
plek=ProbXk pgtk=ProbX>k peqk=ProbX=k .
The method is similar to the method for the Poisson distribution described in Knüsel (1986).

4  References

Knüsel L (1986) Computation of the chi-square and Poisson distribution SIAM J. Sci. Statist. Comput. 7 1022–1036

5  Arguments

1:     nIntegerInput
On entry: the parameter n of the binomial distribution.
Constraint: n0.
2:     pdoubleInput
On entry: the parameter p of the binomial distribution.
Constraint: 0.0<p<1.0.
3:     kIntegerInput
On entry: the integer k which defines the required probabilities.
Constraint: 0kn.
4:     plekdouble *Output
On exit: the lower tail probability, ProbXk.
5:     pgtkdouble *Output
On exit: the upper tail probability, ProbX>k.
6:     peqkdouble *Output
On exit: the point probability, ProbX=k.
7:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

On entry, k=value and n=value.
Constraint: k or n.
On entry, n is too large to be represented exactly as a double precision number.
On entry, argument value had an illegal value.
On entry, k=value.
Constraint: k0.
On entry, n=value.
Constraint: n0.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
On entry, p=value.
Constraint: p<1.0.
On entry, p=value.
Constraint: p>0.0.
On entry, the variance = np 1-p  exceeds 10 6 .

7  Accuracy

Results are correct to a relative accuracy of at least 10-6 on machines with a precision of 9 or more decimal digits, and to a relative accuracy of at least 10-3 on machines of lower precision (provided that the results do not underflow to zero).

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by nag_binomial_dist (g01bjc) depends on the variance (=np1-p) and on k. For given variance, the time is greatest when knp (=the mean), and is then approximately proportional to the square-root of the variance.

10  Example

This example reads values of n and p from a data file until end-of-file is reached, and prints the corresponding probabilities.

10.1  Program Text

Program Text (g01bjce.c)

10.2  Program Data

Program Data (g01bjce.d)

10.3  Program Results

Program Results (g01bjce.r)

nag_binomial_dist (g01bjc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014