G01BLF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01BLF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G01BLF returns the lower tail, upper tail and point probabilities associated with a hypergeometric distribution.

2  Specification

SUBROUTINE G01BLF ( N, L, M, K, PLEK, PGTK, PEQK, IFAIL)
INTEGER  N, L, M, K, IFAIL
REAL (KIND=nag_wp)  PLEK, PGTK, PEQK

3  Description

Let X denote a random variable having a hypergeometric distribution with parameters n, l and m (nl0, nm0). Then
ProbX=k= m k n-m l-k n l ,  
where max0,l-n-m k minl,m , 0ln and 0mn.
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 = lm n , and the variance = lmn-ln-m n2n-1 .
G01BLF computes for given n, l, m 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  Parameters

1:     N – INTEGERInput
On entry: the parameter n of the hypergeometric distribution.
Constraint: N0.
2:     L – INTEGERInput
On entry: the parameter l of the hypergeometric distribution.
Constraint: 0LN.
3:     M – INTEGERInput
On entry: the parameter m of the hypergeometric distribution.
Constraint: 0MN.
4:     K – INTEGERInput
On entry: the integer k which defines the required probabilities.
Constraint: max0,L-N-MKminL,M.
5:     PLEK – REAL (KIND=nag_wp)Output
On exit: the lower tail probability, ProbXk.
6:     PGTK – REAL (KIND=nag_wp)Output
On exit: the upper tail probability, ProbX>k.
7:     PEQK – REAL (KIND=nag_wp)Output
On exit: the point probability, ProbX=k.
8:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N<0.
IFAIL=2
On entry,L<0,
orL>N.
IFAIL=3
On entry,M<0,
orM>N.
IFAIL=4
On entry,K<0,
orK>L,
orK>M,
orK<L+M-N.
IFAIL=5
On entry,N is too large to be represented exactly as a real number.
IFAIL=6
On entry,the variance (see Section 3) exceeds 106.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

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 G01BLF depends on the variance (see Section 3) and on k. For given variance, the time is greatest when klm/n (= the mean), and is then approximately proportional to the square-root of the variance.

10  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.

10.1  Program Text

Program Text (g01blfe.f90)

10.2  Program Data

Program Data (g01blfe.d)

10.3  Program Results

Program Results (g01blfe.r)


G01BLF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

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