hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_int_poisson (g05tj)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_rand_int_poisson (g05tj) generates a vector of pseudorandom integers from the discrete Poisson distribution with mean λ.

Syntax

[r, state, x, ifail] = g05tj(mode, n, lambda, r, state)
[r, state, x, ifail] = nag_rand_int_poisson(mode, n, lambda, r, state)

Description

nag_rand_int_poisson (g05tj) generates n integers xi from a discrete Poisson distribution with mean λ, where the probability of xi=I is
Pxi=I= λI×e-λ I! ,  I=0,1,,  
where λ0.
The variates can be generated with or without using a search table and index. If a search table is used then it is stored with the index in a reference vector and subsequent calls to nag_rand_int_poisson (g05tj) with the same parameter values can then use this reference vector to generate further variates. The reference array is found using a recurrence relation if λ is less than 50 and by Stirling's formula otherwise.
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 (g05tj).

References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley

Parameters

Compulsory Input Parameters

1:     mode int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
mode=0
Set up reference vector only.
mode=1
Generate variates using reference vector set up in a prior call to nag_rand_int_poisson (g05tj).
mode=2
Set up reference vector and generate variates.
mode=3
Generate variates without using the reference vector.
Constraint: mode=0, 1, 2 or 3.
2:     n int64int32nag_int scalar
n, the number of pseudorandom numbers to be generated.
Constraint: n0.
3:     lambda – double scalar
λ, the mean of the Poisson distribution.
Constraint: lambda0.0.
4:     rlr – double array
lr, the dimension of the array, must satisfy the constraint
  • if mode=0 or 2,
    • if lambda>7.15, lr>9+int8.5+14.3×lambda;
    • otherwise lr>9+intlambda+7.15×lambda+8.5;
  • if mode=1, lr must remain unchanged from the previous call to nag_rand_int_poisson (g05tj).
If mode=1, the reference vector from the previous call to nag_rand_int_poisson (g05tj).
If mode=3, r is not referenced.
5:     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

None.

Output Parameters

1:     rlr – double array
If mode3, the reference vector.
2:     state: int64int32nag_int array
Contains updated information on the state of the generator.
3:     xn int64int32nag_int array
The n pseudorandom numbers from the specified Poisson distribution.
4:     ifail int64int32nag_int scalar
ifail=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
Constraint: mode=0, 1, 2 or 3.
   ifail=2
Constraint: n0.
   ifail=3
Constraint: lambda0.0.
lambda is such that lr would have to be larger than the largest representable integer.
   ifail=4
lambda is not the same as when r was set up in a previous call.
On entry, some of the elements of the array r have been corrupted or have not been initialized.
   ifail=5
On entry, lr is too small when mode=0 or 2.
   ifail=6
On entry, state vector has been corrupted or not initialized.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

This example prints 10 pseudorandom integers from a Poisson distribution with mean λ=20, generated by a single call to nag_rand_int_poisson (g05tj), after initialization by nag_rand_init_repeat (g05kf).
function g05tj_example


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

% Initialize the base generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
                        genid, subid, seed);

% Number of variates
n = int64(10);

% Parameters
lambda = 20;

% Generate variates from a Poisson distribution
mode = int64(2);
r = zeros(120, 1);
[r, state, x, ifail] = g05tj( ...
                              mode, n, lambda, r, state);

disp('Variates');
disp(double(x));


g05tj example results

Variates
    21
    15
    23
    24
    14
    20
    19
    23
    20
    22


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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