NAG Library Function Document
nag_rngs_matrix_multi_students_t (g05lxc)
1 Purpose
nag_rngs_matrix_multi_students_t (g05lxc) sets up a reference vector and generates an array of pseudorandom numbers from a multivariate Student's distribution with degrees of freedom, mean vector and covariance matrix .
2 Specification
| #include <nag.h> |
| #include <nagg05.h> |
| void |
nag_rngs_matrix_multi_students_t (Nag_OrderType order,
Integer mode,
Integer df,
Integer m,
const double xmu[],
const double c[],
Integer pdc,
Integer n,
double x[],
Integer pdx,
Integer igen,
Integer iseed[],
double r[],
Integer lr,
NagError *fail) |
|
3 Description
When the covariance matrix is nonsingular (i.e., strictly positive definite), the distribution has probability density function
where
is the number of dimensions,
is the degrees of freedom,
is the vector of means,
is the vector of positions and
is the covariance matrix.
The function returns the value
where
is generated by
nag_rgsn_matrix_multi_normal (g05lyc) from a Normal distribution with mean zero and covariance matrix
and
is generated by
nag_rngs_chi_sq (g05lcc) from a
-distribution with
degrees of freedom.
One of the initialization functions
nag_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or
nag_rngs_init_nonrepeatable (g05kcc) (for a non-repeatable sequence) must be called prior to the first call to nag_rngs_matrix_multi_students_t (g05lxc).
4 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
5 Arguments
- 1:
order – Nag_OrderTypeInput
-
On entry: the
order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by
. See
Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint:
or Nag_ColMajor.
- 2:
mode – IntegerInput
On entry: selects the operation to be performed.
- Initialize and generate random numbers.
- Initialize only (i.e., set up reference vector).
- Generate random numbers using previously set up reference vector.
Constraint:
, or .
- 3:
df – IntegerInput
On entry: , the number of degrees of freedom of the distribution.
Constraint:
.
- 4:
m – IntegerInput
On entry:
, the number of dimensions of the distribution.
Constraint:
.
- 5:
xmu[m] – const doubleInput
On entry: , the vector of means of the distribution.
- 6:
c[] – const doubleInput
-
Note: the dimension,
dim, of the array
c
must be at least
.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: 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.
- 7:
pdc – IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
c.
Constraint:
.
- 8:
n – IntegerInput
On entry:
, the number of random variates required.
Constraint:
.
- 9:
x[] – doubleOutput
-
Note: the dimension,
dim, of the array
x
must be at least
- when ;
- when .
Where
appears in this document, it refers to the array element
- when ;
- when .
On exit: the array of pseudorandom multivariate
Student's vectors generated by the function, with holding the th dimension for the th variate.
- 10:
pdx – IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
x.
Constraints:
- if ,
;
- if , .
- 11:
igen – IntegerInput
On entry: must contain the identification number for the generator to be used to return a pseudorandom number and should remain unchanged following initialization by a prior call to
nag_rngs_init_repeatable (g05kbc) or
nag_rngs_init_nonrepeatable (g05kcc).
- 12:
iseed[] – IntegerCommunication Array
On entry: contains values which define the current state of the selected generator.
On exit: contains updated values defining the new state of the selected generator.
- 13:
r[lr] – doubleInput/Output
On entry: if , the reference vector as set up by nag_rngs_matrix_multi_students_t (g05lxc) in a previous call with or .
On exit: if or , the reference vector that can be used in subsequent calls to nag_rngs_matrix_multi_students_t (g05lxc) with .
- 14:
lr – IntegerInput
On entry: the dimension of the array
r. If
, it must be the same as the value of
lr specified in the prior call to nag_rngs_matrix_multi_students_t (g05lxc) with
or
.
Constraint:
.
- 15:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
Dynamic memory allocation failed.
- NE_BAD_PARAM
On entry, argument had an illegal value.
- NE_INT
On entry, .
Constraint: .
On entry, invalid value for
igen. Ensure
igen has not changed since random number generator was initialized.
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: and .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
m is not the same as when
r was set up in a previous call. Previous value
and
.
On entry, , .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
- NE_POS_DEF
The covariance matrix
c is not positive semidefinite to
machine precision.
7 Accuracy
The maximum absolute error in , and hence in the covariance matrix of the resulting vectors, is less than times the maximum element of , where is the machine precision. Under normal circumstances, the above will be small compared to sampling error.
The time taken by nag_rngs_matrix_multi_students_t (g05lxc) is of order .
It is recommended that the diagonal elements of should not differ too widely in order of magnitude. This may be achieved by scaling the variables if necessary. The actual matrix decomposed is , where is a diagonal matrix with small positive diagonal elements. This ensures that, even when is singular, or nearly singular, the Cholesky factor corresponds to a positive definite covariance matrix that agrees with within machine precision.
9 Example
This example prints ten pseudorandom observations from a multivariate Student's
-distribution ten degrees of freedom, means vector
and
c matrix
generated by nag_rngs_matrix_multi_students_t (g05lxc). All ten observations are generated by a single call to nag_rngs_matrix_multi_students_t (g05lxc) with
. The random number generator is initialized by
nag_rngs_init_repeatable (g05kbc).
9.1 Program Text
Program Text (g05lxce.c)
9.2 Program Data
None.
9.3 Program Results
Program Results (g05lxce.r)