nag_ref_vec_discrete_pdf_cdf (g05exc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_ref_vec_discrete_pdf_cdf (g05exc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_ref_vec_discrete_pdf_cdf (g05exc) sets up the reference vector R for a discrete distribution with probability density function (PDF) or cumulative distribution function (CDF) p.

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_ref_vec_discrete_pdf_cdf (const double p[], Integer np, Integer sizep, Nag_DiscreteDistrib distf, double **r, NagError *fail)

3  Description

nag_ref_vec_discrete_pdf_cdf (g05exc) sets up a reference vector for use in nag_return_discrete (g05eyc) according to information supplied in p. This may either be the PDF or CDF of the distribution.

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:     p[np]const doubleInput
On entry: the PDF or CDF of the distribution.
2:     npIntegerInput
On entry: np is used in the calculation of the length of the reference vector.
Constraint: np1 .
3:     sizepIntegerInput
On entry: the value of the variate, assumed to be a whole number, to which the probability in p[0]  corresponds.
4:     distfNag_DiscreteDistribInput
On entry: indicates the type of information contained in p.
p contains a cumulative distribution function (CDF).
p contains a probability density function (PDF).
Constraint: distf=Nag_PDF or Nag_CDF.
5:     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.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

All the probabilities in array p are zero.
Dynamic memory allocation failed.
On entry, argument distf had an illegal value.
On entry, np=value.
Constraint: np1.
At least one of the probabilities in array p is negative, p[value] = value.
distf=Nag_CDF and the sequence p is not increasing: p[i-1] = value, p[i] = value.
The total probability is not 1, may be due to rounding errors, total probability =value .

7  Accuracy

Not applicable.

8  Further Comments


9  Example

The example program sets up a reference vector for a distribution whose CDF, f n , is defined as follows:
n f n 0 0.0 1 0.1 2 0.2 3 0.4 4 0.5 5 0.6 6 0.8 7 0.9 8 1.0 9 1.0 .
It then prints the first five pseudorandom numbers generated by nag_ref_vec_discrete_pdf_cdf (g05exc), after initialization by nag_random_init_repeatable (g05cbc).

9.1  Program Text

Program Text (g05exce.c)

9.2  Program Data


9.3  Program Results

Program Results (g05exce.r)

nag_ref_vec_discrete_pdf_cdf (g05exc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

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