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_rand_int_poisson_varmean (g05tk)

Purpose

nag_rand_int_poisson_varmean (g05tk) generates a vector of pseudorandom integers, each from a discrete Poisson distribution with differing parameter.

Syntax

[state, x, ifail] = g05tk(vlamda, state, 'm', m)
[state, x, ifail] = nag_rand_int_poisson_varmean(vlamda, state, 'm', m)

Description

nag_rand_int_poisson_varmean (g05tk) generates m$m$ integers xj${x}_{j}$, each from a discrete Poisson distribution with mean λj${\lambda }_{j}$, where the probability of xj = I${x}_{j}=I$ is
 P (xj = I) = ( λjI × e − λj )/(I ! ) ,   I = 0,1, … , $P (xj=I) = λjI × e -λj I! , I=0,1,… ,$
where
 λj ≥ 0 ,   j = 1,2, … ,m . $λj ≥ 0 , j=1,2,…,m .$
The methods used by this function have low set up times and are designed for efficient use when the value of the parameter λ$\lambda$ changes during the simulation. For large samples from a distribution with fixed λ$\lambda$ using nag_rand_int_poisson (g05tj) to set up and use a reference vector may be more efficient.
When λ < 7.5$\lambda <7.5$ the product of uniforms method is used, see for example Dagpunar (1988). For larger values of λ$\lambda$ an envelope rejection method is used with a target distribution:
 f(x) = (1/3) if ​|x| ≤ 1, f(x) = (1/3)|x| − 3 otherwise.
$f(x)=13 if ​|x|≤1, f(x)=13|x|-3 otherwise.$
This distribution is generated using a ratio of uniforms method. A similar approach has also been suggested by Ahrens and Dieter (1989). The basic method is combined with quick acceptance and rejection tests given by Maclaren (1990). For values of λ87$\lambda \ge 87$ Stirling's approximation is used in the computation of the Poisson distribution function, otherwise tables of factorials are used as suggested by Maclaren (1990).
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_int_poisson_varmean (g05tk).

References

Ahrens J H and Dieter U (1989) A convenient sampling method with bounded computation times for Poisson distributions Amer. J. Math. Management Sci. 1–13
Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Maclaren N M (1990) A Poisson random number generator Personal Communication

Parameters

Compulsory Input Parameters

1:     vlamda(m) – double array
m, the dimension of the array, must satisfy the constraint m1${\mathbf{m}}\ge 1$.
The means, λj${\lambda }_{\mathit{j}}$, for j = 1,2,,m$\mathit{j}=1,2,\dots ,{\mathbf{m}}$, of the Poisson distributions.
Constraint: 0.0vlamda(j)x02bb / 2.0$0.0\le {\mathbf{vlamda}}\left(\mathit{j}\right)\le \mathbf{x02bb}/2.0$, for j = 1,2,,m$\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
2:     state( : $:$) – int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array vlamda.
m$m$, the number of Poisson distributions for which pseudorandom variates are required.
Constraint: m1${\mathbf{m}}\ge 1$.

None.

Output Parameters

1:     state( : $:$) – int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains updated information on the state of the generator.
2:     x(m) – int64int32nag_int array
The m$m$ pseudorandom numbers from the specified Poisson distributions.
3:     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:
ifail = 1${\mathbf{ifail}}=1$
On entry, m < 1${\mathbf{m}}<1$.
ifail = 2${\mathbf{ifail}}=2$
On entry, vlamda(j) < 0.0${\mathbf{vlamda}}\left(j\right)<0.0$ for at least one value of j$j$.
On entry, 2 × vlamda(j) > x02bb()$2×{\mathbf{vlamda}}\left(j\right)>\mathbf{x02bb}\left(\right)$ for at least one value of j$j$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, state vector was not initialized or has been corrupted.

Not applicable.

None.

Example

```function nag_rand_int_poisson_varmean_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
vlamda = [0.5; 5; 10; 500; 1000];
x = zeros(10, 5, 'int64');
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
% Generate n sets of the m variates
for i = 1:10
[state, x(i, :), ifail] = nag_rand_int_poisson_varmean(vlamda, state);
end
x
```
```

x =

Columns 1 through 4

1                    6                   12                  507
0                    9                   11                  520
1                    3                    7                  483
0                    3                   11                  513
1                    5                    9                  496
0                    6                   17                  548
1                    9                    8                  512
0                    4                   10                  458
1                    6                   13                  523
0                    9                   16                  519

Column 5

1003
1028
1041
1012
940
990
1035
1029
971
999

```
```function g05tk_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
vlamda = [0.5; 5; 10; 500; 1000];
x = zeros(10, 5, 'int64');
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
% Generate n sets of the m variates
for i = 1:10
[state, x(i, :), ifail] = g05tk(vlamda, state);
end
x
```
```

x =

Columns 1 through 4

1                    6                   12                  507
0                    9                   11                  520
1                    3                    7                  483
0                    3                   11                  513
1                    5                    9                  496
0                    6                   17                  548
1                    9                    8                  512
0                    4                   10                  458
1                    6                   13                  523
0                    9                   16                  519

Column 5

1003
1028
1041
1012
940
990
1035
1029
971
999

```