nag_ref_vec_binomial (g05edc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_ref_vec_binomial (g05edc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_ref_vec_binomial (g05edc) sets up the reference vector r for a binomial distribution of the number of successes in n  trials, each with probability of success p .

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_ref_vec_binomial (Integer n, double p, double **r, NagError *fail)

3  Description

nag_ref_vec_binomial (g05edc) sets up a reference vector for use in nag_return_discrete (g05eyc). Together these functions produce random numbers from the binomial distribution defined by:
P I=i = n! i! n-i ! p i 1-p n-i if ​ i = 0 , , n, P I=i = 0 otherwise.
The reference array is found by a recurrence relation if n p 1-p < 50 ; otherwise Stirling's approximation is used.

4  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

5  Arguments

1:     nIntegerInput
On entry: the number of trials, n , of the distribution.
Constraint: n0 .
2:     pdoubleInput
On entry: the probability of success, p , of the distribution.
Constraint: 0.0 p 1.0 .
3:     rdouble **Output
On exit: reference vector for which memory will be allocated internally. If no memory is allocated to r (e.g., when an input error is detected) then r will be NULL on return, otherwise you should use the NAG macro NAG_FREE to free the storage allocated by r when it is no longer of use.
4:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, n=value.
Constraint: n0.
NE_REAL_ARG_GT
On entry, p must not be greater than 1.0: p=value .
NE_REAL_ARG_LT
On entry, p must not be less than 0.0: p=value .

7  Accuracy

Not applicable.

8  Further Comments

None.

9  Example

The example program sets up a reference vector for a binomial distribution with n=100  and p=0.5 ; it then prints the first five pseudorandom numbers generated by nag_return_discrete (g05eyc), after initialization by nag_random_init_repeatable (g05cbc).

9.1  Program Text

Program Text (g05edce.c)

9.2  Program Data

None.

9.3  Program Results

Program Results (g05edce.r)


nag_ref_vec_binomial (g05edc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012