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

NAG Library Routine Document

G01NBF

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

G01NBF computes the moments of ratios of quadratic forms in Normal variables and related statistics.

2  Specification

SUBROUTINE G01NBF ( CASE, MEAN, N, A, LDA, B, LDB, C, LDC, ELA, EMU, SIGMA, LDSIG, L1, L2, LMAX, RMOM, ABSERR, EPS, WK, IFAIL)
INTEGER  N, LDA, LDB, LDC, LDSIG, L1, L2, LMAX, IFAIL
REAL (KIND=nag_wp)  A(LDA,N), B(LDB,N), C(LDC,*), ELA(*), EMU(*), SIGMA(LDSIG,N), RMOM(L2-L1+1), ABSERR, EPS, WK(3*N*N+(8+L2)*N)
CHARACTER(1)  CASE, MEAN

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, G01NBF 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 routine 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 routine is based on the routine 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 D01AMF.

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  Parameters

1:     CASE – CHARACTER(1)Input
On entry: indicates the moments of which function are to be computed.
CASE='R' (Ratio)
ERs is computed.
CASE='L' (Linear with ratio)
ERsaTx is computed.
CASE='Q' (Quadratic with ratio)
ERsxTCx is computed.
Constraint: CASE='R', 'L' or 'Q'.
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:     A(LDA,N) – 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 G01NBF is called.
Constraint: LDAN.
6:     B(LDB,N) – REAL (KIND=nag_wp) arrayInput
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.
7:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which G01NBF is called.
Constraint: LDBN.
8:     C(LDC,*) – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array C must be at least N if CASE='Q', and at least 1 otherwise.
On entry: if CASE='Q', C must contain the n by n symmetric matrix C; only the lower triangle is referenced.
If CASE'Q', C is not referenced.
9:     LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G01NBF is called.
Constraints:
  • if CASE='Q', LDCN;
  • otherwise LDC1.
10:   ELA(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array ELA must be at least N if CASE='L', and at least 1 otherwise.
On entry: if CASE='L', ELA must contain the vector a of length n, otherwise A is not referenced.
11:   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.
12:   SIGMA(LDSIG,N) – 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.
13:   LDSIG – INTEGERInput
On entry: the first dimension of the array SIGMA as declared in the (sub)program from which G01NBF is called.
Constraint: LDSIGN.
14:   L1 – INTEGERInput
On entry: the first moment to be computed, l1.
Constraint: 0<L1L2.
15:   L2 – INTEGERInput
On entry: the last moment to be computed, l2.
Constraint: L1L212.
16:   LMAX – INTEGEROutput
On exit: the highest moment computed, lMAX. This will be l2 if IFAIL=0 on exit.
17:   RMOM(L2-L1+1) – REAL (KIND=nag_wp) arrayOutput
On exit: the l1 to lMAX moments.
18:   ABSERR – REAL (KIND=nag_wp)Output
On exit: the estimated maximum absolute error in any computed moment.
19:   EPS – REAL (KIND=nag_wp)Input
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.
20:   WK(3×N×N+8+L2×N) – REAL (KIND=nag_wp) arrayWorkspace
21:   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, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. 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).
Note: G01NBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1,
orLDA<N,
orLDB<N,
orLDSIG<N,
orCASE='Q' and LDC<N,
orCASE'Q' and LDC<1,
orL1<1,
orL1>L2,
orL2>12,
orCASE'R', 'L' or 'Q',
orMEAN'M' or 'Z',
orEPS0.0 and EPS<machine precision.
IFAIL=2
On entry,Σ is not positive definite,
orB is not positive semidefinite or is null.
IFAIL=3
None of the required moments can be computed.
IFAIL=4
The matrix LTBL is not positive semidefinite or is null.
IFAIL=5
The computation to compute the eigenvalues required in the calculation of moments has failed to converge: this is an unlikely error exit.
IFAIL=6
Only some of the required moments have been computed, the highest is given by LMAX.
IFAIL=7
The required accuracy has not been achieved in the integration. An estimate of the accuracy is returned in ABSERR.

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  Further Comments

None.

9  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 G01NBF. 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.

9.1  Program Text

Program Text (g01nbfe.f90)

9.2  Program Data

Program Data (g01nbfe.d)

9.3  Program Results

Program Results (g01nbfe.r)


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

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