NAG C 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 x have an n-dimensional multivariate Normal distribution with mean μ and variance-covariance matrix Σ. Then for a symmetric matrix A and symmetric positive semidefinite matrix B, nag_moments_ratio_quad_forms (g01nbc) computes a subset, l1 to l2, of the first 12 moments of the ratio of quadratic forms
R=xTAx/xTBx.  
The sth moment (about the origin) is defined as
ERs, (1)
where E denotes the expectation. Alternatively, this function will compute the following expectations:
ERsaTx (2)
and
ERsxTCx, (3)
where a is a vector of length n and C is a n by n symmetric matrix, if they exist. In the case of (2) the moments are zero if μ=0.
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, lMAX.
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 LTBL, where LLT=Σ. The matrix LTBL 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:     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 order=Nag_RowMajor. See Section 3.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: order=Nag_RowMajor or Nag_ColMajor.
2:     ratio_type Nag_MomentTypeInput
On entry: indicates the moments of which function are to be computed.
ratio_type=Nag_RatioMoments (Ratio)
ERs is computed.
ratio_type=Nag_LinearRatio (Linear with ratio)
ERsaTx is computed.
ratio_type=Nag_QuadRatio (Quadratic with ratio)
ERsxTCx is computed.
Constraint: ratio_type=Nag_RatioMoments, Nag_LinearRatio or Nag_QuadRatio.
3:     mean Nag_IncludeMeanInput
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 IntegerInput
On entry: n, the dimension of the quadratic form.
Constraint: n>1.
5:     a[dim] const doubleInput
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 IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraint: pdan.
7:     b[dim] const doubleInput
Note: the dimension, dim, of the array b must be at least pdb×n.
The i,jth element of the matrix B is stored in
  • b[j-1×pdb+i-1] when order=Nag_ColMajor;
  • b[i-1×pdb+j-1] when order=Nag_RowMajor.
On entry: the n by n positive semidefinite symmetric matrix B. Only the lower triangle is referenced.
Constraint: the matrix B must be positive semidefinite.
8:     pdb IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraint: pdbn.
9:     c[dim] const doubleInput
Note: the dimension, dim, of the array c must be at least n when ratio_type=Nag_QuadRatio.
The i,jth element of the matrix C is stored in
  • c[j-1×pdc+i-1] when order=Nag_ColMajor;
  • c[i-1×pdc+j-1] when order=Nag_RowMajor.
On entry: if ratio_type=Nag_QuadRatio, c must contain the n by n symmetric matrix C; only the lower triangle is referenced.
If ratio_typeNag_QuadRatio, c is not referenced.
10:   pdc IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array c.
Constraint: if ratio_type=Nag_QuadRatio, pdcn
11:   ela[dim] const doubleInput
Note: the dimension, dim, of the array ela must be at least
  • n when ratio_type=Nag_LinearRatio;
  • 1 otherwise.
On entry: if ratio_type=Nag_LinearRatio, ela must contain the vector a of length n, otherwise ela is not referenced.
12:   emu[dim] const doubleInput
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.
13:   sigma[dim] const doubleInput
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.
14:   pdsig IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array sigma.
Constraint: pdsign.
15:   l1 IntegerInput
On entry: the first moment to be computed, l1.
Constraint: 0<l1l2.
16:   l2 IntegerInput
On entry: the last moment to be computed, l2.
Constraint: l1l212.
17:   lmax Integer *Output
On exit: the highest moment computed, lMAX. This will be l2 on successful exit.
18:   rmom[l2-l1+1] doubleOutput
On exit: the l1 to lMAX moments.
19:   abserr double *Output
On exit: the estimated maximum absolute error in any computed moment.
20:   eps 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 eps=0.0, a value of ε where ε is the machine precision used.
Constraint: eps=0.0 or epsmachine precision.
21:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ACCURACY
The required accuracy has not been achieved in the integration. An estimate of the accuracy is returned in abserr.
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 value had an illegal value.
NE_EIGENVALUES
The computation to compute the eigenvalues required in the calculation of moments has failed to converge: this is an unlikely error exit.
NE_ENUM_INT
On entry, ratio_type=value and n=value.
Constraint: n>0.
NE_ENUM_INT_2
On entry, ratio_type=value, pdc=value, n=value.
Constraint:
if ratio_type=Nag_QuadRatio, pdcn.
NE_INT
On entry, l1=value.
Constraint: l11.
On entry, l2=value.
Constraint: l212.
On entry, n=value.
Constraint: n>1.
On entry, pda=value.
Constraint: pda>0.
On entry, pdb=value.
Constraint: pdb>0.
On entry, pdc=value.
Constraint: pdc>0.
On entry, pdsig=value.
Constraint: pdsig>0.
NE_INT_2
On entry, l1=value and l2=value.
Constraint: 0<l1l2.
On entry, l1=value and l2=value.
Constraint: l1l212.
On entry, l1=value and l2=value.
Constraint: l2l1.
On entry, pda=value and n=value.
Constraint: pdan.
On entry, pdb=value and n=value.
Constraint: pdbn.
On entry, pdc=value and n=value.
Constraint: pdcn.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_MOMENTS
Only value moments exist, less than l1=value, therefore none of the required moments can be computed.
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.
NE_POS_SEMI_DEF
On entry, b is not positive semidefinite or is null.
The matrix LTBL is not positive semidefinite or is null.
NE_REAL
On entry, eps=value.
Constraint: if eps0.0, epsmachine precision.
NE_SOME_MOMENTS
Only some of the required moments have been computed, the highest is given by lmax.

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) 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 least squares estimate of β, β^, is given by
β^=t=2nytyt-1 t=2nyt2 .  
Thus β^ can be written as a ratio of quadratic forms and its moments computed using nag_moments_ratio_quad_forms (g01nbc). The matrix A is given by
Ai+1,i=12, i=1,2,n-1; Ai,j=0, otherwise,  
and the matrix B is given by
Bi,i=1, i=1,2,n-1; Bi,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 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)