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_stat_prob_poisson_vector (g01sk)

Purpose

nag_stat_prob_poisson_vector (g01sk) returns a number of the lower tail, upper tail and point probabilities for the Poisson distribution.

Syntax

[plek, pgtk, peqk, ivalid, ifail] = g01sk(l, k, 'll', ll, 'lk', lk)
[plek, pgtk, peqk, ivalid, ifail] = nag_stat_prob_poisson_vector(l, k, 'll', ll, 'lk', lk)

Description

Let X = {Xi : i = 1 , 2 ,, m } $X=\left\{{X}_{i}:i=1,2,\dots ,m\right\}$ denote a vector of random variables each having a Poisson distribution with parameter λi${\lambda }_{i}$ ( > 0)$\left(>0\right)$. Then
 Prob{Xi = ki} = e − λi (λiki)/(ki ! ) ,   ki = 0,1,2, … $Prob{ Xi = ki } = e -λi λi ki ki! , ki = 0,1,2,…$
The mean and variance of each distribution are both equal to λi${\lambda }_{i}$.
nag_stat_prob_poisson_vector (g01sk) computes, for given λi${\lambda }_{i}$ and ki${k}_{i}$ the probabilities: Prob{Xiki}$\mathrm{Prob}\left\{{X}_{i}\le {k}_{i}\right\}$, Prob{Xi > ki}$\mathrm{Prob}\left\{{X}_{i}>{k}_{i}\right\}$ and Prob{Xi = ki}$\mathrm{Prob}\left\{{X}_{i}={k}_{i}\right\}$ using the algorithm described in Knüsel (1986).
The input arrays to this function are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section [Vectorized s] in the G01 Chapter Introduction for further information.

References

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

Parameters

Compulsory Input Parameters

1:     l(ll) – double array
ll, the dimension of the array, must satisfy the constraint ll > 0${\mathbf{ll}}>0$.
λi${\lambda }_{i}$, the parameter of the Poisson distribution with λi = l(j)${\lambda }_{i}={\mathbf{l}}\left(j\right)$, j = ((i1)  mod  ll) + 1, for i = 1,2,,max (ll,lk)$i=1,2,\dots ,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ll}},{\mathbf{lk}}\right)$.
Constraint: 0.0 < l(j)106$0.0<{\mathbf{l}}\left(\mathit{j}\right)\le {10}^{6}$, for j = 1,2,,ll$\mathit{j}=1,2,\dots ,{\mathbf{ll}}$.
2:     k(lk) – int64int32nag_int array
lk, the dimension of the array, must satisfy the constraint lk > 0${\mathbf{lk}}>0$.
ki${k}_{i}$, the integer which defines the required probabilities with ki = k(j)${k}_{i}={\mathbf{k}}\left(j\right)$, j = ((i1)  mod  lk) + 1.
Constraint: k(j)0${\mathbf{k}}\left(\mathit{j}\right)\ge 0$, for j = 1,2,,lk$\mathit{j}=1,2,\dots ,{\mathbf{lk}}$.

Optional Input Parameters

1:     ll – int64int32nag_int scalar
Default: The dimension of the array l.
The length of the array l
Constraint: ll > 0${\mathbf{ll}}>0$.
2:     lk – int64int32nag_int scalar
Default: The dimension of the array k.
The length of the array k
Constraint: lk > 0${\mathbf{lk}}>0$.

None.

Output Parameters

1:     plek( : $:$) – double array
Note: the dimension of the array plek must be at least max (ll,lk)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ll}},{\mathbf{lk}}\right)$.
Prob{Xiki} $\mathrm{Prob}\left\{{X}_{i}\le {k}_{i}\right\}$, the lower tail probabilities.
2:     pgtk( : $:$) – double array
Note: the dimension of the array pgtk must be at least max (ll,lk)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ll}},{\mathbf{lk}}\right)$.
Prob{Xi > ki} $\mathrm{Prob}\left\{{X}_{i}>{k}_{i}\right\}$, the upper tail probabilities.
3:     peqk( : $:$) – double array
Note: the dimension of the array peqk must be at least max (ll,lk)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ll}},{\mathbf{lk}}\right)$.
Prob{Xi = ki} $\mathrm{Prob}\left\{{X}_{i}={k}_{i}\right\}$, the point probabilities.
4:     ivalid( : $:$) – int64int32nag_int array
Note: the dimension of the array ivalid must be at least max (ll,lk)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ll}},{\mathbf{lk}}\right)$.
ivalid(i)${\mathbf{ivalid}}\left(i\right)$ indicates any errors with the input arguments, with
ivalid(i) = 0${\mathbf{ivalid}}\left(i\right)=0$
No error.
ivalid(i) = 1${\mathbf{ivalid}}\left(i\right)=1$
 On entry, λi ≤ 0.0${\lambda }_{i}\le 0.0$.
ivalid(i) = 2${\mathbf{ivalid}}\left(i\right)=2$
 On entry, ki < 0${k}_{i}<0$.
ivalid(i) = 3${\mathbf{ivalid}}\left(i\right)=3$
 On entry, λi > 106${\lambda }_{i}>{10}^{6}$.
5:     ifail – int64int32nag_int scalar
${\mathrm{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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail = 1${\mathbf{ifail}}=1$
On entry, at least one value of l or k was invalid.
ifail = 2${\mathbf{ifail}}=2$
Constraint: ll > 0${\mathbf{ll}}>0$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: lk > 0${\mathbf{lk}}>0$.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Accuracy

Results are correct to a relative accuracy of at least 106${10}^{-6}$ on machines with a precision of 9$9$ or more decimal digits (provided that the results do not underflow to zero).

The time taken by nag_stat_prob_poisson_vector (g01sk) to calculate each probability depends on λi${\lambda }_{i}$ and ki${k}_{i}$. For given λi${\lambda }_{i}$, the time is greatest when kiλi${k}_{i}\approx {\lambda }_{i}$, and is then approximately proportional to sqrt(λi)$\sqrt{{\lambda }_{i}}$.

Example

```function nag_stat_prob_poisson_vector_example
rlamda = [0.750; 9.200; 34.000; 175.000];
k = [int64(3); 12; 25; 175];
[plek, pgtk, peqk, ivalid, ifail] = nag_stat_prob_poisson_vector(rlamda, k);

fprintf('\n    RLAMDA     K     PLEK      PGTK      PEQK\n');
lrlamda = numel(rlamda);
lk = numel(k);
len = max ([lrlamda, lk]);
for i=0:len-1
fprintf('%10.3f%6d%10.5f%10.5f%10.5f%3d\n', rlamda(mod(i,lrlamda)+1), ...
k(mod(i,lk)+1), plek(i+1), pgtk(i+1), peqk(i+1), ivalid(i+1));
end
```
```

RLAMDA     K     PLEK      PGTK      PEQK
0.750     3   0.99271   0.00729   0.03321  0
9.200    12   0.86074   0.13926   0.07755  0
34.000    25   0.06736   0.93264   0.02140  0
175.000   175   0.52009   0.47991   0.03014  0

```
```function g01sk_example
rlamda = [0.750; 9.200; 34.000; 175.000];
k = [int64(3); 12; 25; 175];
[plek, pgtk, peqk, ivalid, ifail] = g01sk(rlamda, k);

fprintf('\n    RLAMDA     K     PLEK      PGTK      PEQK\n');
lrlamda = numel(rlamda);
lk = numel(k);
len = max ([lrlamda, lk]);
for i=0:len-1
fprintf('%10.3f%6d%10.5f%10.5f%10.5f%3d\n', rlamda(mod(i,lrlamda)+1), ...
k(mod(i,lk)+1), plek(i+1), pgtk(i+1), peqk(i+1), ivalid(i+1));
end
```
```

RLAMDA     K     PLEK      PGTK      PEQK
0.750     3   0.99271   0.00729   0.03321  0
9.200    12   0.86074   0.13926   0.07755  0
34.000    25   0.06736   0.93264   0.02140  0
175.000   175   0.52009   0.47991   0.03014  0

```