NAG Library Function Document
nag_moments_ratio_quad_forms (g01nbc)
1 Purpose
nag_moments_ratio_quad_forms (g01nbc) computes the moments of ratios of quadratic forms in Normal variables and related statistics.
2 Specification
#include <nag.h> |
#include <nagg01.h> |
void |
nag_moments_ratio_quad_forms (Nag_OrderType order,
Nag_MomentType ratio_type,
Nag_IncludeMean mean,
Integer n,
const double a[],
Integer pda,
const double b[],
Integer pdb,
const double c[],
Integer pdc,
const double ela[],
const double emu[],
const double sigma[],
Integer pdsig,
Integer l1,
Integer l2,
Integer *lmax,
double rmom[],
double *abserr,
double eps,
NagError *fail) |
|
3 Description
Let
have an
-dimensional multivariate Normal distribution with mean
and variance-covariance matrix
. Then for a symmetric matrix
and symmetric positive semidefinite matrix
, nag_moments_ratio_quad_forms (g01nbc) computes a subset,
to
, of the first
moments of the ratio of quadratic forms
The
th moment (about the origin) is defined as
where
denotes the expectation. Alternatively, this function will compute the following expectations:
and
where
is a vector of length
and
is a
by
symmetric matrix, if they exist. In the case of
(2) the moments are zero if
.
The conditions of theorems 1, 2 and 3 of
Magnus (1986) and
Magnus (1990) are used to check for the existence of the moments. If all the requested moments do not exist, the computations are carried out for those moments that are requested up to the maximum that exist,
.
This function is based on the function QRMOM written by
Magnus and Pesaran (1993a) and based on the theory given by
Magnus (1986) and
Magnus (1990). The computation of the moments requires first the computation of the eigenvectors of the matrix
, where
. The matrix
must be positive semidefinite and not null. Given the eigenvectors of this matrix, a function which has to be integrated over the range zero to infinity can be computed. This integration is performed using
nag_1d_quad_inf_1 (d01smc).
4 References
Magnus J R (1986) The exact moments of a ratio of quadratic forms in Normal variables Ann. Économ. Statist. 4 95–109
Magnus J R (1990) On certain moments relating to quadratic forms in Normal variables: Further results Sankhyā, Ser. B 52 1–13
Magnus J R and Pesaran B (1993a) The evaluation of cumulants and moments of quadratic forms in Normal variables (CUM): Technical description Comput. Statist. 8 39–45
Magnus J R and Pesaran B (1993b) The evaluation of moments of quadratic forms and ratios of quadratic forms in Normal variables: Background, motivation and examples Comput. Statist. 8 47–55
5 Arguments
- 1:
– 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 .
- 2:
– Nag_MomentTypeInput
-
On entry: indicates the moments of which function are to be computed.
- (Ratio)
- is computed.
- (Linear with ratio)
- is computed.
- (Quadratic with ratio)
- is computed.
Constraint:
, or .
- 3:
– Nag_IncludeMeanInput
-
On entry: indicates if the mean,
, is zero.
- is zero.
- The value of is supplied in emu.
Constraint:
or .
- 4:
– IntegerInput
-
On entry: , the dimension of the quadratic form.
Constraint:
.
- 5:
– const doubleInput
-
Note: the dimension,
dim, of the array
a
must be at least
.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: the by symmetric matrix . Only the lower triangle is referenced.
- 6:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
a.
Constraint:
.
- 7:
– const doubleInput
-
Note: the dimension,
dim, of the array
b
must be at least
.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: the by positive semidefinite symmetric matrix . Only the lower triangle is referenced.
Constraint:
the matrix must be positive semidefinite.
- 8:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
b.
Constraint:
.
- 9:
– const doubleInput
-
Note: the dimension,
dim, of the array
c
must be at least
- when
;
- otherwise.
The
th element of the matrix
is stored in
- when ;
- when .
On entry: if
,
c must contain the
by
symmetric matrix
; only the lower triangle is referenced.
If
,
c is not referenced.
- 10:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
c.
Constraints:
- if , ;
- otherwise .
- 11:
– const doubleInput
-
Note: the dimension,
dim, of the array
ela
must be at least
- when ;
- otherwise.
On entry: if
,
ela must contain the vector
of length
, otherwise
ela is not referenced.
- 12:
– const doubleInput
-
Note: the dimension,
dim, of the array
emu
must be at least
- when ;
- otherwise.
On entry: if
,
emu must contain the
elements of the vector
.
If
,
emu is not referenced.
- 13:
– const doubleInput
-
Note: the dimension,
dim, of the array
sigma
must be at least
.
The
th element of the matrix is stored in
- when ;
- when .
On entry: the by variance-covariance matrix . Only the lower triangle is referenced.
Constraint:
the matrix must be positive definite.
- 14:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
sigma.
Constraint:
.
- 15:
– IntegerInput
-
On entry: the first moment to be computed, .
Constraint:
.
- 16:
– IntegerInput
-
On entry: the last moment to be computed, .
Constraint:
.
- 17:
– Integer *Output
-
On exit: the highest moment computed, . This will be on successful exit.
- 18:
– doubleOutput
-
On exit: the to moments.
- 19:
– double *Output
-
On exit: the estimated maximum absolute error in any computed moment.
- 20:
– doubleInput
-
On entry: the relative accuracy required for the moments, this value is also used in the checks for the existence of the moments.
If , a value of where is the machine precision used.
Constraint:
or .
- 21:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ACCURACY
-
Full accuracy not achieved in integration.
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.2.1.2 in the Essential Introduction for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_EIGENVALUES
-
Failure in computing eigenvalues.
- NE_ENUM_INT
-
On entry, and .
Constraint: .
- NE_ENUM_INT_2
-
On entry, , , .
Constraint: if ,
;
otherwise .
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
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.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 3.6.6 in the Essential Introduction for further information.
- NE_MOMENTS
-
Only moments exist, less than .
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 3.6.5 in the Essential Introduction for further information.
- NE_POS_DEF
-
On entry,
sigma is not positive definite.
- NE_POS_SEMI_DEF
-
On entry,
b is not positive semidefinite or is null.
The matrix is not positive semidefinite or is null.
- NE_REAL
-
On entry, .
Constraint: if , .
- NE_SOME_MOMENTS
-
Only moments exist, less than .
7 Accuracy
The relative accuracy is specified by
eps and an estimate of the maximum absolute error for all computed moments is returned in
abserr.
8 Parallelism and Performance
nag_moments_ratio_quad_forms (g01nbc) is not threaded by NAG in any implementation.
nag_moments_ratio_quad_forms (g01nbc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
None.
10 Example
This example is given by
Magnus and Pesaran (1993b) and considers the simple autoregression:
where
is a sequence of independent Normal variables with mean zero and variance one, and
is known. The least squares estimate of
,
, is given by
Thus
can be written as a ratio of quadratic forms and its moments computed using nag_moments_ratio_quad_forms (g01nbc). The matrix
is given by
and the matrix
is given by
The value of
can be computed using the relationships
The values of , , , and the number of moments required are read in and the moments computed and printed.
10.1 Program Text
Program Text (g01nbce.c)
10.2 Program Data
Program Data (g01nbce.d)
10.3 Program Results
Program Results (g01nbce.r)