NAG CL Interface
g01nac (moments_​quad_​form)

1 Purpose

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

2 Specification

#include <nag.h>
void  g01nac (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)
The function may be called by the names: g01nac, nag_stat_moments_quad_form or nag_moments_quad_form.

3 Description

Let x have an n-dimensional multivariate Normal distribution with mean μ and variance-covariance matrix Σ. Then for a symmetric matrix A, g01nac 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 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: order Nag_OrderType Input
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 order=Nag_RowMajor. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2: mom Nag_SelectMoments Input
On entry: indicates if moments are computed in addition to cumulants.
mom=Nag_CumulantsOnly
Only cumulants are computed.
mom=Nag_ComputeMoments
Moments are computed in addition to cumulants.
Constraint: mom=Nag_CumulantsOnly or Nag_ComputeMoments.
3: mean Nag_IncludeMean Input
On entry: indicates if the mean, μ, is zero.
mean=Nag_MeanZero
μ is zero.
mean=Nag_MeanInclude
The value of μ is supplied in emu.
Constraint: mean=Nag_MeanZero or Nag_MeanInclude.
4: n Integer Input
On entry: n, the dimension of the quadratic form.
Constraint: n>1.
5: a[dim] const double Input
Note: the dimension, dim, of the array a must be at least pda×n.
the i,jth element of the matrix A is stored in
  • a[j-1×pda+i-1] when order=Nag_ColMajor;
  • a[i-1×pda+j-1] when order=Nag_RowMajor.
On entry: the n by n symmetric matrix A. Only the lower triangle is referenced.
6: pda Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraint: pdan.
7: emu[dim] const double Input
Note: the dimension, dim, of the array emu must be at least
  • n when mean=Nag_MeanInclude;
  • 1 otherwise.
On entry: if mean=Nag_MeanInclude, emu must contain the n elements of the vector μ.
If mean=Nag_MeanZero, emu is not referenced.
8: sigma[dim] const double Input
Note: the dimension, dim, of the array sigma must be at least pdsig×n.
the i,jth element of the matrix is stored in
  • sigma[j-1×pdsig+i-1] when order=Nag_ColMajor;
  • sigma[i-1×pdsig+j-1] when order=Nag_RowMajor.
On entry: the n by n variance-covariance matrix Σ. Only the lower triangle is referenced.
Constraint: the matrix Σ must be positive definite.
9: pdsig Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array sigma.
Constraint: pdsign.
10: l Integer Input
On entry: the required number of cumulants, and moments if specified.
Constraint: 1l12.
11: rkum[l] double Output
On exit: the l cumulants of the quadratic form.
12: rmom[dim] double Output
Note: the dimension, dim, of the array rmom must be at least
  • l when mom=Nag_ComputeMoments;
  • 1 otherwise.
On exit: if mom=Nag_ComputeMoments, the l moments of the quadratic form.
13: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, l=value.
Constraint: l12.
On entry, l=value.
Constraint: l1.
On entry, n=value.
Constraint: n>1.
On entry, pda=value.
Constraint: pda>0.
On entry, pdsig=value.
Constraint: pdsig>0.
NE_INT_2
On entry, pda=value and n=value.
Constraint: pdan.
On entry, pdsig=value and n=value.
Constraint: pdsign.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface 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

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.

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 g01nac. 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 (g01nace.c)

10.2 Program Data

Program Data (g01nace.d)

10.3 Program Results

Program Results (g01nace.r)