Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_moments_ratio_quad_forms (g01nb)

## Purpose

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

## Syntax

[lmax, rmom, abserr, ifail] = g01nb(a, b, sigma, l1, l2, eps, 'n', n, 'c', c, 'ela', ela, 'emu', emu)
[lmax, rmom, abserr, ifail] = nag_stat_moments_ratio_quad_forms(a, b, sigma, l1, l2, eps, 'n', n, 'c', c, 'ela', ela, 'emu', emu)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: mean and case dropped from interface, c, ela, emu now optional
.

## Description

Let x$x$ have an n$n$-dimensional multivariate Normal distribution with mean μ$\mu$ and variance-covariance matrix Σ$\Sigma$. Then for a symmetric matrix A$A$ and symmetric positive semidefinite matrix B$B$, nag_stat_moments_ratio_quad_forms (g01nb) computes a subset, l1${l}_{1}$ to l2${l}_{2}$, of the first 12$12$ moments of the ratio of quadratic forms
 R = xTAx / xTBx. $R=xTAx/xTBx.$
The s$s$th moment (about the origin) is defined as
 E(Rs), $E(Rs),$ (1)
where E$E$ denotes the expectation. Alternatively, this function will compute the following expectations:
 E(Rs(aTx)) $E(Rs(aTx))$ (2)
and
 E(Rs(xTCx)), $E(Rs(xTCx)),$ (3)
where a$a$ is a vector of length n$n$ and C$C$ is a n$n$ by n$n$ symmetric matrix, if they exist. In the case of (2) the moments are zero if μ = 0$\mu =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${l}_{\mathrm{MAX}}$.
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${L}^{\mathrm{T}}BL$, where LLT = Σ$L{L}^{\mathrm{T}}=\Sigma$. The matrix LTBL${L}^{\mathrm{T}}BL$ 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_quad_1d_inf (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

## Parameters

### Compulsory Input Parameters

1:     a(lda,n) – double array
lda, the first dimension of the array, must satisfy the constraint ldan$\mathit{lda}\ge {\mathbf{n}}$.
The n$n$ by n$n$ symmetric matrix A$A$. Only the lower triangle is referenced.
2:     b(ldb,n) – double array
ldb, the first dimension of the array, must satisfy the constraint ldbn$\mathit{ldb}\ge {\mathbf{n}}$.
The n$n$ by n$n$ positive semidefinite symmetric matrix B$B$. Only the lower triangle is referenced.
Constraint: the matrix B$B$ must be positive semidefinite.
3:     sigma(ldsig,n) – double array
ldsig, the first dimension of the array, must satisfy the constraint ldsign$\mathit{ldsig}\ge {\mathbf{n}}$.
The n$n$ by n$n$ variance-covariance matrix Σ$\Sigma$. Only the lower triangle is referenced.
Constraint: the matrix Σ$\Sigma$ must be positive definite.
4:     l1 – int64int32nag_int scalar
The first moment to be computed, l1${l}_{1}$.
Constraint: 0 < l1l2$0<{\mathbf{l1}}\le {\mathbf{l2}}$.
5:     l2 – int64int32nag_int scalar
The last moment to be computed, l2${l}_{2}$.
Constraint: l1l212${\mathbf{l1}}\le {\mathbf{l2}}\le 12$.
6:     eps – double scalar
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${\mathbf{eps}}=0.0$, a value of sqrt(ε)$\sqrt{\epsilon }$ where ε$\epsilon$ is the machine precision used.
Constraint: eps = 0.0${\mathbf{eps}}=0.0$ or epsmachine precision.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays a, b, sigma and the second dimension of the arrays a, b, sigma. (An error is raised if these dimensions are not equal.)
n$n$, the dimension of the quadratic form.
Constraint: n > 1${\mathbf{n}}>1$.
2:     c(ldc, : $:$) – double array
The first dimension, ldc, of the array c must satisfy
• if case = 'Q'$\mathit{case}=\text{'Q'}$, ldcn$\mathit{ldc}\ge {\mathbf{n}}$;
• otherwise ldc1$\mathit{ldc}\ge 1$.
The second dimension of the array must be at least n${\mathbf{n}}$ if case = 'Q'$\mathit{case}=\text{'Q'}$, and at least 1$1$ otherwise
If case = 'Q'$\mathit{case}=\text{'Q'}$, c must contain the n$n$ by n$n$ symmetric matrix C$C$; only the lower triangle is referenced.
If case'Q'$\mathit{case}\ne \text{'Q'}$, c is not referenced.
3:     ela( : $:$) – double array
Note: the dimension of the array ela must be at least n${\mathbf{n}}$ if case = 'L'$\mathit{case}=\text{'L'}$, and at least 1$1$ otherwise.
If case = 'L'$\mathit{case}=\text{'L'}$, ela must contain the vector a$a$ of length n$n$, otherwise a is not referenced.
4:     emu( : $:$) – double array
Note: the dimension of the array emu must be at least n${\mathbf{n}}$ if mean = 'M'$\mathit{mean}=\text{'M'}$, and at least 1$1$ otherwise.
If mean = 'M'$\mathit{mean}=\text{'M'}$, emu must contain the n$n$ elements of the vector μ$\mu$.
If mean = 'Z'$\mathit{mean}=\text{'Z'}$, emu is not referenced.

### Input Parameters Omitted from the MATLAB Interface

case mean lda ldb ldc ldsig wk

### Output Parameters

1:     lmax – int64int32nag_int scalar
The highest moment computed, lMAX${l}_{\mathrm{MAX}}$. This will be l2${l}_{2}$ if ${\mathbf{ifail}}={\mathbf{0}}$ on exit.
2:     rmom(l2l1 + 1${\mathbf{l2}}-{\mathbf{l1}}+1$) – double array
The l1${l}_{1}$ to lMAX${l}_{\mathrm{MAX}}$ moments.
3:     abserr – double scalar
The estimated maximum absolute error in any computed moment.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_stat_moments_ratio_quad_forms (g01nb) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, n ≤ 1${\mathbf{n}}\le 1$, or lda < n$\mathit{lda}<{\mathbf{n}}$, or ldb < n$\mathit{ldb}<{\mathbf{n}}$, or ldsig < n$\mathit{ldsig}<{\mathbf{n}}$, or case = 'Q'$\mathit{case}=\text{'Q'}$ and ldc < n$\mathit{ldc}<{\mathbf{n}}$, or case ≠ 'Q'$\mathit{case}\ne \text{'Q'}$ and ldc < 1$\mathit{ldc}<1$, or l1 < 1${\mathbf{l1}}<1$, or l1 > l2${\mathbf{l1}}>{\mathbf{l2}}$, or l2 > 12${\mathbf{l2}}>12$, or case ≠ 'R'$\mathit{case}\ne \text{'R'}$, 'L'$\text{'L'}$ or 'Q'$\text{'Q'}$, or mean ≠ 'M'$\mathit{mean}\ne \text{'M'}$ or 'Z'$\text{'Z'}$, or eps ≠ 0.0${\mathbf{eps}}\ne 0.0$ and eps < machine precision.
ifail = 2${\mathbf{ifail}}=2$
 On entry, Σ$\Sigma$ is not positive definite, or b${\mathbf{b}}$ is not positive semidefinite or is null.
ifail = 3${\mathbf{ifail}}=3$
None of the required moments can be computed.
ifail = 4${\mathbf{ifail}}=4$
The matrix LTBL${L}^{\mathrm{T}}BL$ is not positive semidefinite or is null.
ifail = 5${\mathbf{ifail}}=5$
The computation to compute the eigenvalues required in the calculation of moments has failed to converge: this is an unlikely error exit.
W ifail = 6${\mathbf{ifail}}=6$
Only some of the required moments have been computed, the highest is given by lmax.
W ifail = 7${\mathbf{ifail}}=7$
The required accuracy has not been achieved in the integration. An estimate of the accuracy is returned in abserr.

## Accuracy

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

None.

## Example

```function nag_stat_moments_ratio_quad_forms_example
fcase = 'Ratio';
a = zeros(10, 10);
b = zeros(10, 10);
for i=1:9
a(i+1, i) = 0.5;
b(i, i)   = 1;
end
emu = [0.8;
0.64;
0.512;
0.4096;
0.32768;
0.262144;
0.2097152;
0.16777216;
0.134217728;
0.1073741824000001];
beta = 0.8;
sigma = zeros(10, 10);
sigma(1,1) = 1;
for i=2:10
sigma(i,i) = beta*beta*sigma(i-1,i-1)+1;
end
for i=1:10
for j=i+1:10
sigma(j,i) = beta*sigma(j-1,i);
end
end
l1 = int64(1);
l2 = int64(3);
epsilon = 0;
[lmax, rmom, abserr, ifail] = ...
nag_stat_moments_ratio_quad_forms(a, b, sigma, l1, l2, epsilon, 'emu', emu)
```
```

lmax =

3

rmom =

0.6820
0.5357
0.4427

abserr =

8.4646e-10

ifail =

0

```
```function g01nb_example
fcase = 'Ratio';
a = zeros(10, 10);
b = zeros(10, 10);
for i=1:9
a(i+1, i) = 0.5;
b(i, i)   = 1;
end
emu = [0.8;
0.64;
0.512;
0.4096;
0.32768;
0.262144;
0.2097152;
0.16777216;
0.134217728;
0.1073741824000001];
beta = 0.8;
sigma = zeros(10, 10);
sigma(1,1) = 1;
for i=2:10
sigma(i,i) = beta*beta*sigma(i-1,i-1)+1;
end
for i=1:10
for j=i+1:10
sigma(j,i) = beta*sigma(j-1,i);
end
end
l1 = int64(1);
l2 = int64(3);
epsilon = 0;
[lmax, rmom, abserr, ifail] = g01nb(a, b, sigma, l1, l2, epsilon, 'emu', emu)
```
```

lmax =

3

rmom =

0.6820
0.5357
0.4427

abserr =

8.4646e-10

ifail =

0

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013