Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_prob_binomial (g01bj)

## Purpose

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

## Syntax

[plek, pgtk, peqk, ifail] = g01bj(n, p, k)
[plek, pgtk, peqk, ifail] = nag_stat_prob_binomial(n, p, k)

## Description

Let X$X$ denote a random variable having a binomial distribution with parameters n$n$ and p$p$ (n0$n\ge 0$ and 0 < p < 1$0). Then
Prob{X = k} =
 ( n ) k
pk(1p)nk,  k = 0,1,,n.
$Prob{X=k}= n k pk(1-p)n-k, k=0,1,…,n.$
The mean of the distribution is np$np$ and the variance is np(1p)$np\left(1-p\right)$.
nag_stat_prob_binomial (g01bj) computes for given n$n$, p$p$ and k$k$ the probabilities:
 plek = Prob{X ≤ k} pgtk = Prob{X > k} peqk = Prob{X = k} .
$plek=Prob{X≤k} pgtk=Prob{X>k} peqk=Prob{X=k} .$
The method is similar to the method for the Poisson distribution described in Knüsel (1986).

## References

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

## Parameters

### Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The parameter n$n$ of the binomial distribution.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     p – double scalar
The parameter p$p$ of the binomial distribution.
Constraint: 0.0 < p < 1.0$0.0<{\mathbf{p}}<1.0$.
3:     k – int64int32nag_int scalar
The integer k$k$ which defines the required probabilities.
Constraint: 0kn$0\le {\mathbf{k}}\le {\mathbf{n}}$.

None.

None.

### Output Parameters

1:     plek – double scalar
The lower tail probability, Prob{Xk}$\mathrm{Prob}\left\{X\le k\right\}$.
2:     pgtk – double scalar
The upper tail probability, Prob{X > k}$\mathrm{Prob}\left\{X>k\right\}$.
3:     peqk – double scalar
The point probability, Prob{X = k}$\mathrm{Prob}\left\{X=k\right\}$.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 0${\mathbf{n}}<0$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, p ≤ 0.0${\mathbf{p}}\le 0.0$, or p ≥ 1.0${\mathbf{p}}\ge 1.0$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, k < 0${\mathbf{k}}<0$, or k > n${\mathbf{k}}>{\mathbf{n}}$.
ifail = 4${\mathbf{ifail}}=4$
 On entry, n is too large to be represented exactly as a double number.
ifail = 5${\mathbf{ifail}}=5$
 On entry, the variance ( = np(1 − p)$\text{}=np\left(1-p\right)$) exceeds 106${10}^{6}$.

## Accuracy

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

The time taken by nag_stat_prob_binomial (g01bj) depends on the variance ( = np(1p)$\text{}=np\left(1-p\right)$) and on k$k$. For given variance, the time is greatest when knp$k\approx np$ ( = the mean$\text{}=\text{the mean}$), and is then approximately proportional to the square-root of the variance.

## Example

```function nag_stat_prob_binomial_example
n = int64(4);
p = 0.5;
k = int64(2);
[plek, pgtk, peqk, ifail] = nag_stat_prob_binomial(n, p, k)
```
```

plek =

0.6875

pgtk =

0.3125

peqk =

0.3750

ifail =

0

```
```function g01bj_example
n = int64(4);
p = 0.5;
k = int64(2);
[plek, pgtk, peqk, ifail] = g01bj(n, p, k)
```
```

plek =

0.6875

pgtk =

0.3125

peqk =

0.3750

ifail =

0

```