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

Syntax

C#
public static void g01nb(
	string dncase,
	string mean,
	int n,
	double[,] a,
	double[,] b,
	double[,] c,
	double[] ela,
	double[] emu,
	double[,] sigma,
	int l1,
	int l2,
	out int lmax,
	double[] rmom,
	out double abserr,
	double eps,
	out int ifail
)
Visual Basic
Public Shared Sub g01nb ( _
	dncase As String, _
	mean As String, _
	n As Integer, _
	a As Double(,), _
	b As Double(,), _
	c As Double(,), _
	ela As Double(), _
	emu As Double(), _
	sigma As Double(,), _
	l1 As Integer, _
	l2 As Integer, _
	<OutAttribute> ByRef lmax As Integer, _
	rmom As Double(), _
	<OutAttribute> ByRef abserr As Double, _
	eps As Double, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g01nb(
	String^ dncase, 
	String^ mean, 
	int n, 
	array<double,2>^ a, 
	array<double,2>^ b, 
	array<double,2>^ c, 
	array<double>^ ela, 
	array<double>^ emu, 
	array<double,2>^ sigma, 
	int l1, 
	int l2, 
	[OutAttribute] int% lmax, 
	array<double>^ rmom, 
	[OutAttribute] double% abserr, 
	double eps, 
	[OutAttribute] int% ifail
)
F#
static member g01nb : 
        dncase : string * 
        mean : string * 
        n : int * 
        a : float[,] * 
        b : float[,] * 
        c : float[,] * 
        ela : float[] * 
        emu : float[] * 
        sigma : float[,] * 
        l1 : int * 
        l2 : int * 
        lmax : int byref * 
        rmom : float[] * 
        abserr : float byref * 
        eps : float * 
        ifail : int byref -> unit 

Parameters

dncase
Type: System..::..String
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".
mean
Type: System..::..String
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".
n
Type: System..::..Int32
On entry: n, the dimension of the quadratic form.
Constraint: n>1.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1n
On entry: the n by n symmetric matrix A. Only the lower triangle is referenced.
b
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1n
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.
c
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint:
  • if case="Q", dim1n;
  • otherwise dim11.
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.
ela
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
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.
emu
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
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.
sigma
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1n
On entry: the n by n variance-covariance matrix Σ. Only the lower triangle is referenced.
Constraint: the matrix Σ must be positive definite.
l1
Type: System..::..Int32
On entry: the first moment to be computed, l1.
Constraint: 0<l1l2.
l2
Type: System..::..Int32
On entry: the last moment to be computed, l2.
Constraint: l1l212.
lmax
Type: System..::..Int32%
On exit: the highest moment computed, lMAX. This will be l2 if ifail=0 on exit.
rmom
Type: array<System..::..Double>[]()[][]
An array of size [l2-l1+1]
On exit: the l1 to lMAX moments.
abserr
Type: System..::..Double%
On exit: the estimated maximum absolute error in any computed moment.
eps
Type: System..::..Double
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.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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, g01nb 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 method 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 method is based on the method 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 d01am.

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

Error Indicators and Warnings

Note: g01nb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDA, LDB, LDC, LDSIG) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
On entry,n1,
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.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

The relative accuracy is specified by eps and an estimate of the maximum absolute error for all computed moments is returned in abserr.

Parallelism and Performance

None.

Further Comments

None.

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-1t=2nyt2.
Thus β^ can be written as a ratio of quadratic forms and its moments computed using g01nb. 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.

Example program (C#): g01nbe.cs

Example program data: g01nbe.d

Example program results: g01nbe.r

See Also