hide long namesshow long names
hide short namesshow short names
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_quad_form (g01na)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_stat_moments_quad_form (g01na) computes the cumulants and moments of quadratic forms in Normal variates.

Syntax

[rkum, rmom, ifail] = g01na(a, sigma, l, 'n', n, 'emu', emu)
[rkum, rmom, ifail] = nag_stat_moments_quad_form(a, sigma, l, 'n', n, 'emu', emu)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: mom and mean were removed from the interface; emu was made optional

Description

Let x have an n-dimensional multivariate Normal distribution with mean μ and variance-covariance matrix Σ. Then for a symmetric matrix A, nag_stat_moments_quad_form (g01na) computes up to the first 12 moments and cumulants of the quadratic form Q=xTAx. The sth moment (about the origin) is defined as
EQs,  
where E denotes expectation. The sth moment of Q can also be found as the coefficient of ts/s! in the expansion of EeQt. The sth cumulant is defined as the coefficient of ts/s! in the expansion of logEeQt.
The function is based on the function CUM written by Magnus and Pesaran (1993a) and based on the theory given by Magnus (1978), Magnus (1979) and Magnus (1986).

References

Magnus J R (1978) The moments of products of quadratic forms in Normal variables Statist. Neerlandica 32 201–210
Magnus J R (1979) The expectation of products of quadratic forms in Normal variables: the practice Statist. Neerlandica 33 131–136
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 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:     aldan – double array
lda, the first dimension of the array, must satisfy the constraint ldan.
The n by n symmetric matrix A. Only the lower triangle is referenced.
2:     sigmaldsign – double array
ldsig, the first dimension of the array, must satisfy the constraint ldsign.
The n by n variance-covariance matrix Σ. Only the lower triangle is referenced.
Constraint: the matrix Σ must be positive definite.
3:     l int64int32nag_int scalar
The required number of cumulants, and moments if specified.
Constraint: 1l12.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the first dimension of the arrays a, sigma and the second dimension of the arrays a, sigma. (An error is raised if these dimensions are not equal.)
n, the dimension of the quadratic form.
Constraint: n>1.
2:     emu: – double array
The dimension of the array emu must be at least n if mean='M', and at least 1 otherwise
If supplied, emu must contain the n elements of the vector μ.

Output Parameters

1:     rkuml – double array
The l cumulants of the quadratic form.
2:     rmom: – double array
The dimension of the array rmom will be l if mom='M' and 1 otherwise
If mom='M', the l moments of the quadratic form.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,n1,
orl<1,
orl>12,
orlda<n,
orldsig<n,
ormom'C' or 'M',
ormean'M' or 'Z'.
   ifail=2
On entry,the matrix Σ is not positive definite.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

In a range of tests the accuracy was found to be a modest multiple of machine precision. See Magnus and Pesaran (1993b).

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 moments of the quadratic form
Q=t=2nytyt-1  
are computed using nag_stat_moments_quad_form (g01na). The matrix A is given by:
Ai+1,i = 12,  i=1,2,n-1; Ai,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 and cumulants printed.
function g01na_example


fprintf('g01na example results\n\n');

% Problem parameters
n    = 10;
l    = int64(4);
beta = 0.8;
con  = 1.0;

% Simple autoregression setup
a            = zeros(n,n);
a(2:n,1:n-1) = 0.5*eye(n-1);
emu = zeros(n,1);
for j=1:n
  emu(j) = con*beta^j;
end
sigma = zeros(n,n);
sigma(1,1) = 1;
for j = 2:n
  sigma(j,j) = sigma(j-1,j-1)*beta^2 + 1;
end
for i = 1:n
  s = sigma(i,i);
  for j = i+1:n
    sigma(j,i) = s*beta^(j-i);
  end
end

[rkum, rmom, ifail] = g01na( ...
                             a, sigma, l, 'emu', emu);

% Display results
fprintf(' n = %3d, beta = %6.3f, con = %6.3f\n\n', n, beta, con);
fprintf('    Cumulants       Moments\n\n');
ival = double([1:l]');
fprintf('%3d%12.4e    %12.4e\n',[ival rkum rmom]');


g01na example results

 n =  10, beta =  0.800, con =  1.000

    Cumulants       Moments

  1  1.7517e+01      1.7517e+01
  2  3.5010e+02      6.5695e+02
  3  1.6091e+04      3.9865e+04
  4  1.1700e+06      3.4039e+06

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–2015