Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_rand_copula_clayton (g05rh)

## Purpose

nag_rand_copula_clayton (g05rh) generates pseudorandom uniform variates with joint distribution of a Clayton/Cook–Johnson Archimedean copula.

## Syntax

[state, x, ifail] = g05rh(n, m, theta, sorder, state)
[state, x, ifail] = nag_rand_copula_clayton(n, m, theta, sorder, state)

## Description

Generates n$n$ pseudorandom uniform m$m$-variates whose joint distribution is the Clayton/Cook–Johnson Archimedean copula Cθ${C}_{\theta }$, given by
Cθ = (u1 − θ + u2 − θ + ⋯ + um − θ − m + 1) − 1 / θ ,
 { θ ∈ (0,∞) , uj ∈ (0,1] ,   j = 1 , … m ;
$Cθ = ( u1-θ + u2-θ + ⋯ + um-θ - m + 1 ) -1/θ , { θ ∈ (0,∞) , uj ∈ (0,1] , j = 1 , … m ;$
with the special case:
• C = min (u1,u2,,um) ${C}_{\infty }=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({u}_{1},{u}_{2},\dots ,{u}_{m}\right)$, the Fréchet–Hoeffding upper bound.
The generation method uses mixture of powers.
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_copula_clayton (g05rh).

## References

Marshall A W and Olkin I (1988) Families of multivariate distributions Journal of the American Statistical Association 83 403
Nelsen R B (2006) An Introduction to Copulas (2nd Edition) Springer Series in Statistics

## Parameters

### Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the number of pseudorandom uniform variates to generate.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     m – int64int32nag_int scalar
m$m$, the number of dimensions.
Constraint: m2${\mathbf{m}}\ge 2$.
3:     theta – double scalar
θ$\theta$, the copula parameter.
Constraint: theta1.0 × 106${\mathbf{theta}}\ge 1.0×{10}^{-6}$.
4:     sorder – int64int32nag_int scalar
Determines the storage order of variates; the (i,j)$\left(\mathit{i},\mathit{j}\right)$th variate is stored in x(i,j)${\mathbf{x}}\left(\mathit{i},\mathit{j}\right)$ if sorder = 1${\mathbf{sorder}}=1$, and x(j,i)${\mathbf{x}}\left(\mathit{j},\mathit{i}\right)$ if sorder = 2${\mathbf{sorder}}=2$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,m$\mathit{j}=1,2,\dots ,m$.
Constraint: sorder = 1${\mathbf{sorder}}=1$ or 2$2$.
5:     state( : $:$) – int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

None.

ldx sdx

### Output Parameters

1:     state( : $:$) – int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains updated information on the state of the generator.
2:     x(ldx,sdx) – double array
The pseudorandom uniform variates with joint distribution described by Cθ${C}_{\theta }$, with x(i,j)${\mathbf{x}}\left(i,j\right)$ holding the i$i$th value for the j$j$th dimension if sorder = 1${\mathbf{sorder}}=1$ and the j$j$th value for the i$i$th dimension of sorder = 2${\mathbf{sorder}}=2$.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
On entry, corrupt state parameter.
ifail = 2${\mathbf{ifail}}=2$
Constraint: theta1.0 × 106${\mathbf{theta}}\ge 1.0×{10}^{-6}$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: n0${\mathbf{n}}\ge 0$.
ifail = 4${\mathbf{ifail}}=4$
Constraint: m > 1${\mathbf{m}}>1$.
ifail = 5${\mathbf{ifail}}=5$
Invalid storage option.
ifail = 7${\mathbf{ifail}}=7$
On entry, ldx is too small: .
ifail = 8${\mathbf{ifail}}=8$
On entry, sdx is too small: .
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

In practice, the need for numerical stability restricts the range of θ$\theta$ such that:
• the function requires θ1.0 × 106$\theta \ge 1.0×{10}^{-6}$;
• if θ > 200.0$\theta >200.0$, the function returns pseudorandom uniform variates with C${C}_{\infty }$ joint distribution.

## Example

```function nag_rand_copula_clayton_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
% Sample size
n = int64(13);
m = int64(4);
% Sample order
sorder = int64(1);
% Parameter
theta = 1.3;

% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);

% Generate variates
[state, x, ifail] = nag_rand_copula_clayton(n, m, theta, sorder, state)
```
```

state =

17
1234
1
0
19510
9645
7142
11687
17917
13895
19930
8
0
1234
1
1
1234

x =

0.8576    0.5048    0.9761    0.5895
0.3186    0.6372    0.9959    0.5898
0.9050    0.6950    0.9353    0.9329
0.5278    0.1804    0.4177    0.2330
0.1510    0.9777    0.2621    0.3867
0.3906    0.7938    0.3073    0.3150
0.1279    0.1709    0.1751    0.0568
0.7613    0.4314    0.3498    0.2913
0.3871    0.4430    0.3610    0.3774
0.1242    0.0647    0.0472    0.0780
0.6866    0.9500    0.9289    0.9763
0.5259    0.8218    0.7134    0.4914
0.0955    0.0459    0.1265    0.1947

ifail =

0

```
```function g05rh_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
% Sample size
n = int64(13);
m = int64(4);
% Sample order
sorder = int64(1);
% Parameter
theta = 1.3;

% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);

% Generate variates
[state, x, ifail] = g05rh(n, m, theta, sorder, state)
```
```

state =

17
1234
1
0
19510
9645
7142
11687
17917
13895
19930
8
0
1234
1
1
1234

x =

0.8576    0.5048    0.9761    0.5895
0.3186    0.6372    0.9959    0.5898
0.9050    0.6950    0.9353    0.9329
0.5278    0.1804    0.4177    0.2330
0.1510    0.9777    0.2621    0.3867
0.3906    0.7938    0.3073    0.3150
0.1279    0.1709    0.1751    0.0568
0.7613    0.4314    0.3498    0.2913
0.3871    0.4430    0.3610    0.3774
0.1242    0.0647    0.0472    0.0780
0.6866    0.9500    0.9289    0.9763
0.5259    0.8218    0.7134    0.4914
0.0955    0.0459    0.1265    0.1947

ifail =

0

```