G01NAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01NAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G01NAF computes the cumulants and moments of quadratic forms in Normal variates.

2  Specification

SUBROUTINE G01NAF ( MOM, MEAN, N, A, LDA, EMU, SIGMA, LDSIG, L, RKUM, RMOM, WK, IFAIL)
INTEGER  N, LDA, LDSIG, L, IFAIL
REAL (KIND=nag_wp)  A(LDA,N), EMU(*), SIGMA(LDSIG,N), RKUM(L), RMOM(*), WK(3*N*(N+1)/2+N)
CHARACTER(1)  MOM, MEAN

3  Description

Let x have an n-dimensional multivariate Normal distribution with mean μ and variance-covariance matrix Σ. Then for a symmetric matrix A, G01NAF computes up to the first 12 moments and cumulants of the quadratic form Q=xTAx. The sth moment (about the origin) is defined as
EQs,  
where E denotes expectation. The sth moment of Q can also be found as the coefficient of ts/s! in the expansion of EeQt. The sth cumulant is defined as the coefficient of ts/s! in the expansion of logEeQt.
The routine is based on the routine 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  Parameters

1:     MOM – CHARACTER(1)Input
On entry: indicates if moments are computed in addition to cumulants.
MOM='C'
Only cumulants are computed.
MOM='M'
Moments are computed in addition to cumulants.
Constraint: MOM='C' or 'M'.
2:     MEAN – CHARACTER(1)Input
On entry: indicates if the mean, μ, is zero.
MEAN='Z'
μ is zero.
MEAN='M'
The value of μ is supplied in EMU.
Constraint: MEAN='Z' or 'M'.
3:     N – INTEGERInput
On entry: n, the dimension of the quadratic form.
Constraint: N>1.
4:     ALDAN – REAL (KIND=nag_wp) arrayInput
On entry: the n by n symmetric matrix A. Only the lower triangle is referenced.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which G01NAF is called.
Constraint: LDAN.
6:     EMU* – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array EMU must be at least N if MEAN='M', and at least 1 otherwise.
On entry: if MEAN='M', EMU must contain the n elements of the vector μ.
If MEAN='Z', EMU is not referenced.
7:     SIGMALDSIGN – REAL (KIND=nag_wp) arrayInput
On entry: the n by n variance-covariance matrix Σ. Only the lower triangle is referenced.
Constraint: the matrix Σ must be positive definite.
8:     LDSIG – INTEGERInput
On entry: the first dimension of the array SIGMA as declared in the (sub)program from which G01NAF is called.
Constraint: LDSIGN.
9:     L – INTEGERInput
On entry: the required number of cumulants, and moments if specified.
Constraint: 1L12.
10:   RKUML – REAL (KIND=nag_wp) arrayOutput
On exit: the L cumulants of the quadratic form.
11:   RMOM* – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array RMOM must be at least L if MOM='M', and at least 1 otherwise.
On exit: if MOM='M', the L moments of the quadratic form.
12:   WK3×N×N+1/2+N – REAL (KIND=nag_wp) arrayWorkspace
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1,
orL<1,
orL>12,
orLDA<N,
orLDSIG<N,
orMOM'C' or 'M',
orMEAN'M' or 'Z'.
IFAIL=2
On entry,the matrix Σ is not positive definite.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

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

G01NAF is not threaded by NAG in any implementation.
G01NAF 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

None.

10  Example

This example is given by Magnus and Pesaran (1993b) and considers the simple autoregression
yt=βyt-1+ut,   t=1,2,n,  
where ut is a sequence of independent Normal variables with mean zero and variance one, and y0 is known. The moments of the quadratic form
Q=t=2nytyt-1  
are computed using G01NAF. The matrix A is given by:
Ai+1,i = 12,  i=1,2,n-1; Ai,j = 0,   otherwise.  
The value of Σ can be computed using the relationships
varyt=β2varyt-1+1  
and
covytyt+k=β covytyt+k- 1  
for k0 and vary1=1.
The values of β, y0, n, and the number of moments required are read in and the moments and cumulants printed.

10.1  Program Text

Program Text (g01nafe.f90)

10.2  Program Data

Program Data (g01nafe.d)

10.3  Program Results

Program Results (g01nafe.r)


G01NAF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015