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_tsa_multi_diff (g13dl)

Purpose

nag_tsa_multi_diff (g13dl) differences and/or transforms a multivariate time series. It is intended to be used prior to nag_tsa_multi_varma_estimate (g13dd) to fit a vector autoregressive moving average (VARMA) model to the differenced/transformed series.

Syntax

[w, nd, ifail] = g13dl(z, tr, id, delta, 'k', k, 'n', n)
[w, nd, ifail] = nag_tsa_multi_diff(z, tr, id, delta, 'k', k, 'n', n)

Description

For certain time series it may first be necessary to difference the original data to obtain a stationary series before calculating autocorrelations, etc. This function also allows you to apply either a square root or a log transformation to the original time series to stabilize the variance if required.
If the order of differencing required for the iith series is didi, then the differencing operator is defined by δi(B) = 1δi1Bδi2B2δidiBdiδi(B)=1-δi1B-δi2B2--δidiBdi, where BB is the backward shift operator; that is, BZt = Zt1BZt=Zt-1. Let dd denote the maximum of the orders of differencing, didi, over the kk series. The function computes values of the differenced/transformed series Wt = (w1t,w2t,,wkt)T Wt = (w1t,w2t,,wkt)T , for t = d + 1,,nt=d+1,,n, as follows:
wit = δi(B)zit * ,  i = 1,2,,k
wit=δi(B)zit*,  i=1,2,,k
where zit * zit* are the transformed values of the original kk-dimensional time series Zt = (z1t,z2t,,zkt)T Zt = (z1t,z2t,,zkt)T .
The differencing parameters δijδij, for i = 1,2,,ki=1,2,,k and j = 1,2,,dij=1,2,,di, must be supplied by you. If the iith series does not require differencing, then di = 0di=0.

References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley

Parameters

Compulsory Input Parameters

1:     z(kmax,n) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxkkmaxk.
z(i,t)zit must contain, zitzit, the iith component of ZtZt, for i = 1,2,,ki=1,2,,k and t = 1,2,,nt=1,2,,n.
Constraints:
  • if tr(i) = 'L'tri='L', z(i,t) > 0.0zit>0.0;
  • if tr(i) = 'S'tri='S', z(i,t)0.0zit0.0, for i = 1,2,,ki=1,2,,k and t = 1,2,,nt=1,2,,n.
2:     tr(k) – cell array of strings
k, the dimension of the array, must satisfy the constraint k1k1.
tr(i)tri indicates whether the iith time series is to be transformed, for i = 1,2,,ki=1,2,,k.
tr(i) = 'N'tri='N'
No transformation is used.
tr(i) = 'L'tri='L'
A log transformation is used.
tr(i) = 'S'tri='S'
A square root transformation is used.
Constraint: tr(i) = 'N'tri='N', 'L''L' or 'S''S', for i = 1,2,,ki=1,2,,k.
3:     id(k) – int64int32nag_int array
k, the dimension of the array, must satisfy the constraint k1k1.
The order of differencing for each series, d1,d2,,dkd1,d2,,dk.
Constraint: 0id(i) < n0idi<n, for i = 1,2,,ki=1,2,,k.
4:     delta(kmax, : :) – double array
The second dimension of the array must be at least max (1,d)max(1,d), where d = max (id(i))d=max(idi)
If id(i) > 0idi>0, then delta(i,j)deltaij must be set equal to δijδij, for j = 1,2,,dij=1,2,,di and i = 1,2,,ki=1,2,,k.
If d = 0d=0, then delta is not referenced.

Optional Input Parameters

1:     k – int64int32nag_int scalar
Default: The dimension of the arrays tr, id. (An error is raised if these dimensions are not equal.)
kk, the dimension of the multivariate time series.
Constraint: k1k1.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array z.
nn, the number of observations in the series, prior to differencing.
Constraint: n1n1.

Input Parameters Omitted from the MATLAB Interface

kmax work

Output Parameters

1:     w(kmax, : :) – double array
The second dimension of the array will be ndn-d, where d = max (id(i))d=max(idi)
kmaxkkmaxk.
w(i,t)wit contains the value of wi,t + dwi,t+d, for i = 1,2,,ki=1,2,,k and t = 1,2,,ndt=1,2,,n-d.
2:     nd – int64int32nag_int scalar
The number of differenced values, ndn-d, in the series, where d = max (id(i))d=max(idi).
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,k < 1k<1,
orn < 1n<1,
orkmax < kkmax<k.
  ifail = 2ifail=2
On entry,id(i) < 0idi<0, for some i = 1,2,,ki=1,2,,k,
orid(i)nidin, for some i = 1,2,,ki=1,2,,k.
  ifail = 3ifail=3
On entry,at least one of the first kk elements of tr is not equal to 'N', 'L' or 'S'.
  ifail = 4ifail=4
On entry, one or more of the elements of z is invalid, for the transformation requested; that is, you may be trying to log or square root a series, some of whose values are negative.

Accuracy

The computations are believed to be stable.

Further Comments

The same differencing operator does not have to be applied to all the series. For example, suppose we have k = 2k=2, and wish to apply the second-order differencing operator 22 to the first series and the first-order differencing operator  to the second series:
w1t = 2z1t = (1B)2z1t = (12B + B2)z1t,   and
w2t = z2t = (1B)z2t.
w1t =2z1t= (1-B) 2z1t=(1-2B+B2)z1t,   and w2t =z2t=(1-B)z2t.
Then d1 = 2,d2 = 1d1=2,d2=1, d = max (d1,d2) = 2d=max(d1,d2)=2, and
delta =
[ δ11 δ12 δ21 ]
=
[ 2 − 1 1 ]
.
delta = [ δ11 δ12 δ21 ] = [ 2 -1 1 ] .

Example

function nag_tsa_multi_diff_example
z = [-1.49, -1.62, 5.2, 6.23, 6.21, 5.86, 4.09, 3.18, 2.62, 1.49, 1.17, ...
    0.85, -0.35, 0.24, 2.44, 2.58, 2.04, 0.4, 2.26, 3.34, 5.09, 5, 4.78, ...
    4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.5, 3.89, 1.58, 5.21, 5.25, 4.93, ...
    7.38, 5.87, 5.81, 9.68, 9.07, 7.29, 7.84, 7.55, 7.32, 7.97, 7.76, 7, 8.35;
     7.34, 6.35, 6.96, 8.54, 6.62, 4.97, 4.55, 4.81, 4.75, ...
    4.76, 10.88, 10.01, 11.62, 10.36, 6.4, 6.24, 7.93, 4.04, 3.73, 5.6, ...
    5.35, 6.81, 8.27, 7.68, 6.65, 6.08, 10.25, 9.14, 17.75, 13.3, ...
    9.63, 6.8, 4.08, 5.06, 4.94, 6.65, 7.94, 10.76, 11.89, ...
    5.85, 9.01, 7.5, 10.02, 10.38, 8.15, 8.37, 10.73, 12.14];
tr = {'N'; 'N'};
id = [int64(1);1];
delta = [1;
     1;
     0];
[w, nd, ifail] = nag_tsa_multi_diff(z, tr, id, delta)
 

w =

  Columns 1 through 9

   -0.1300    6.8200    1.0300   -0.0200   -0.3500   -1.7700   -0.9100   -0.5600   -1.1300
   -0.9900    0.6100    1.5800   -1.9200   -1.6500   -0.4200    0.2600   -0.0600    0.0100

  Columns 10 through 18

   -0.3200   -0.3200   -1.2000    0.5900    2.2000    0.1400   -0.5400   -1.6400    1.8600
    6.1200   -0.8700    1.6100   -1.2600   -3.9600   -0.1600    1.6900   -3.8900   -0.3100

  Columns 19 through 27

    1.0800    1.7500   -0.0900   -0.2200   -0.6700   -0.6600   -1.8000   -0.3600    2.8000
    1.8700   -0.2500    1.4600    1.4600   -0.5900   -1.0300   -0.5700    4.1700   -1.1100

  Columns 28 through 36

    2.2300    1.1800   -3.6100   -2.3100    3.6300    0.0400   -0.3200    2.4500   -1.5100
    8.6100   -4.4500   -3.6700   -2.8300   -2.7200    0.9800   -0.1200    1.7100    1.2900

  Columns 37 through 45

   -0.0600    3.8700   -0.6100   -1.7800    0.5500   -0.2900   -0.2300    0.6500   -0.2100
    2.8200    1.1300   -6.0400    3.1600   -1.5100    2.5200    0.3600   -2.2300    0.2200

  Columns 46 through 47

   -0.7600    1.3500
    2.3600    1.4100


nd =

                   47


ifail =

                    0


function g13dl_example
z = [-1.49, -1.62, 5.2, 6.23, 6.21, 5.86, 4.09, 3.18, 2.62, 1.49, 1.17, ...
    0.85, -0.35, 0.24, 2.44, 2.58, 2.04, 0.4, 2.26, 3.34, 5.09, 5, 4.78, ...
    4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.5, 3.89, 1.58, 5.21, 5.25, 4.93, ...
    7.38, 5.87, 5.81, 9.68, 9.07, 7.29, 7.84, 7.55, 7.32, 7.97, 7.76, 7, 8.35;
     7.34, 6.35, 6.96, 8.54, 6.62, 4.97, 4.55, 4.81, 4.75, ...
    4.76, 10.88, 10.01, 11.62, 10.36, 6.4, 6.24, 7.93, 4.04, 3.73, 5.6, ...
    5.35, 6.81, 8.27, 7.68, 6.65, 6.08, 10.25, 9.14, 17.75, 13.3, ...
    9.63, 6.8, 4.08, 5.06, 4.94, 6.65, 7.94, 10.76, 11.89, ...
    5.85, 9.01, 7.5, 10.02, 10.38, 8.15, 8.37, 10.73, 12.14];
tr = {'N'; 'N'};
id = [int64(1);1];
delta = [1;
     1;
     0];
[w, nd, ifail] = g13dl(z, tr, id, delta)
 

w =

  Columns 1 through 9

   -0.1300    6.8200    1.0300   -0.0200   -0.3500   -1.7700   -0.9100   -0.5600   -1.1300
   -0.9900    0.6100    1.5800   -1.9200   -1.6500   -0.4200    0.2600   -0.0600    0.0100

  Columns 10 through 18

   -0.3200   -0.3200   -1.2000    0.5900    2.2000    0.1400   -0.5400   -1.6400    1.8600
    6.1200   -0.8700    1.6100   -1.2600   -3.9600   -0.1600    1.6900   -3.8900   -0.3100

  Columns 19 through 27

    1.0800    1.7500   -0.0900   -0.2200   -0.6700   -0.6600   -1.8000   -0.3600    2.8000
    1.8700   -0.2500    1.4600    1.4600   -0.5900   -1.0300   -0.5700    4.1700   -1.1100

  Columns 28 through 36

    2.2300    1.1800   -3.6100   -2.3100    3.6300    0.0400   -0.3200    2.4500   -1.5100
    8.6100   -4.4500   -3.6700   -2.8300   -2.7200    0.9800   -0.1200    1.7100    1.2900

  Columns 37 through 45

   -0.0600    3.8700   -0.6100   -1.7800    0.5500   -0.2900   -0.2300    0.6500   -0.2100
    2.8200    1.1300   -6.0400    3.1600   -1.5100    2.5200    0.3600   -2.2300    0.2200

  Columns 46 through 47

   -0.7600    1.3500
    2.3600    1.4100


nd =

                   47


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