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_multivar_students_t (g05ry)

## Purpose

nag_rand_multivar_students_t (g05ry) sets up a reference vector and generates an array of pseudorandom numbers from a multivariate Student's $t$ distribution with $\nu$ degrees of freedom, mean vector $a$ and covariance matrix $\frac{\nu }{\nu -2}C$.

## Syntax

[r, state, x, ifail] = g05ry(mode, n, df, xmu, c, r, state, 'm', m, 'lr', lr)
[r, state, x, ifail] = nag_rand_multivar_students_t(mode, n, df, xmu, c, r, state, 'm', m, 'lr', lr)

## Description

When the covariance matrix is nonsingular (i.e., strictly positive definite), the distribution has probability density function
 $fx = Γ ν+m 2 πv m/2 Γ ν/2 C 12 1 + x-aT C-1 x-a ν -ν+m 2$
where $m$ is the number of dimensions, $\nu$ is the degrees of freedom, $a$ is the vector of means, $x$ is the vector of positions and $\frac{\nu }{\nu -2}C$ is the covariance matrix.
The function returns the value
 $x = a + νs z$
where $z$ is generated by nag_rand_dist_normal (g05sk) from a Normal distribution with mean zero and covariance matrix $C$ and $s$ is generated by nag_rand_dist_chisq (g05sd) from a ${\chi }^{2}$-distribution with $\nu$ degrees of freedom.
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_multivar_students_t (g05ry).

## References

Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{mode}$int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
${\mathbf{mode}}=0$
Set up reference vector only.
${\mathbf{mode}}=1$
Generate variates using reference vector set up in a prior call to nag_rand_multivar_students_t (g05ry).
${\mathbf{mode}}=2$
Set up reference vector and generate variates.
Constraint: ${\mathbf{mode}}=0$, $1$ or $2$.
2:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of random variates required.
Constraint: ${\mathbf{n}}\ge 0$.
3:     $\mathrm{df}$int64int32nag_int scalar
$\nu$, the number of degrees of freedom of the distribution.
Constraint: ${\mathbf{df}}\ge 3$.
4:     $\mathrm{xmu}\left({\mathbf{m}}\right)$ – double array
$a$, the vector of means of the distribution.
5:     $\mathrm{c}\left(\mathit{ldc},{\mathbf{m}}\right)$ – double array
ldc, the first dimension of the array, must satisfy the constraint $\mathit{ldc}\ge {\mathbf{m}}$.
Matrix which, along with df, defines the covariance of the distribution. Only the upper triangle need be set.
Constraint: c must be positive semidefinite to machine precision.
6:     $\mathrm{r}\left({\mathbf{lr}}\right)$ – double array
If ${\mathbf{mode}}=1$, the reference vector as set up by nag_rand_multivar_students_t (g05ry) in a previous call with ${\mathbf{mode}}=0$ or $2$.
7:     $\mathrm{state}\left(:\right)$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:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the array xmu and 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.)
$m$, the number of dimensions of the distribution.
Constraint: ${\mathbf{m}}>0$.
2:     $\mathrm{lr}$int64int32nag_int scalar
Default: the dimension of the array r.
The dimension of the array r. if ${\mathbf{mode}}=1$, it must be the same as the value of lr specified in the prior call to nag_rand_multivar_students_t (g05ry) with ${\mathbf{mode}}=0$ or $2$.
Constraint: ${\mathbf{lr}}\ge {\mathbf{m}}×\left({\mathbf{m}}+1\right)+2$.

### Output Parameters

1:     $\mathrm{r}\left({\mathbf{lr}}\right)$ – double array
If ${\mathbf{mode}}=0$ or $2$, the reference vector that can be used in subsequent calls to nag_rand_multivar_students_t (g05ry) with ${\mathbf{mode}}=1$.
2:     $\mathrm{state}\left(:\right)$int64int32nag_int array
Contains updated information on the state of the generator.
3:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{m}}\right)$ – double array
The array of pseudorandom multivariate Student's $t$ vectors generated by the function, with ${\mathbf{x}}\left(i,j\right)$ holding the $j$th dimension for the $i$th variate.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{mode}}=0$, $1$ or $2$.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{df}}\ge 3$.
${\mathbf{ifail}}=4$
Constraint: ${\mathbf{m}}>0$.
${\mathbf{ifail}}=6$
On entry, the covariance matrix $C$ is not positive semidefinite to machine precision.
${\mathbf{ifail}}=7$
Constraint: $\mathit{ldc}\ge {\mathbf{m}}$.
${\mathbf{ifail}}=8$
m is not the same as when r was set up in a previous call.
${\mathbf{ifail}}=9$
On entry, lr is not large enough, ${\mathbf{lr}}=_$: minimum length required .
${\mathbf{ifail}}=10$
On entry, state vector has been corrupted or not initialized.
${\mathbf{ifail}}=12$
Constraint: $\mathit{ldx}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The time taken by nag_rand_multivar_students_t (g05ry) is of order $n{m}^{3}$.
It is recommended that the diagonal elements of $C$ 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=L{L}^{\mathrm{T}}$, where $E$ is a diagonal matrix with small positive diagonal elements. This ensures that, even when $C$ is singular, or nearly singular, the Cholesky factor $L$ corresponds to a positive definite covariance matrix that agrees with $C$ within machine precision.

## Example

This example prints ten pseudorandom observations from a multivariate Student's $t$-distribution with ten degrees of freedom, means vector
 $1.0 2.0 -3.0 0.0$
and c matrix
 $1.69 0.39 -1.86 0.07 0.39 98.01 -7.07 -0.71 -1.86 -7.07 11.56 0.03 0.07 -0.71 0.03 0.01 ,$
generated by nag_rand_multivar_students_t (g05ry). All ten observations are generated by a single call to nag_rand_multivar_students_t (g05ry) with ${\mathbf{mode}}=2$. The random number generator is initialized by nag_rand_init_repeat (g05kf).
```function g05ry_example

fprintf('g05ry example results\n\n');

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

% Number of variates and degrees of freedom
n  = int64(10);
df = int64(10);

% Distribution means
xmu = [1; 2; -3; 0];

% Upper triangular part of covariance matrix
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];
m = size(c,1);

% Setup and generate in one go
mode = int64(2);

% Generate variates from a multivariate Student t distrobution
lr = m*(m+1) + 2;
r = zeros(lr, 1);
[r, state, x, ifail] = g05ry( ...
mode, n, df, xmu, c, r, state);

disp('Variates from multivariate Student t distribution');
disp(x);

```
```g05ry example results

Variates from multivariate Student t distribution
1.4957  -15.6226   -3.8101    0.1294
-1.0827   -6.7473    0.6696   -0.0391
2.1369    6.3861   -5.7413    0.0140
2.2481  -16.0417   -1.0982    0.1641
-0.2550    3.5166   -0.2541   -0.0592
0.9731   -4.3553   -4.4181    0.0043
0.7098   -3.4281    1.1741    0.0586
1.8827   23.2619    1.5140   -0.0704
0.9904   22.7479    0.1811   -0.0893
1.5026    2.7753   -2.2805   -0.0112

```

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–2015