hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_copula_normal (g05rd)

Purpose

nag_rand_copula_normal (g05rd) sets up a reference vector and generates an array of pseudorandom numbers from a Normal (Gaussian) copula with covariance matrix CC.

Syntax

[r, state, x, ifail] = g05rd(mode, n, c, r, state, 'm', m, 'lr', lr)
[r, state, x, ifail] = nag_rand_copula_normal(mode, n, c, r, state, 'm', m, 'lr', lr)

Description

The Gaussian copula, GG, is defined by
G (u1,u2,,um ; C) = ΦC (φC111(u1),φC221(u2),,φCmm1(um))
G ( u1 , u2 ,, um ; C ) = ΦC ( ϕ C11 -1 (u1) , ϕ C22 -1 (u2) ,, ϕ Cmm -1 (um) )
where mm is the number of dimensions, ΦC ΦC  is the multivariate Normal density function with mean zero and covariance matrix CC and φCii1 ϕ Cii -1  is the inverse of the univariate Normal density function with mean zero and variance Cii Cii .
nag_rand_multivar_normal (g05rz) is used to generate a vector from a multivariate Normal distribution and nag_stat_prob_normal (g01ea) is used to convert each element of that vector into a uniformly distributed value between zero and one.
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_normal (g05rd).

References

Nelsen R B (1998) An Introduction to Copulas. Lecture Notes in Statistics 139 Springer
Sklar A (1973) Random variables: joint distribution functions and copulas Kybernetika 9 499–460

Parameters

Compulsory Input Parameters

1:     mode – int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
mode = 0mode=0
Set up reference vector only.
mode = 1mode=1
Generate variates using reference vector set up in a prior call to nag_rand_copula_normal (g05rd).
mode = 2mode=2
Set up reference vector and generate variates.
Constraint: mode = 0mode=0, 11 or 22.
2:     n – int64int32nag_int scalar
nn, the number of random variates required.
Constraint: n0n0.
3:     c(ldc,m) – double array
ldc, the first dimension of the array, must satisfy the constraint ldcmldcm.
The covariance matrix of the distribution. Only the upper triangle need be set.
Constraint: CC must be positive semidefinite to machine precision.
4:     r(lr) – double array
lr, the dimension of the array, must satisfy the constraint lrm × (m + 1) + 1lrm×(m+1)+1.
If mode = 1mode=1, the reference vector as set up by nag_rand_copula_normal (g05rd) in a previous call with mode = 0mode=0 or 22.
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.

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array c and the second dimension of the array c. (An error is raised if these dimensions are not equal.)
mm, the number of dimensions of the distribution.
Constraint: m > 0m>0.
2:     lr – int64int32nag_int scalar
Default: The dimension of the array r.
The dimension of the array r as declared in the (sub)program from which nag_rand_copula_normal (g05rd) is called. If mode = 1mode=1, it must be the same as the value of lr specified in the prior call to nag_rand_copula_normal (g05rd) with mode = 0mode=0 or 22.
Constraint: lrm × (m + 1) + 1lrm×(m+1)+1.

Input Parameters Omitted from the MATLAB Interface

ldc ldx

Output Parameters

1:     r(lr) – double array
If mode = 0mode=0 or 22, the reference vector that can be used in subsequent calls to nag_rand_copula_normal (g05rd) with mode = 1mode=1.
2:     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.
3:     x(ldx,m) – double array
ldxnldxn.
The array of values from a multivariate Gaussian copula, with x(i,j)xij holding the jjth dimension for the iith variate.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry, mode0mode0, 11 or 22.
  ifail = 2ifail=2
On entry, n < 0n<0.
  ifail = 3ifail=3
On entry, m < 1m<1.
  ifail = 4ifail=4
The covariance matrix CC is not positive semidefinite to machine precision.
  ifail = 5ifail=5
On entry, ldc < mldc<m.
  ifail = 6ifail=6
The reference vector r has been corrupted or m has changed since r was set up in a previous call to nag_rand_copula_normal (g05rd) with mode = 0mode=0 or 22.
  ifail = 7ifail=7
On entry, lrm × (m + 1)lrm×(m+1).
  ifail = 8ifail=8
On entry,state vector was not initialized or has been corrupted.
  ifail = 10ifail=10
On entry, ldx < nldx<n.

Accuracy

See Section [Accuracy] in (g05rz) for an indication of the accuracy of the underlying multivariate Normal distribution.

Further Comments

The time taken by nag_rand_copula_normal (g05rd) is of order nm3nm3.
It is recommended that the diagonal elements of CC should not differ too widely in order of magnitude. This may be achieved by scaling the variables if necessary. The actual matrix decomposed is C + E = LLTC+E=LLT, where EE is a diagonal matrix with small positive diagonal elements. This ensures that, even when CC is singular, or nearly singular, the Cholesky factor LL corresponds to a positive definite covariance matrix that agrees with CC within machine precision.

Example

function nag_rand_copula_normal_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);

mode = int64(2);
n = int64(10);
c = [1.69, 0.39, -1.86, 0.07;
     0, 98.01, -7.07, -0.71;
     0, 0, 11.56, 0.03;
     0, 0, 0, 0.01];
r = zeros(31, 1);
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
[rOut, stateOut, x, ifail] = nag_rand_copula_normal(mode, n, c, r, state)
 

rOut =

    4.5000
    1.3000
    0.3000
   -1.4308
    0.0538
         0
    9.8955
   -0.6711
   -0.0734
         0
         0
    3.0104
    0.0192
         0
         0
         0
    0.0367
    1.3000
    9.9000
    3.4000
    0.1000
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


stateOut =

                   17
                 1234
                    1
                    0
                24966
                 7893
                22166
                28418
                17917
                13895
                19930
                    8
                    0
                 1234
                    1
                    1
                 1234


x =

    0.6364    0.0517    0.4137    0.8817
    0.1065    0.2461    0.7993    0.3806
    0.7460    0.6313    0.2708    0.5421
    0.7983    0.0564    0.6868    0.9234
    0.1046    0.5790    0.8533    0.2208
    0.4925    0.2784    0.3513    0.5158
    0.3843    0.2349    0.9472    0.7801
    0.7871    0.9941    0.9403    0.2044
    0.4982    0.9015    0.7176    0.2914
    0.6717    0.5359    0.5961    0.4487


ifail =

                    0


function g05rd_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);

mode = int64(2);
n = int64(10);
c = [1.69, 0.39, -1.86, 0.07;
     0, 98.01, -7.07, -0.71;
     0, 0, 11.56, 0.03;
     0, 0, 0, 0.01];
r = zeros(31, 1);
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
[rOut, stateOut, x, ifail] = g05rd(mode, n, c, r, state)
 

rOut =

    4.5000
    1.3000
    0.3000
   -1.4308
    0.0538
         0
    9.8955
   -0.6711
   -0.0734
         0
         0
    3.0104
    0.0192
         0
         0
         0
    0.0367
    1.3000
    9.9000
    3.4000
    0.1000
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


stateOut =

                   17
                 1234
                    1
                    0
                24966
                 7893
                22166
                28418
                17917
                13895
                19930
                    8
                    0
                 1234
                    1
                    1
                 1234


x =

    0.6364    0.0517    0.4137    0.8817
    0.1065    0.2461    0.7993    0.3806
    0.7460    0.6313    0.2708    0.5421
    0.7983    0.0564    0.6868    0.9234
    0.1046    0.5790    0.8533    0.2208
    0.4925    0.2784    0.3513    0.5158
    0.3843    0.2349    0.9472    0.7801
    0.7871    0.9941    0.9403    0.2044
    0.4982    0.9015    0.7176    0.2914
    0.6717    0.5359    0.5961    0.4487


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013