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_hypergeom (g01bl)

## Purpose

nag_stat_prob_hypergeom (g01bl) returns the lower tail, upper tail and point probabilities associated with a hypergeometric distribution.

## Syntax

[plek, pgtk, peqk, ifail] = g01bl(n, l, m, k)
[plek, pgtk, peqk, ifail] = nag_stat_prob_hypergeom(n, l, m, k)

## Description

Let X$X$ denote a random variable having a hypergeometric distribution with parameters n$n$, l$l$ and m$m$ (nl0$n\ge l\ge 0$, nm0$n\ge m\ge 0$). Then
Prob{X = k} =
 (m) k (n − m) l − k
(n) l ,
$Prob{X=k}= m k n-m l-k n l ,$
where max (0,l(nm)) k min (l,m) $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(0,l-\left(n-m\right)\right)\le k\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(l,m\right)$, 0ln$0\le l\le n$ and 0mn$0\le m\le n$.
The hypergeometric distribution may arise if in a population of size n$n$ a number m$m$ are marked. From this population a sample of size l$l$ is drawn and of these k$k$ are observed to be marked.
The mean of the distribution = (lm)/n $\text{}=\frac{lm}{n}$, and the variance = (lm(nl)(nm))/(n2(n1)) $\text{}=\frac{lm\left(n-l\right)\left(n-m\right)}{{n}^{2}\left(n-1\right)}$.
nag_stat_prob_hypergeom (g01bl) computes for given n$n$, l$l$, m$m$ 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 hypergeometric distribution.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     l – int64int32nag_int scalar
The parameter l$l$ of the hypergeometric distribution.
Constraint: 0ln$0\le {\mathbf{l}}\le {\mathbf{n}}$.
3:     m – int64int32nag_int scalar
The parameter m$m$ of the hypergeometric distribution.
Constraint: 0mn$0\le {\mathbf{m}}\le {\mathbf{n}}$.
4:     k – int64int32nag_int scalar
The integer k$k$ which defines the required probabilities.
Constraint: max (0,l(nm))kmin (l,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(0,{\mathbf{l}}-\left({\mathbf{n}}-{\mathbf{m}}\right)\right)\le {\mathbf{k}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{l}},{\mathbf{m}}\right)$.

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, l < 0${\mathbf{l}}<0$, or l > n${\mathbf{l}}>{\mathbf{n}}$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, m < 0${\mathbf{m}}<0$, or m > n${\mathbf{m}}>{\mathbf{n}}$.
ifail = 4${\mathbf{ifail}}=4$
 On entry, k < 0${\mathbf{k}}<0$, or k > l${\mathbf{k}}>{\mathbf{l}}$, or k > m${\mathbf{k}}>{\mathbf{m}}$, or k < l + m − n${\mathbf{k}}<{\mathbf{l}}+{\mathbf{m}}-{\mathbf{n}}$.
ifail = 5${\mathbf{ifail}}=5$
 On entry, n is too large to be represented exactly as a double number.
ifail = 6${\mathbf{ifail}}=6$
 On entry, the variance (see Section [Description]) 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_hypergeom (g01bl) depends on the variance (see Section [Description]) and on k$k$. For given variance, the time is greatest when klm / n$k\approx lm/n$ ( = $=$ the mean), and is then approximately proportional to the square-root of the variance.

## Example

```function nag_stat_prob_hypergeom_example
n = int64(10);
l = int64(2);
m = int64(5);
k = int64(1);
[plek, pgtk, peqk, ifail] = nag_stat_prob_hypergeom(n, l, m, k)
```
```

plek =

0.7778

pgtk =

0.2222

peqk =

0.5556

ifail =

0

```
```function g01bl_example
n = int64(10);
l = int64(2);
m = int64(5);
k = int64(1);
[plek, pgtk, peqk, ifail] = g01bl(n, l, m, k)
```
```

plek =

0.7778

pgtk =

0.2222

peqk =

0.5556

ifail =

0

```