﻿ g01bl Method
g01bl returns the lower tail, upper tail and point probabilities associated with a hypergeometric distribution.

# Syntax

C#
```public static void g01bl(
int n,
int l,
int m,
int k,
out double plek,
out double pgtk,
out double peqk,
out int ifail
)```
Visual Basic
```Public Shared Sub g01bl ( _
n As Integer, _
l As Integer, _
m As Integer, _
k As Integer, _
<OutAttribute> ByRef plek As Double, _
<OutAttribute> ByRef pgtk As Double, _
<OutAttribute> ByRef peqk As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g01bl(
int n,
int l,
int m,
int k,
[OutAttribute] double% plek,
[OutAttribute] double% pgtk,
[OutAttribute] double% peqk,
[OutAttribute] int% ifail
)```
F#
```static member g01bl :
n : int *
l : int *
m : int *
k : int *
plek : float byref *
pgtk : float byref *
peqk : float byref *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
On entry: the parameter $n$ of the hypergeometric distribution.
Constraint: ${\mathbf{n}}\ge 0$.
l
Type: System..::..Int32
On entry: the parameter $l$ of the hypergeometric distribution.
Constraint: $0\le {\mathbf{l}}\le {\mathbf{n}}$.
m
Type: System..::..Int32
On entry: the parameter $m$ of the hypergeometric distribution.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{n}}$.
k
Type: System..::..Int32
On entry: the integer $k$ which defines the required probabilities.
Constraint: $\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)$.
plek
Type: System..::..Double%
On exit: the lower tail probability, $\mathrm{Prob}\left\{X\le k\right\}$.
pgtk
Type: System..::..Double%
On exit: the upper tail probability, $\mathrm{Prob}\left\{X>k\right\}$.
peqk
Type: System..::..Double%
On exit: the point probability, $\mathrm{Prob}\left\{X=k\right\}$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

Let $X$ denote a random variable having a hypergeometric distribution with parameters $n$, $l$ and $m$ ($n\ge l\ge 0$, $n\ge m\ge 0$). Then
 $ProbX=k=mkn-ml-knl,$
where $\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)$, $0\le l\le n$ and $0\le m\le n$.
The hypergeometric distribution may arise if in a population of size $n$ a number $m$ are marked. From this population a sample of size $l$ is drawn and of these $k$ are observed to be marked.
The mean of the distribution $\text{}=\frac{lm}{n}$, and the variance $\text{}=\frac{lm\left(n-l\right)\left(n-m\right)}{{n}^{2}\left(n-1\right)}$.
g01bl computes for given $n$, $l$, $m$ and $k$ the probabilities:
 $plek=ProbX≤kpgtk=ProbX>kpeqk=ProbX=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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<0$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{l}}<0$, or ${\mathbf{l}}>{\mathbf{n}}$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{m}}<0$, or ${\mathbf{m}}>{\mathbf{n}}$.
${\mathbf{ifail}}=4$
 On entry, ${\mathbf{k}}<0$, or ${\mathbf{k}}>{\mathbf{l}}$, or ${\mathbf{k}}>{\mathbf{m}}$, or ${\mathbf{k}}<{\mathbf{l}}+{\mathbf{m}}-{\mathbf{n}}$.
${\mathbf{ifail}}=5$
 On entry, n is too large to be represented exactly as a real number.
${\mathbf{ifail}}=6$
 On entry, the variance (see [Description]) exceeds ${10}^{6}$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.

# 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).

# Parallelism and Performance

None.

The time taken by g01bl depends on the variance (see [Description]) and on $k$. For given variance, the time is greatest when $k\approx lm/n$ ($=$ the mean), and is then approximately proportional to the square-root of the variance.

# Example

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

Example program (C#): g01ble.cs

Example program data: g01ble.d

Example program results: g01ble.r