NAG Library Function Document
nag_moments_quad_form (g01nac)
1 Purpose
nag_moments_quad_form (g01nac) computes the cumulants and moments of quadratic forms in Normal variates.
2 Specification
#include <nag.h> |
#include <nagg01.h> |
void |
nag_moments_quad_form (Nag_OrderType order,
Nag_SelectMoments mom,
Nag_IncludeMean mean,
Integer n,
const double a[],
Integer pda,
const double emu[],
const double sigma[],
Integer pdsig,
Integer l,
double rkum[],
double rmom[],
NagError *fail) |
|
3 Description
Let
have an
-dimensional multivariate Normal distribution with mean
and variance-covariance matrix
. Then for a symmetric matrix
, nag_moments_quad_form (g01nac) computes up to the first
moments and cumulants of the quadratic form
. The
th moment (about the origin) is defined as
where
denotes expectation. The
th moment of
can also be found as the coefficient of
in the expansion of
. The
th cumulant is defined as the coefficient of
in the expansion of
.
The function is based on the function CUM written by
Magnus and Pesaran (1993a) and based on the theory given by
Magnus (1978),
Magnus (1979) and
Magnus (1986).
4 References
Magnus J R (1978) The moments of products of quadratic forms in Normal variables Statist. Neerlandica 32 201–210
Magnus J R (1979) The expectation of products of quadratic forms in Normal variables: the practice Statist. Neerlandica 33 131–136
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 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 2.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint:
or .
- 2:
– Nag_SelectMomentsInput
-
On entry: indicates if moments are computed in addition to cumulants.
- Only cumulants are computed.
- Moments are computed in addition to cumulants.
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
emu
must be at least
- when ;
- otherwise.
On entry: if
,
emu must contain the
elements of the vector
.
If
,
emu is not referenced.
- 8:
– 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.
- 9:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
sigma.
Constraint:
.
- 10:
– IntegerInput
-
On entry: the required number of cumulants, and moments if specified.
Constraint:
.
- 11:
– doubleOutput
-
On exit: the
l cumulants of the quadratic form.
- 12:
– doubleOutput
-
Note: the dimension,
dim, of the array
rmom
must be at least
- when ;
- otherwise.
On exit: if
, the
l moments of the quadratic form.
- 13:
– NagError *Input/Output
-
The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INT
-
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: .
- 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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_POS_DEF
-
On entry,
sigma is not positive definite.
7 Accuracy
In a range of tests the accuracy was found to be a modest multiple of
machine precision. See
Magnus and Pesaran (1993b).
8 Parallelism and Performance
nag_moments_quad_form (g01nac) 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 moments of the quadratic form
are computed using nag_moments_quad_form (g01nac). The matrix
is given by:
The value of
can be computed using the relationships
and
for
and
.
The values of , , , and the number of moments required are read in and the moments and cumulants printed.
10.1 Program Text
Program Text (g01nace.c)
10.2 Program Data
Program Data (g01nace.d)
10.3 Program Results
Program Results (g01nace.r)