# NAG FL Interfaceg07abf (ci_​poisson)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g07abf ( n, tl, tu,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xmean, clevel Real (Kind=nag_wp), Intent (Out) :: tl, tu
#include <nag.h>
 void g07abf_ (const Integer *n, const double *xmean, const double *clevel, double *tl, double *tu, Integer *ifail)
The routine may be called by the names g07abf or nagf_univar_ci_poisson.

## 3Description

Given a random sample of size $n$, denoted by ${x}_{1},{x}_{2},\dots ,{x}_{n}$, from a Poisson distribution with probability function
 $p(x)=e-θ θxx! , x=0,1,2,…$
the point estimate, $\stackrel{^}{\theta }$, for $\theta$ is the sample mean, $\overline{x}$.
Given $n$ and $\overline{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θl)xx! =α2, e-nθu∑x=0T(nθu)xx! =α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.
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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the sample size.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{xmean}$Real (Kind=nag_wp) Input
On entry: the sample mean, $\overline{x}$.
Constraint: ${\mathbf{xmean}}\ge 0.0$.
3: $\mathbf{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: $\mathbf{tl}$Real (Kind=nag_wp) Output
On exit: the lower limit, ${\theta }_{l}$, of the confidence interval.
5: $\mathbf{tu}$Real (Kind=nag_wp) Output
On exit: the upper limit, ${\theta }_{u}$, of the confidence interval.
6: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 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{clevel}}=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0<{\mathbf{clevel}}<1.0$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>0$.
On entry, ${\mathbf{xmean}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{xmean}}\ge 0.0$.
${\mathbf{ifail}}=2$
When using the relationship with the gamma distribution the series to calculate the gamma probabilities has failed to converge. Both tl and tu are set to zero. This is an unlikely error exit.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

g07abf is not threaded in any implementation.

None.

## 10Example

The following example reads in data showing the number of noxious weed seeds and the frequency with which that number occurred in $98$ subsamples 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$.

### 10.1Program Text

Program Text (g07abfe.f90)

### 10.2Program Data

Program Data (g07abfe.d)

### 10.3Program Results

Program Results (g07abfe.r)