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 i$i$th series is di${\mathit{d}}_{i}$, then the differencing operator is defined by δi(B) = 1δi1Bδi2B2δidiBdi${\delta }_{i}\left(B\right)=1-{\delta }_{i1}B-{\delta }_{i2}{B}^{2}-\cdots -{\delta }_{i{\mathit{d}}_{i}}{B}^{{\mathit{d}}_{i}}$, where B$B$ is the backward shift operator; that is, BZt = Zt1$B{Z}_{t}={Z}_{t-1}$. Let d$\mathit{d}$ denote the maximum of the orders of differencing, di${\mathit{d}}_{i}$, over the k$k$ series. The function computes values of the differenced/transformed series Wt = (w1t,w2t,,wkt)T ${W}_{\mathit{t}}={\left({w}_{1\mathit{t}},{w}_{2\mathit{t}},\dots ,{w}_{\mathit{k}\mathit{t}}\right)}^{\mathrm{T}}$, for t = d + 1,,n$\mathit{t}=\mathit{d}+1,\dots ,n$, as follows:
 wit = δi(B)zit * ,  i = 1,2, … ,k $wit=δi(B)zit*, i=1,2,…,k$
where zit * ${z}_{it}^{*}$ are the transformed values of the original k$k$-dimensional time series Zt = (z1t,z2t,,zkt)T ${Z}_{t}={\left({z}_{1t},{z}_{2t},\dots ,{z}_{kt}\right)}^{\mathrm{T}}$.
The differencing parameters δij${\delta }_{ij}$, for i = 1,2,,k$i=1,2,\dots ,k$ and j = 1,2,,di$j=1,2,\dots ,{\mathit{d}}_{i}$, must be supplied by you. If the i$i$th series does not require differencing, then di = 0${\mathit{d}}_{i}=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 kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
z(i,t)${\mathbf{z}}\left(\mathit{i},\mathit{t}\right)$ must contain, zit${z}_{\mathit{i}\mathit{t}}$, the i$\mathit{i}$th component of Zt${Z}_{\mathit{t}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and t = 1,2,,n$\mathit{t}=1,2,\dots ,n$.
Constraints:
• if tr(i) = 'L'${\mathbf{tr}}\left(i\right)=\text{'L'}$, z(i,t) > 0.0${\mathbf{z}}\left(i,t\right)>0.0$;
• if tr(i) = 'S'${\mathbf{tr}}\left(i\right)=\text{'S'}$, z(i,t)0.0${\mathbf{z}}\left(\mathit{i},\mathit{t}\right)\ge 0.0$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and t = 1,2,,n$\mathit{t}=1,2,\dots ,n$.
2:     tr(k) – cell array of strings
k, the dimension of the array, must satisfy the constraint k1${\mathbf{k}}\ge 1$.
tr(i)${\mathbf{tr}}\left(\mathit{i}\right)$ indicates whether the i$\mathit{i}$th time series is to be transformed, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$.
tr(i) = 'N'${\mathbf{tr}}\left(i\right)=\text{'N'}$
No transformation is used.
tr(i) = 'L'${\mathbf{tr}}\left(i\right)=\text{'L'}$
A log transformation is used.
tr(i) = 'S'${\mathbf{tr}}\left(i\right)=\text{'S'}$
A square root transformation is used.
Constraint: tr(i) = 'N'${\mathbf{tr}}\left(\mathit{i}\right)=\text{'N'}$, 'L'$\text{'L'}$ or 'S'$\text{'S'}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$.
3:     id(k) – int64int32nag_int array
k, the dimension of the array, must satisfy the constraint k1${\mathbf{k}}\ge 1$.
The order of differencing for each series, d1,d2,,dk${\mathit{d}}_{1},{\mathit{d}}_{2},\dots ,{\mathit{d}}_{k}$.
Constraint: 0id(i) < n$0\le {\mathbf{id}}\left(\mathit{i}\right)<{\mathbf{n}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,{\mathbf{k}}$.
4:     delta(kmax, : $:$) – double array
The second dimension of the array must be at least max (1,d)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{d}\right)$, where d = max (id(i))$\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$
If id(i) > 0${\mathbf{id}}\left(i\right)>0$, then delta(i,j)${\mathbf{delta}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to δij${\delta }_{\mathit{i}\mathit{j}}$, for j = 1,2,,di$\mathit{j}=1,2,\dots ,{\mathit{d}}_{i}$ and i = 1,2,,k$\mathit{i}=1,2,\dots ,k$.
If d = 0$\mathit{d}=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.)
k$k$, the dimension of the multivariate time series.
Constraint: k1${\mathbf{k}}\ge 1$.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array z.
n$n$, the number of observations in the series, prior to differencing.
Constraint: n1${\mathbf{n}}\ge 1$.

kmax work

### Output Parameters

1:     w(kmax, : $:$) – double array
The second dimension of the array will be nd${\mathbf{n}}-\mathit{d}$, where d = max (id(i))$\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
w(i,t)${\mathbf{w}}\left(\mathit{i},\mathit{t}\right)$ contains the value of wi,t + d${w}_{\mathit{i},\mathit{t}+\mathit{d}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and t = 1,2,,nd$\mathit{t}=1,2,\dots ,n-\mathit{d}$.
2:     nd – int64int32nag_int scalar
The number of differenced values, nd$n-\mathit{d}$, in the series, where d = max (id(i))$\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{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${\mathbf{ifail}}=1$
 On entry, k < 1${\mathbf{k}}<1$, or n < 1${\mathbf{n}}<1$, or kmax < k$\mathit{kmax}<{\mathbf{k}}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, id(i) < 0${\mathbf{id}}\left(i\right)<0$, for some i = 1,2, … ,k$i=1,2,\dots ,k$, or id(i) ≥ n${\mathbf{id}}\left(i\right)\ge {\mathbf{n}}$, for some i = 1,2, … ,k$i=1,2,\dots ,k$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, at least one of the first k$k$ elements of tr is not equal to 'N', 'L' or 'S'.
ifail = 4${\mathbf{ifail}}=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.

The same differencing operator does not have to be applied to all the series. For example, suppose we have k = 2$k=2$, and wish to apply the second-order differencing operator 2${\nabla }^{2}$ to the first series and the first-order differencing operator $\nabla$ to the second series:
 w1t = ∇2z1t = (1 − B)2z1t = (1 − 2B + B2)z1t,   and w2t = ∇z2t = (1 − B)z2t.
$w1t =∇2z1t= (1-B) 2z1t=(1-2B+B2)z1t, and w2t =∇z2t=(1-B)z2t.$
Then d1 = 2,d2 = 1${\mathit{d}}_{1}=2,{\mathit{d}}_{2}=1$, d = max (d1,d2) = 2$\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathit{d}}_{1},{\mathit{d}}_{2}\right)=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