# NAG Library Routine Document

## 1Purpose

g01bkf returns the lower tail, upper tail and point probabilities associated with a Poisson distribution.

## 2Specification

Fortran Interface
 Subroutine g01bkf ( k, plek, pgtk, peqk,
 Integer, Intent (In) :: k Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: rlamda Real (Kind=nag_wp), Intent (Out) :: plek, pgtk, peqk
#include <nagmk26.h>
 void g01bkf_ (const double *rlamda, const Integer *k, double *plek, double *pgtk, double *peqk, Integer *ifail)

## 3Description

Let $X$ denote a random variable having a Poisson distribution with parameter $\lambda$ $\left(>0\right)$. Then
 $ProbX=k=e-λλkk! , k=0,1,2,…$
The mean and variance of the distribution are both equal to $\lambda$.
g01bkf computes for given $\lambda$ and $k$ the probabilities:
 $plek=ProbX≤k pgtk=ProbX>k peqk=ProbX=k .$
The method is described in Knüsel (1986).

## 4References

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

## 5Arguments

1:     $\mathbf{rlamda}$ – Real (Kind=nag_wp)Input
On entry: the parameter $\lambda$ of the Poisson distribution.
Constraint: $0.0<{\mathbf{rlamda}}\le {10}^{6}$.
2:     $\mathbf{k}$ – IntegerInput
On entry: the integer $k$ which defines the required probabilities.
Constraint: ${\mathbf{k}}\ge 0$.
3:     $\mathbf{plek}$ – Real (Kind=nag_wp)Output
On exit: the lower tail probability, $\mathrm{Prob}\left\{X\le k\right\}$.
4:     $\mathbf{pgtk}$ – Real (Kind=nag_wp)Output
On exit: the upper tail probability, $\mathrm{Prob}\left\{X>k\right\}$.
5:     $\mathbf{peqk}$ – Real (Kind=nag_wp)Output
On exit: the point probability, $\mathrm{Prob}\left\{X=k\right\}$.
6:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value  is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value  is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{rlamda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{rlamda}}>0.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{k}}\ge 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{rlamda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{rlamda}}\le {10}^{6}$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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

## 8Parallelism and Performance

g01bkf is not threaded in any implementation.

The time taken by g01bkf depends on $\lambda$ and $k$. For given $\lambda$, the time is greatest when $k\approx \lambda$, and is then approximately proportional to $\sqrt{\lambda }$.

## 10Example

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

### 10.1Program Text

Program Text (g01bkfe.f90)

### 10.2Program Data

Program Data (g01bkfe.d)

### 10.3Program Results

Program Results (g01bkfe.r)