G05RGF (PDF version)
G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG05RGF

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

G05RGF generates pseudorandom uniform bivariates with joint distribution of a Plackett copula.

## 2  Specification

 SUBROUTINE G05RGF ( 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 Plackett copula ${C}_{\theta }$ with parameter $\theta$, given by
 $Cθ = 1 + θ-1 u1 + u2 - 1 + θ-1 u1 + u2 2 - 4 u1 u2 θ θ-1 2θ-1 , θ ∈ 0,∞ ∖ 1$
with the special cases:
• ${C}_{0}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({u}_{1}+{u}_{2}-1,0\right)$, the Fréchet–Hoeffding lower bound;
• ${C}_{1}={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 G05RGF.
Nelsen R B (2006) An Introduction to Copulas (2nd Edition) Springer Series in Statistics

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of bivariates to generate.
Constraint: ${\mathbf{N}}\ge 0$.
2:     THETA – REAL (KIND=nag_wp)Input
On entry: $\theta$, the copula parameter.
Constraint: ${\mathbf{THETA}}\ge 0.0$.
3:     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:     STATE($*$) – 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:     X(LDX,SDX) – 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 of ${\mathbf{SORDER}}=2$.
6:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G05RGF is called.
Constraints:
• if ${\mathbf{SORDER}}=1$, ${\mathbf{LDX}}\ge {\mathbf{N}}$;
• if ${\mathbf{SORDER}}=2$, ${\mathbf{LDX}}\ge 2$.
7:     SDX – INTEGERInput
On entry: the second dimension of the array X as declared in the (sub)program from which G05RGF is called.
Constraints:
• if ${\mathbf{SORDER}}=1$, ${\mathbf{SDX}}\ge 2$;
• if ${\mathbf{SORDER}}=2$, ${\mathbf{SDX}}\ge {\mathbf{N}}$.
8:     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, STATE vector was not initialized or has been corrupted.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{THETA}}<0.0$
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{N}}<0$.
${\mathbf{IFAIL}}=4$
 On entry, ${\mathbf{SORDER}}\ne 1$ and ${\mathbf{SORDER}}\ne 2$.
${\mathbf{IFAIL}}=6$
 On entry, ${\mathbf{SORDER}}=1$ and ${\mathbf{LDX}}<{\mathbf{N}}$, or ${\mathbf{SORDER}}=2$ and ${\mathbf{LDX}}<2$.
${\mathbf{IFAIL}}=7$
 On entry, ${\mathbf{SORDER}}=1$ and ${\mathbf{SDX}}<2$, or ${\mathbf{SORDER}}=2$ and ${\mathbf{SDX}}<{\mathbf{N}}$.

Not applicable.

## 8  Further Comments

In practice, the need for numerical stability restricts the range of $\theta$ such that:
• if $\theta <{\epsilon }_{s}$, the routine returns pseudorandom uniform variates with ${C}_{0}$ joint distribution;
• if $\left|\theta -1\right|<\epsilon$, the routine returns pseudorandom uniform variates with ${C}_{1}$ joint distribution;
• if $\theta >{\epsilon }_{s}^{-1/2}$, 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.

## 9  Example

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

### 9.1  Program Text

Program Text (g05rgfe.f90)

### 9.2  Program Data

Program Data (g05rgfe.d)

### 9.3  Program Results

Program Results (g05rgfe.r)

G05RGF (PDF version)
G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual