Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_univar_ci_poisson (g07ab)

## Purpose

nag_univar_ci_poisson (g07ab) computes a confidence interval for the mean argument of the Poisson distribution.

## Syntax

[tl, tu, ifail] = g07ab(n, xmean, clevel)
[tl, tu, ifail] = nag_univar_ci_poisson(n, xmean, clevel)

## 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 function computes a $100\left(1-\alpha \right)%$ confidence interval for the argument $\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 argument $\alpha$ and scale argument $\beta$. These deviates are computed using nag_stat_inv_cdf_gamma (g01ff).

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, the sample size.
Constraint: ${\mathbf{n}}\ge 1$.
2:     $\mathrm{xmean}$ – double scalar
The sample mean, $\stackrel{-}{x}$.
Constraint: ${\mathbf{xmean}}\ge 0.0$.
3:     $\mathrm{clevel}$ – double scalar
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$.

None.

### Output Parameters

1:     $\mathrm{tl}$ – double scalar
The lower limit, ${\theta }_{l}$, of the confidence interval.
2:     $\mathrm{tu}$ – double scalar
The upper limit, ${\theta }_{u}$, of the confidence interval.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\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.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## 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 nag_machine_precision (x02aj)). 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.

## Example

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 argument $\theta$. nag_univar_ci_poisson (g07ab) is then called to compute both a 95% and a 99% confidence interval for the argument $\theta$.
```function g07ab_example

fprintf('g07ab example results\n\n');

num   = [0:10];
ifreq = [3 17 26 16 18  9  3  5  0  1  0];

% Estimate Poison parameter
xmean = dot(num,ifreq)/sum(ifreq);
n     = int64(sum(ifreq));
fprintf('The point estimate of the Poisson parameter = %10.4f\n', xmean);

ci = [0.95, 0.99];

for j = 1:numel(ci)

clevel = ci(j);
% Calculate clevel confidence interval
[tl, tu, ifail] = g07ab( ...
n, xmean, clevel);

fprintf('\n%2d percent Confidence Interval for the estimate\n',100*clevel);
fprintf('      (%7.4f, %7.4f)\n', tl, tu);
end

```
```g07ab example results

The point estimate of the Poisson parameter =     3.0204

95 percent Confidence Interval for the estimate
( 2.6861,  3.3848)

99 percent Confidence Interval for the estimate
( 2.5874,  3.5027)
```

Chapter Contents
Chapter Introduction
NAG Toolbox

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