2 Specification

3 Description

nag_rngs_neg_bin (g05mcc) generates n integers xi from a discrete negative binomial distribution, where the probability of xi=I (I successes before m failures) is

Pxi=I=m+I-1!I!m-1!×pI×1-pm, I=0,1,….

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_rngs_neg_bin (g05mcc) with the same parameter value can then use this reference vector to generate further variates.

6 Error Indicators and Warnings

p and m are such that the reference vector length would exceed integer range. We recommend setting mode=3.

NE_INT

On entry, m=value.
Constraint: m≥0.

On entry, mode=value.
Constraint: mode=0, 1, 2 or 3.

On entry, n=value.
Constraint: n≥1.

NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

NE_PREV_CALL

p or m is not the same as when r was set up in a previous call. Previous value of p=value and p=value. Previous value of m=value and m=value.

NE_REAL

On entry, p<0.0 or p≥1.0: p=value.

7 Accuracy

Not applicable.

8 Further Comments

None.

9 Example

This example prints five pseudorandom integers from a negative binomial distribution with parameters m=60 and p=0.999, generated by a single call to nag_rngs_neg_bin (g05mcc), after initialization by nag_rngs_init_repeatable (g05kbc).