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

# NAG Library Function Documentnag_ref_vec_discrete_pdf_cdf (g05exc)

## 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 #include
 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: ${\mathbf{np}}\ge 1$.
3:     sizepIntegerInput
On entry: the value of the variate, assumed to be a whole number, to which the probability in ${\mathbf{p}}\left[0\right]$ corresponds.
4:     distfNag_DiscreteDistribInput
On entry: indicates the type of information contained in p.
${\mathbf{distf}}=\mathrm{Nag_CDF}$
p contains a cumulative distribution function (CDF).
${\mathbf{distf}}=\mathrm{Nag_PDF}$
p contains a probability density function (PDF).
Constraint: ${\mathbf{distf}}=\mathrm{Nag_PDF}$ or $\mathrm{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

NE_ALL_PROB_ZERO
All the probabilities in array p are zero.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument distf had an illegal value.
NE_INT_ARG_LT
On entry, ${\mathbf{np}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{np}}\ge 1$.
NE_NEG_PROB
At least one of the probabilities in array p is negative, ${\mathbf{p}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
NE_NOT_INCREASING
${\mathbf{distf}}=\mathrm{Nag_CDF}$ and the sequence p is not increasing: ${\mathbf{p}}\left[i-1\right]=〈\mathit{\text{value}}〉$, ${\mathbf{p}}\left[i\right]=〈\mathit{\text{value}}〉$.
NE_PROB_NOT_ONE
The total probability is not 1, may be due to rounding errors, total probability $\text{}=〈\mathit{\text{value}}〉$.

Not applicable.

None.

## 9  Example

The example program sets up a reference vector for a distribution whose CDF, $f\left(n\right)$, 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)

None.

### 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