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

C# |
---|

public static void g05ry( int mode, int n, int df, int m, double[] xmu, double[,] c, double[] r, G05..::..G05State g05state, double[,] x, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g05ry ( _ mode As Integer, _ n As Integer, _ df As Integer, _ m As Integer, _ xmu As Double(), _ c As Double(,), _ r As Double(), _ g05state As G05..::..G05State, _ x As Double(,), _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g05ry( int mode, int n, int df, int m, array<double>^ xmu, array<double,2>^ c, array<double>^ r, G05..::..G05State^ g05state, array<double,2>^ x, [OutAttribute] int% ifail ) |

F# |
---|

static member g05ry : mode : int * n : int * df : int * m : int * xmu : float[] * c : float[,] * r : float[] * g05state : G05..::..G05State * x : float[,] * ifail : int byref -> unit |

#### Parameters

- mode
- Type: System..::..Int32
*On entry*: a code for selecting the operation to be performed by the method.- ${\mathbf{mode}}=0$
- Set up reference vector only.
- ${\mathbf{mode}}=1$
- Generate variates using reference vector set up in a prior call to g05ry.
- ${\mathbf{mode}}=2$
- Set up reference vector and generate variates.

*Constraint*: ${\mathbf{mode}}=0$, $1$ or $2$.

- n
- Type: System..::..Int32
*On entry*: $n$, the number of random variates required.*Constraint*: ${\mathbf{n}}\ge 0$.

- df
- Type: System..::..Int32
*On entry*: $\nu $, the number of degrees of freedom of the distribution.*Constraint*: ${\mathbf{df}}\ge 3$.

- m
- Type: System..::..Int32
*On entry*: $m$, the number of dimensions of the distribution.*Constraint*: ${\mathbf{m}}>0$.

- xmu
- Type: array<System..::..Double>[]()[][]An array of size [m]
*On entry*: $a$, the vector of means of the distribution.

- c
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]
**Note:**dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$*On entry*: matrix which, along with df, defines the covariance of the distribution. Only the upper triangle need be set.

- r
- Type: array<System..::..Double>[]()[][]An array of size [lr]
*On entry*: if ${\mathbf{mode}}=1$, the reference vector as set up by g05ry in a previous call with ${\mathbf{mode}}=0$ or $2$.*On exit*: if ${\mathbf{mode}}=0$ or $2$, the reference vector that can be used in subsequent calls to g05ry with ${\mathbf{mode}}=1$.

- g05state
- Type: NagLibrary..::..G05..::..G05StateAn Object of type G05.G05State.

- x
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1,
**_tdx**]**Note:**dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$*On exit*: the array of pseudorandom multivariate Student's $t$ vectors generated by the method, with ${\mathbf{x}}[i-1,j-1]$ holding the $j$th dimension for the $i$th variate.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

When the covariance matrix is nonsingular (i.e., strictly positive definite), the distribution has probability density function

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.

$$f\left(x\right)=\frac{\Gamma \left(\frac{\left(\nu +m\right)}{2}\right)}{{\left(\pi v\right)}^{m/2}\Gamma \left(\nu /2\right){\left|C\right|}^{\frac{1}{2}}}{\left[1+\frac{{\left(x-a\right)}^{\mathrm{T}}{C}^{-1}\left(x-a\right)}{\nu}\right]}^{\frac{-\left(\nu +m\right)}{2}}$$ |

The method returns the value

where $z$ is generated by g05sk from a Normal distribution with mean zero and covariance matrix $C$ and $s$ is generated by g05sd from a ${\chi}^{2}$-distribution with $\nu $ degrees of freedom.

$$x=a+\sqrt{\frac{\nu}{s}}z$$ |

One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05ry.

# References

Knuth D E (1981)

*The Art of Computer Programming (Volume 2)*(2nd Edition) Addison–WesleyWilkinson J H (1965)

*The Algebraic Eigenvalue Problem*Oxford University Press, Oxford# Error Indicators and Warnings

Errors or warnings detected by the method:

Some error messages may refer to parameters that are dropped from this interface
(LDC, LDX) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.

- ${\mathbf{ifail}}=1$
- On entry, ${\mathbf{mode}}\ne 0$, $1$ or $2$.

- ${\mathbf{ifail}}=2$
- On entry, ${\mathbf{n}}<0$.

- ${\mathbf{ifail}}=3$
- On entry, ${\mathbf{df}}\le 2$.

- ${\mathbf{ifail}}=4$
- On entry, ${\mathbf{m}}<1$.

- ${\mathbf{ifail}}=6$
- The covariance matrix c is not positive semidefinite to machine precision.

- ${\mathbf{ifail}}=7$
- On entry, ${\mathbf{ldc}}<{\mathbf{m}}$.

- ${\mathbf{ifail}}=8$

- ${\mathbf{ifail}}=9$
- On entry, ${\mathbf{lr}}\le {\mathbf{m}}\times \left({\mathbf{m}}+1\right)+1$.

- ${\mathbf{ifail}}=10$
On entry, state vector was not initialized or has been corrupted.

- ${\mathbf{ifail}}=12$
- On entry, ${\mathbf{ldx}}<{\mathbf{n}}$.

- ${\mathbf{ifail}}=-9000$
- An error occured, see message report.
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-4000$
- Invalid dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-8000$
- Negative dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$

# Accuracy

Not applicable.

# Parallelism and Performance

None.

# Further Comments

The time taken by 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.