G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG05REF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G05REF generates pseudorandom uniform bivariates with joint distribution of a Clayton/Cook–Johnson Archimedean copula.

## 2  Specification

 SUBROUTINE G05REF ( N, THETA, SORDER, STATE, X, LDX, SDX, IFAIL)
 INTEGER N, SORDER, STATE(*), LDX, SDX, IFAIL REAL (KIND=nag_wp) THETA, X(LDX,SDX)

## 3  Description

Generates pseudorandom uniform bivariates $\left\{{u}_{1},{u}_{2}\right\}\in {\left(0,1\right]}^{2}$ whose joint distribution is the Clayton/Cook–Johnson Archimedean copula ${C}_{\theta }$ with parameter $\theta$, given by
 $Cθ = max u1 -θ + u2 -θ -1 ,0 -1/θ , θ ∈ -1,∞ ∖ 0$
with the special cases:
• ${C}_{-1}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({u}_{1}+{u}_{2}-1,0\right)$, the Fréchet–Hoeffding lower bound;
• ${C}_{0}={u}_{1}{u}_{2}$, the product copula;
• ${C}_{\infty }=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({u}_{1},{u}_{2}\right)$, the Fréchet–Hoeffding upper bound.
The generation method uses conditional sampling.
One of the initialization routines G05KFF (for a repeatable sequence if computed sequentially) or G05KGF (for a non-repeatable sequence) must be called prior to the first call to G05REF.

## 4  References

Nelsen R B (2006) An Introduction to Copulas (2nd Edition) Springer Series in Statistics

## 5  Parameters

1:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of bivariates to generate.
Constraint: ${\mathbf{N}}\ge 0$.
2:     $\mathrm{THETA}$ – REAL (KIND=nag_wp)Input
On entry: $\theta$, the copula parameter.
Constraint: ${\mathbf{THETA}}\ge -1.0$.
3:     $\mathrm{SORDER}$ – INTEGERInput
On entry: determines the storage order of variates; the $\left(\mathit{i},\mathit{j}\right)$th variate is stored in ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$ if ${\mathbf{SORDER}}=1$, and ${\mathbf{X}}\left(\mathit{j},\mathit{i}\right)$ if ${\mathbf{SORDER}}=2$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2$.
Constraint: ${\mathbf{SORDER}}=1$ or $2$.
4:     $\mathrm{STATE}\left(*\right)$ – INTEGER arrayCommunication Array
Note: the actual argument supplied must be the array STATE supplied to the initialization routines G05KFF or G05KGF.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
5:     $\mathrm{X}\left({\mathbf{LDX}},{\mathbf{SDX}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the $n$ bivariate uniforms with joint distribution described by ${C}_{\theta }$, with ${\mathbf{X}}\left(i,j\right)$ holding the $i$th value for the $j$th dimension if ${\mathbf{SORDER}}=1$ and the $j$th value for the $i$th dimension if ${\mathbf{SORDER}}=2$.
6:     $\mathrm{LDX}$ – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G05REF is called.
Constraints:
• if ${\mathbf{SORDER}}=1$, ${\mathbf{LDX}}\ge {\mathbf{N}}$;
• if ${\mathbf{SORDER}}=2$, ${\mathbf{LDX}}\ge 2$.
7:     $\mathrm{SDX}$ – INTEGERInput
On entry: the second dimension of the array X as declared in the (sub)program from which G05REF is called.
Constraints:
• if ${\mathbf{SORDER}}=1$, ${\mathbf{SDX}}\ge 2$;
• if ${\mathbf{SORDER}}=2$, ${\mathbf{SDX}}\ge {\mathbf{N}}$.
8:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, corrupt STATE parameter.
${\mathbf{IFAIL}}=2$
On entry, invalid THETA: ${\mathbf{THETA}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{THETA}}\ge -1.0$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}\ge 0$.
${\mathbf{IFAIL}}=4$
On entry, invalid SORDER.
Constraint: ${\mathbf{SORDER}}=1$ or $2$.
${\mathbf{IFAIL}}=6$
On entry, LDX must be at least $〈\mathit{\text{value}}〉$: ${\mathbf{LDX}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=7$
On entry, SDX must be at least $〈\mathit{\text{value}}〉$: ${\mathbf{SDX}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

Not applicable.

## 8  Parallelism and Performance

G05REF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

In practice, the need for numerical stability restricts the range of $\theta$ such that:
• if $\left(\theta +1\right)<\epsilon$, the routine returns pseudorandom uniform variates with ${C}_{-1}$ joint distribution;
• if $\left|\theta \right|<1.0×{10}^{-6}$, the routine returns pseudorandom uniform variates with ${C}_{0}$ joint distribution;
• if $\theta >\mathrm{ln}{\epsilon }_{s}/\mathrm{ln}\left(1.0×{10}^{-2}\right)$, the routine returns pseudorandom uniform variates with ${C}_{\infty }$ joint distribution;
where ${\epsilon }_{s}$ is the safe-range parameter, the value of which is returned by X02AMF; and $\epsilon$ is the machine precision returned by X02AJF.

## 10  Example

This example generates thirteen variates for copula ${C}_{-0.8}$.

### 10.1  Program Text

Program Text (g05refe.f90)

### 10.2  Program Data

Program Data (g05refe.d)

### 10.3  Program Results

Program Results (g05refe.r)