NAG Library Routine Document

g01nbf (moments_ratio_quad_forms)

1
Purpose

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

2
Specification

Fortran Interface
Subroutine g01nbf ( case, mean, n, a, lda, b, ldb, c, ldc, ela, emu, sigma, ldsig, l1, l2, lmax, rmom, abserr, eps, wk, ifail)
Integer, Intent (In):: n, lda, ldb, ldc, ldsig, l1, l2
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: lmax
Real (Kind=nag_wp), Intent (In):: a(lda,n), b(ldb,n), c(ldc,*), ela(*), emu(*), sigma(ldsig,n), eps
Real (Kind=nag_wp), Intent (Out):: rmom(l2-l1+1), abserr, wk(3*n*n+(8+l2)*n)
Character (1), Intent (In):: case, mean
C Header Interface
#include <nagmk26.h>
void  g01nbf_ (const char *cas, const char *mean, const Integer *n, const double a[], const Integer *lda, const double b[], const Integer *ldb, const double c[], const Integer *ldc, const double ela[], const double emu[], const double sigma[], const Integer *ldsig, const Integer *l1, const Integer *l2, Integer *lmax, double rmom[], double *abserr, const double *eps, double wk[], Integer *ifail, const Charlen length_cas, const Charlen length_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
Arguments

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:     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 g01nbf is called.
Constraint: ldan.
6:     bldbn – 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:     cldc* – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array c must be at least n if case='Q'.
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.
Constraint: if case='Q', ldcn.
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 ela 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:   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.
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:   rmoml2-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:   wk3×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 argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 arguments 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, case=value.
Constraint: case='R', 'L' or 'Q'.
On entry, eps=value.
Constraint: if eps0.0, epsmachine precision.
On entry, l1=value.
Constraint: l11.
On entry, l1=value and l2=value.
Constraint: l2l1.
On entry, l2=value.
Constraint: l212.
On entry, lda=value and n=value.
Constraint: ldan.
On entry, ldb=value and n=value.
Constraint: ldbn.
On entry, ldc=value and n=value.
Constraint: ldcn.
On entry, ldsig=value and n=value.
Constraint: ldsign.
On entry, mean=value.
Constraint: mean='Z' or 'M'.
On entry, n=value.
Constraint: n>1.
ifail=2
On entry, b is not positive semidefinite or is null.
On entry, sigma is not positive definite.
ifail=3
Only value moments exist, less than l1=value, therefore 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.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

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

g01nbf 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 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.

10.1
Program Text

Program Text (g01nbfe.f90)

10.2
Program Data

Program Data (g01nbfe.d)

10.3
Program Results

Program Results (g01nbfe.r)