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_rand_times_mv_varma (g05pj)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_rand_times_mv_varma (g05pj) generates a realization of a multivariate time series from a vector autoregressive moving average (VARMA) model. The realization may be continued or a new realization generated at subsequent calls to nag_rand_times_mv_varma (g05pj).

Syntax

[r, state, x, ifail] = g05pj(mode, n, xmean, ip, phi, iq, theta, var, r, state, 'k', k, 'lr', lr)
[r, state, x, ifail] = nag_rand_times_mv_varma(mode, n, xmean, ip, phi, iq, theta, var, r, state, 'k', k, 'lr', lr)

Description

Let the vector Xt = x1t,x2t,,xktT , denote a k-dimensional time series which is assumed to follow a vector autoregressive moving average (VARMA) model of the form:
Xt-μ= ϕ1Xt-1-μ+ϕ2Xt-2-μ++ϕpXt-p-μ+ εt-θ1εt-1-θ2εt-2--θqεt-q (1)
where εt = ε1t,ε2t,,εktT , is a vector of k residual series assumed to be Normally distributed with zero mean and covariance matrix Σ. The components of εt are assumed to be uncorrelated at non-simultaneous lags. The ϕi's and θj's are k by k matrices of parameters. ϕi, for i=1,2,,p, are called the autoregressive (AR) parameter matrices, and θj, for j=1,2,,q, the moving average (MA) parameter matrices. The parameters in the model are thus the p k by k ϕ-matrices, the q k by k θ-matrices, the mean vector μ and the residual error covariance matrix Σ. Let
Aϕ= ϕ1 I 0 . . . 0 ϕ2 0 I 0 . . 0 . . . . . . ϕp-1 0 . . . 0 I ϕp 0 . . . 0 0 pk×pk   and   Bθ= θ1 I 0 . . . 0 θ2 0 I 0 . . 0 . . . . . . θq- 1 0 . . . 0 I θq 0 . . . 0 0 qk×qk  
where I denotes the k by k identity matrix.
The model (1) must be both stationary and invertible. The model is said to be stationary if the eigenvalues of Aϕ lie inside the unit circle and invertible if the eigenvalues of Bθ lie inside the unit circle.
For k6 the VARMA model (1) is recast into state space form and a realization of the state vector at time zero computed. For all other cases the function computes a realization of the pre-observed vectors X0,X-1,,X1-p, ε0,ε-1,,ε1-q, from (1), see Shea (1988). This realization is then used to generate a sequence of successive time series observations. Note that special action is taken for pure MA models, that is for p=0.
At your request a new realization of the time series may be generated more efficiently using the information in a reference vector created during a previous call to nag_rand_times_mv_varma (g05pj). See the description of the argument mode in Arguments for details.
The function returns a realization of X1,X2,,Xn. On a successful exit, the recent history is updated and saved in the array r so that nag_rand_times_mv_varma (g05pj) may be called again to generate a realization of Xn+1,Xn+2,, etc. See the description of the argument mode in Arguments for details.
Further computational details are given in Shea (1988). Note, however, that nag_rand_times_mv_varma (g05pj) uses a spectral decomposition rather than a Cholesky factorization to generate the multivariate Normals. Although this method involves more multiplications than the Cholesky factorization method and is thus slightly slower it is more stable when faced with ill-conditioned covariance matrices. A method of assigning the AR and MA coefficient matrices so that the stationarity and invertibility conditions are satisfied is described in Barone (1987).
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_times_mv_varma (g05pj).

References

Barone P (1987) A method for generating independent realisations of a multivariate normal stationary and invertible ARMAp,q process J. Time Ser. Anal. 8 125–130
Shea B L (1988) A note on the generation of independent realisations of a vector autoregressive moving average process J. Time Ser. Anal. 9 403–410

Parameters

Compulsory Input Parameters

1:     mode int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
mode=0
Set up reference vector and compute a realization of the recent history.
mode=1
Generate terms in the time series using reference vector set up in a prior call to nag_rand_times_mv_varma (g05pj).
mode=2
Combine the operations of mode=0 and 1.
mode=3
A new realization of the recent history is computed using information stored in the reference vector, and the following sequence of time series values are generated.
If mode=1 or 3, then you must ensure that the reference vector r and the values of k, ip, iq, xmean, phi, theta, var and ldvar have not been changed between calls to nag_rand_times_mv_varma (g05pj).
Constraint: mode=0, 1, 2 or 3.
2:     n int64int32nag_int scalar
n, the number of observations to be generated.
Constraint: n0.
3:     xmeank – double array
μ, the vector of means of the multivariate time series.
4:     ip int64int32nag_int scalar
p, the number of autoregressive parameter matrices.
Constraint: ip0.
5:     phik×k×ip – double array
Must contain the elements of the ip×k×k autoregressive parameter matrices of the model, ϕ1,ϕ2,,ϕp. If phi is considered as a three-dimensional array, dimensioned as phikkip , then the i,jth element of ϕl would be stored in phiijl ; that is, phil-1×k×k+j-1×k+i must be set equal to the i,jth element of ϕl, for l=1,2,,p, i=1,2,,k and j=1,2,,k.
Constraint: the elements of phi must satisfy the stationarity condition.
6:     iq int64int32nag_int scalar
q, the number of moving average parameter matrices.
Constraint: iq0.
7:     thetak×k×iq – double array
Must contain the elements of the iq×k×k moving average parameter matrices of the model, θ1,θ2,,θq. If theta is considered as a three-dimensional array, dimensioned as theta(k,k,iq), then the i,jth element of θl would be stored in thetaijl ; that is, thetal-1×k×k+j-1×k+i must be set equal to the i,jth element of θl, for l=1,2,,q, i=1,2,,k and j=1,2,,k.
Constraint: the elements of theta must be within the invertibility region.
8:     varldvark – double array
ldvar, the first dimension of the array, must satisfy the constraint ldvark.
varij must contain the (i,j)th element of Σ, for i=1,2,,k and j=1,2,,k. Only the lower triangle is required.
Constraint: the elements of var must be such that Σ is positive semidefinite.
9:     rlr – double array
If mode=1 or 3, the array r as output from the previous call to nag_rand_times_mv_varma (g05pj) must be input without any change.
If mode=0 or 2, the contents of r need not be set.
10:   state: int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

Optional Input Parameters

1:     k int64int32nag_int scalar
Default: the dimension of the array xmean and the first dimension of the array var and the second dimension of the array var. (An error is raised if these dimensions are not equal.)
k, the dimension of the multivariate time series.
Constraint: k1.
2:     lr int64int32nag_int scalar
Default: the dimension of the array r.
The dimension of the array r.
Constraints:
  • if k6, lr5r2+1×k2+4r+3×k+4;
  • if k<6, lr ip+iq 2+1×k2+ 4×ip+iq+3×k+maxkrkr+2,k2 ip+iq 2+ll+3+k2iq+1+4.
Where r=maxip,iq and if ip=0, l=kk+1/2, or if ip1, l=kk+1/2+ip-1k2.
See Further Comments for some examples of the required size of the array r.

Output Parameters

1:     rlr – double array
Information required for any subsequent calls to the function with mode=1 or 3. See Further Comments.
2:     state: int64int32nag_int array
Contains updated information on the state of the generator.
3:     xldxn – double array
xit will contain a realization of the ith component of Xt, for i=1,2,,k and t=1,2,,n.
4:     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:

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
Constraint: mode=0, 1, 2 or 3.
   ifail=2
Constraint: n0.
   ifail=3
Constraint: k1.
   ifail=5
Constraint: ip0.
   ifail=6
On entry, the AR parameters are outside the stationarity region.
   ifail=7
Constraint: iq0.
   ifail=8
On entry, the moving average parameter matrices are such that the model is non-invertible.
   ifail=9
On entry, the covariance matrix var is not positive semidefinite to machine precision.
   ifail=10
Constraint: ldvark.
   ifail=11
k is not the same as when r was set up in a previous call.
   ifail=12
On entry, lr is not large enough, lr=_: minimum length required .
   ifail=13
On entry, state vector has been corrupted or not initialized.
   ifail=15
Constraint: ldxk.
   ifail=20
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues of the matrices used to test for stationarity or invertibility.
   ifail=21
The reference vector cannot be computed because the AR parameters are too close to the boundary of the stationarity region.
   ifail=22
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues of the covariance matrix.
W  ifail=23
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues stored in the reference vector.
   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

The accuracy is limited by the matrix computations performed, and this is dependent on the condition of the argument and covariance matrices.

Further Comments

Note that, in reference to ifail=8, nag_rand_times_mv_varma (g05pj) will permit moving average parameters on the boundary of the invertibility region.
The elements of r contain amongst other information details of the spectral decompositions which are used to generate future multivariate Normals. Note that these eigenvectors may not be unique on different machines. For example the eigenvectors corresponding to multiple eigenvalues may be permuted. Although an effort is made to ensure that the eigenvectors have the same sign on all machines, differences in the signs may theoretically still occur.
The following table gives some examples of the required size of the array r, specified by the argument lr, for k=1,2 or 3, and for various values of p and q.
        q
 
    0 1 2 3
 
    13 20 31 46
  0 36 56 92 144
    85 124 199 310
 
    19 30 45 64
  1 52 88 140 208
    115 190 301 448
p
    35 50 69 92
  2 136 188 256 340
    397 508 655 838
 
    57 76 99 126
  3 268 336 420 520
    877 1024 1207 1426
Note that nag_tsa_uni_arma_roots (g13dx) may be used to check whether a VARMA model is stationary and invertible.
The time taken depends on the values of p, q and especially n and k.

Example

This program generates two realizations, each of length 48, from the bivariate AR(1) model
Xt-μ=ϕ1Xt-1-μ+εt  
with
ϕ1= 0.80 0.07 0.00 0.58 ,  
μ= 5.00 9.00 ,  
and
Σ= 2.97 0 0.64 5.38 .  
The pseudorandom number generator is initialized by a call to nag_rand_init_repeat (g05kf). Then, in the first call to nag_rand_times_mv_varma (g05pj), mode=2 in order to set up the reference vector before generating the first realization. In the subsequent call mode=3 and a new recent history is generated and used to generate the second realization.
function g05pj_example


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

% Initialize the generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
                        genid, subid, seed);

n     = int64(48);
xmean = [5; 9];
ip    = int64(1);
iq    = int64(0);
phi   = [0.8; 0; 0.07; 0.58];
theta = [];
var   = [2.97, 0; 0.64, 5.38];
r     = zeros(600, 1);

% Generate the first realisation
% Use mode = 2 to set up R and generate values
mode = int64(2);
[r, state, x, ifail] = g05pj( ...
                              mode, n, xmean, ip, phi, iq, ...
                              theta, var, r, state);
% Display the results
fprintf(' Realisation Number 1\n\n');
for i=1:2
  fprintf(' Series number %d\n', i);
  fprintf(' ---------------\n');
  for j=1:6
    fprintf(' %8.3f', x(i, (j-1)*8+1:j*8));
    fprintf('\n');
  end
  fprintf('\n');
end
fprintf('\n');

% Generate a second realisation
% Use mode = 3 to reset the series and generate values
mode = int64(3);
[r, state, x, ifail] = g05pj( ...
                              mode, n, xmean, ip, phi, iq, ...
                              theta, var, r, state);
% Display the results
fprintf(' Realisation Number 2\n\n');
for i=1:2
  fprintf(' Series number %d\n', i);
  fprintf(' ---------------\n');
  for j=1:6
    fprintf(' %8.3f', x(i, (j-1)*8+1:j*8));
    fprintf('\n');
  end
  fprintf('\n');
end
fprintf('\n');


g05pj example results

 Realisation Number 1

 Series number 1
 ---------------
    4.833    2.813    3.224    3.825    1.023    1.415    2.184    3.005
    5.547    4.832    4.705    5.484    9.407   10.335    8.495    7.478
    6.373    6.692    6.698    6.976    6.200    4.458    2.520    3.517
    3.054    5.439    5.699    7.136    5.750    8.497    9.563   11.604
    9.020   10.063    7.976    5.927    4.992    4.222    3.982    7.107
    3.554    7.045    7.025    4.106    5.106    5.954    8.026    7.212

 Series number 2
 ---------------
    8.458    9.140   10.866   10.975    9.245    5.054    5.023   12.486
   10.534   10.590   11.376    8.793   14.445   13.237   11.030    8.405
    7.187    8.291    5.920    9.390   10.055    6.222    7.751   10.604
   12.441   10.664   10.960    8.022   10.073   12.870   12.665   14.064
   11.867   12.894   10.546   12.754    8.594    9.042   12.029   12.557
    9.746    5.487    5.500    8.629    9.723    8.632    6.383   12.484


 Realisation Number 2

 Series number 1
 ---------------
    5.396    4.811    2.685    5.824    2.449    3.563    5.663    6.209
    3.130    4.308    4.333    4.903    1.770    1.278    1.340   -0.527
    1.745    3.211    4.478    5.170    5.365    4.852    6.080    6.464
    2.765    2.148    6.641    7.224   10.316    7.102    5.604    3.934
    4.839    3.698    5.210    5.384    7.652    7.315    7.332    7.561
    7.537    7.788    6.868    7.575    6.108    6.188    8.132   10.310

 Series number 2
 ---------------
   11.345   10.070   13.654   12.409   11.329   13.054   12.465    9.867
   10.263   13.394   10.553   10.331    7.814    8.747   10.025   11.167
   10.626    9.366    9.607    9.662   10.492   10.766   11.512   10.813
   10.799    8.780    9.221   14.245   11.575   10.620    8.282    5.447
    9.935    9.386   11.627   10.066   11.394    7.951    7.907   12.616
   15.246    9.962   13.216   11.350   11.227    6.021    6.968   12.428



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