G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG07ABF

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.

## 1  Purpose

G07ABF computes a confidence interval for the mean parameter of the Poisson distribution.

## 2  Specification

 SUBROUTINE G07ABF ( N, XMEAN, CLEVEL, TL, TU, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) XMEAN, CLEVEL, TL, TU

## 3  Description

Given a random sample of size $n$, denoted by ${x}_{1},{x}_{2},\dots ,{x}_{n}$, from a Poisson distribution with probability function
 $px=e-θ θxx! , x=0,1,2,…$
the point estimate, $\stackrel{^}{\theta }$, for $\theta$ is the sample mean, $\stackrel{-}{x}$.
Given $n$ and $\stackrel{-}{x}$ this routine computes a $100\left(1-\alpha \right)%$ confidence interval for the parameter $\theta$, denoted by [${\theta }_{l},{\theta }_{u}$], where $\alpha$ is in the interval $\left(0,1\right)$.
The lower and upper confidence limits are estimated by the solutions to the equations
 $e-nθl∑x=T∞ nθlxx! =α2, e-nθu∑x=0Tnθuxx! =α2,$
where $T=\sum _{i=1}^{n}{x}_{i}=n\stackrel{^}{\theta }$.
The relationship between the Poisson distribution and the ${\chi }^{2}$-distribution (see page 112 of Hastings and Peacock (1975)) is used to derive the equations
 $θl= 12n χ2T,α/22, θu= 12n χ2T+2,1-α/22,$
where ${\chi }_{\nu ,p}^{2}$ is the deviate associated with the lower tail probability $p$ of the ${\chi }^{2}$-distribution with $\nu$ degrees of freedom.
In turn the relationship between the ${\chi }^{2}$-distribution and the gamma distribution (see page 70 of Hastings and Peacock (1975)) yields the following equivalent equations;
 $θl= 12n γT,2;α/2, θu= 12n γT+1,2;1-α/2,$
where ${\gamma }_{\alpha ,\beta \text{;}\delta }$ is the deviate associated with the lower tail probability, $\delta$, of the gamma distribution with shape parameter $\alpha$ and scale parameter $\beta$. These deviates are computed using G01FFF.

## 4  References

Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Snedecor G W and Cochran W G (1967) Statistical Methods Iowa State University Press

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the sample size.
Constraint: ${\mathbf{N}}\ge 1$.
2:     XMEAN – REAL (KIND=nag_wp)Input
On entry: the sample mean, $\stackrel{-}{x}$.
Constraint: ${\mathbf{XMEAN}}\ge 0.0$.
3:     CLEVEL – REAL (KIND=nag_wp)Input
On entry: the confidence level, $\left(1-\alpha \right)$, for two-sided interval estimate. For example ${\mathbf{CLEVEL}}=0.95$ gives a $95%$ confidence interval.
Constraint: $0.0<{\mathbf{CLEVEL}}<1.0$.
4:     TL – REAL (KIND=nag_wp)Output
On exit: the lower limit, ${\theta }_{l}$, of the confidence interval.
5:     TU – REAL (KIND=nag_wp)Output
On exit: the upper limit, ${\theta }_{u}$, of the confidence interval.
6:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{N}}<1$, or ${\mathbf{XMEAN}}<0.0$, or ${\mathbf{CLEVEL}}\le 0.0$, or ${\mathbf{CLEVEL}}\ge 1.0$.
${\mathbf{IFAIL}}=2$
When using the relationship with the gamma distribution to calculate one of the confidence limits, the series to calculate the gamma probabilities has failed to converge. Both TL and TU are set to zero. This is a very unlikely error exit and if it occurs please contact NAG.

## 7  Accuracy

For most cases the results should have a relative accuracy of $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\text{0.5E−12},50.0×\epsilon \right)$ where $\epsilon$ is the machine precision (see X02AJF). Thus on machines with sufficiently high precision the results should be accurate to $12$ significant digits. Some accuracy may be lost when $\alpha /2$ or $1-\alpha /2$ is very close to $0.0$, which will occur if CLEVEL is very close to $1.0$. This should not affect the usual confidence intervals used.

None.

## 9  Example

The following example reads in data showing the number of noxious weed seeds and the frequency with which that number occurred in $98$ sub-samples of meadow grass. The data is taken from page 224 of Snedecor and Cochran (1967). The sample mean is computed as the point estimate of the Poisson parameter $\theta$. G07ABF is then called to compute both a 95% and a 99% confidence interval for the parameter $\theta$.

### 9.1  Program Text

Program Text (g07abfe.f90)

### 9.2  Program Data

Program Data (g07abfe.d)

### 9.3  Program Results

Program Results (g07abfe.r)