PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_int_negbin (g05th)
Purpose
nag_rand_int_negbin (g05th) generates a vector of pseudorandom integers from the discrete negative binomial distribution with parameter and probability of success at a trial.
Syntax
Description
nag_rand_int_negbin (g05th) generates
integers
from a discrete negative binomial distribution, where the probability of
(
successes before
failures) is
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_negbin (g05th) with the same parameter value can then use this reference vector to generate further variates.
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_negbin (g05th).
References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
A code for selecting the operation to be performed by the function.
- Set up reference vector only.
- Generate variates using reference vector set up in a prior call to nag_rand_int_negbin (g05th).
- Set up reference vector and generate variates.
- Generate variates without using the reference vector.
Constraint:
, , or .
- 2:
– int64int32nag_int scalar
-
, the number of pseudorandom numbers to be generated.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
, the number of failures of the distribution.
Constraint:
.
- 4:
– double scalar
-
, the parameter of the negative binomial distribution representing the probability of success at a single trial.
Constraint:
.
- 5:
– double array
-
lr, the dimension of the array, must satisfy the constraint
- if or ,
;
- if , lr must remain unchanged from the previous call to nag_rand_int_negbin (g05th).
If
, the reference vector from the previous call to
nag_rand_int_negbin (g05th).
If
,
r is not referenced.
- 6:
– 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:
– double array
-
If , the reference vector.
- 2:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 3:
– int64int32nag_int array
-
The pseudorandom numbers from the specified negative binomial distribution.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: , , or .
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
On entry, some of the elements of the array
r have been corrupted or have not been initialized.
p or
m is not the same as when
r was set up in a previous call.
-
-
On entry, lr is too small when or .
-
-
On entry,
state vector has been corrupted or not initialized.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
None.
Example
This example prints
pseudorandom integers from a negative binomial distribution with parameters
and
, generated by a single call to
nag_rand_int_negbin (g05th), after initialization by
nag_rand_init_repeat (g05kf).
Open in the MATLAB editor:
g05th_example
function g05th_example
fprintf('g05th example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = int64(20);
m = int64(60);
p = 0.999;
mode = int64(3);
r = [0];
[r, state, x, ifail] = g05th( ...
mode, n, m, p, r, state);
disp('Variates');
disp(double(x));
g05th example results
Variates
62339
50505
64863
66289
50434
59461
57365
65965
59572
63104
47833
54735
62075
48018
61458
55190
54263
80995
70129
60200
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015