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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_multi_autocorr_part (g13db)

## Purpose

nag_tsa_multi_autocorr_part (g13db) calculates the multivariate partial autocorrelation function of a multivariate time series.

## Syntax

[p, v0, v, d, db, w, wb, nvp, ifail] = g13db(c0, c, nl, nk, 'ns', ns)
[p, v0, v, d, db, w, wb, nvp, ifail] = nag_tsa_multi_autocorr_part(c0, c, nl, nk, 'ns', ns)

## Description

The input is a set of lagged autocovariance matrices C0,C1,C2,,Cm${C}_{0},{C}_{1},{C}_{2},\dots ,{C}_{m}$. These will generally be sample values such as are obtained from a multivariate time series using nag_tsa_multi_corrmat_cross (g13dm).
The main calculation is the recursive determination of the coefficients in the finite lag (forward) prediction equation
 xt = Φl,1 xt − 1 + ⋯ + Φl,l xt − l + el,t $xt = Φl,1 xt-1 +⋯+ Φl,l xt-l + el,t$
and the associated backward prediction equation
 xt − l − 1 = Ψl,1xt − l + ⋯ + Ψl,lxt − 1 + fl,t $xt-l- 1=Ψl,1xt-l+⋯+Ψl,lxt- 1+fl,t$
together with the covariance matrices Dl${D}_{l}$ of el,t${e}_{l,t}$ and Gl${G}_{l}$ of fl,t${f}_{l,t}$.
The recursive cycle, by which the order of the prediction equation is extended from l$l$ to l + 1$l+1$, is to calculate
 Ml + 1 = Cl + 1T − Φl,1 ClT − ⋯ − Φl,l C1T $Ml+1 = Cl+1T - Φ l,1 ClT -⋯- Φl,l C1T$ (1)
then Φl + 1,l + 1 = Ml + 1 Dl1 ${\Phi }_{l+1,l+1}={M}_{l+1}{D}_{l}^{-1}$, Ψl + 1,l + 1 = MTl + 1 Gl1 $\text{ }{\Psi }_{l+1,l+1}={{M}^{\mathrm{T}}}_{l+1}{G}_{l}^{-1}$
from which
 Φl + 1,j = Φl,j − Φl + 1,l + 1Ψl,l + 1 − j,   j = 1,2, … ,l $Φl+1,j=Φl,j-Φl+1,l+1Ψl,l+1-j, j=1,2,…,l$ (2)
and
 Ψl + 1,j = Ψl,j − Ψl + 1,l + 1Φl,l + 1 − j,  j = 1,2, … ,l. $Ψl+1,j=Ψl,j-Ψl+1,l+1Φl,l+1-j, j=1,2,…,l.$ (3)
Finally, Dl + 1 = DlMl + 1ΦTl + 1,l + 1${D}_{l+1}={D}_{l}-{M}_{l+1}{{\Phi }^{\mathrm{T}}}_{l+1,l+1}$ and Gl + 1 = GlMTl + 1ΨTl + 1,l + 1${G}_{l+1}={G}_{l}-{{M}^{\mathrm{T}}}_{l+1}{{\Psi }^{\mathrm{T}}}_{l+1,l+1}$.
(Here T$\mathrm{T}$ denotes the transpose of a matrix.)
The cycle is initialized by taking (for l = 0$l=0$)
 D0 = G0 = C0. $D0=G0=C0.$
In the step from l = 0$l=0$ to 1$1$, the above equations contain redundant terms and simplify. Thus (1) becomes M1 = CT1${M}_{1}={{C}^{\mathrm{T}}}_{1}$ and neither (2) or (3) are needed.
Quantities useful in assessing the effectiveness of the prediction equation are generalized variance ratios
 vl = detDl / detC0 ,   l = 1,2, … $vl = det⁡Dl / det⁡C0 , l=1,2,…$
and multiple squared partial autocorrelations
 pl2 = 1 − vl / vl − 1 . $pl2 = 1 - vl / v l-1 .$

## References

Akaike H (1971) Autoregressive model fitting for control Ann. Inst. Statist. Math. 23 163–180
Whittle P (1963) On the fitting of multivariate autoregressions and the approximate canonical factorization of a spectral density matrix Biometrika 50 129–134

## Parameters

### Compulsory Input Parameters

1:     c0(ldc0,ns) – double array
ldc0, the first dimension of the array, must satisfy the constraint ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
Contains the zero lag cross-covariances between the ns series as returned by nag_tsa_multi_corrmat_cross (g13dm). (c0 is assumed to be symmetric, upper triangle only is used.)
2:     c(ldc0,ldc0,nl) – double array
ldc0, the first dimension of the array, must satisfy the constraint ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
Contains the cross-covariances at lags 1$1$ to nl. c(i,j,k)${\mathbf{c}}\left(i,j,k\right)$ must contain the cross-covariance, cijk${c}_{ijk}$, of series i$i$ and series j$j$ at lag k$k$. Series j$j$ leads series i$i$.
3:     nl – int64int32nag_int scalar
m$m$, the maximum lag for which cross-covariances are supplied in c.
Constraint: nl1${\mathbf{nl}}\ge 1$.
4:     nk – int64int32nag_int scalar
The number of lags to which partial auto-correlations are to be calculated.
Constraint: 1nknl$1\le {\mathbf{nk}}\le {\mathbf{nl}}$.

### Optional Input Parameters

1:     ns – int64int32nag_int scalar
Default: The second dimension of the array c0.
k$k$, the number of time series whose cross-covariances are supplied in c and c0.
Constraint: ns1${\mathbf{ns}}\ge 1$.

ldc0 wa iwa

### Output Parameters

1:     p(nk) – double array
The multiple squared partial autocorrelations from lags 1$1$ to nvp; that is, p(l)${\mathbf{p}}\left(l\right)$ contains pl2${p}_{\mathit{l}}^{2}$, for l = 1,2,,nvp$\mathit{l}=1,2,\dots ,{\mathbf{nvp}}$. For lags nvp + 1${\mathbf{nvp}}+1$ to nk the elements of p are set to zero.
2:     v0 – double scalar
The lag zero prediction error variance (equal to the determinant of c0).
3:     v(nk) – double array
The prediction error variance ratios from lags 1$1$ to nvp; that is, v(l)${\mathbf{v}}\left(\mathit{l}\right)$ contains vl${v}_{\mathit{l}}$, for l = 1,2,,nvp$\mathit{l}=1,2,\dots ,{\mathbf{nvp}}$. For lags nvp + 1${\mathbf{nvp}}+1$ to nk the elements of v are set to zero.
4:     d(ldc0,ldc0,nk) – double array
ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
The prediction error variance matrices at lags 1$1$ to nvp.
Element (i,j,k)$\left(i,j,\mathit{k}\right)$ of d contains the prediction error covariance of series i$i$ and series j$j$ at lag k$\mathit{k}$, for k = 1,2,,nvp$\mathit{k}=1,2,\dots ,{\mathbf{nvp}}$. Series j$j$ leads series i$i$; that is, the (i,j)$\left(i,j\right)$th element of Dk${D}_{k}$. For lags nvp + 1${\mathbf{nvp}}+1$ to nk the elements of d are set to zero.
5:     db(ldc0,ns) – double array
ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
The backward prediction error variance matrix at lag nvp.
db(i,j)${\mathbf{db}}\left(i,j\right)$ contains the backward prediction error covariance of series i$i$ and series j$j$; that is, the (i,j)$\left(i,j\right)$th element of the Gk${G}_{k}$, where k = nvp$k={\mathbf{nvp}}$.
6:     w(ldc0,ldc0,nk) – double array
ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
The prediction coefficient matrices at lags 1$1$ to nvp.
w(i,j,l)${\mathbf{w}}\left(i,j,\mathit{l}\right)$ contains the j$j$th prediction coefficient of series i$i$ at lag l$\mathit{l}$; that is, the (i,j)$\left(i,j\right)$th element of Φkl${\Phi }_{k\mathit{l}}$, where k = nvp$k={\mathbf{nvp}}$, for l = 1,2,,nvp$\mathit{l}=1,2,\dots ,{\mathbf{nvp}}$. For lags nvp + 1${\mathbf{nvp}}+1$ to nk the elements of w are set to zero.
7:     wb(ldc0,ldc0,nk) – double array
ldc0max (ns,1)$\mathit{ldc0}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
The backward prediction coefficient matrices at lags 1$1$ to nvp.
wb(i,j,l)${\mathbf{wb}}\left(i,j,\mathit{l}\right)$ contains the j$j$th backward prediction coefficient of series i$i$ at lag l$\mathit{l}$; that is, the (i,j)$\left(i,j\right)$th element of Ψkl${\Psi }_{k\mathit{l}}$, where k = nvp$k={\mathbf{nvp}}$, for l = 1,2,,nvp$\mathit{l}=1,2,\dots ,{\mathbf{nvp}}$. For lags nvp + 1${\mathbf{nvp}}+1$ to nk the elements of wb are set to zero.
8:     nvp – int64int32nag_int scalar
The maximum lag, L$L$, for which calculation of p, v, d, db, w and wb was successful. If the function completes successfully nvp will equal nk.
9:     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:

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, ldc0 < 1$\mathit{ldc0}<1$, or ns < 1${\mathbf{ns}}<1$, or ns > ldc0${\mathbf{ns}}>\mathit{ldc0}$, or nl < 1${\mathbf{nl}}<1$, or nk < 1${\mathbf{nk}}<1$, or nk > nl${\mathbf{nk}}>{\mathbf{nl}}$, or iwa < (2 × ns + 1) × ns$\mathit{iwa}<\left(2×{\mathbf{ns}}+1\right)×{\mathbf{ns}}$.
ifail = 2${\mathbf{ifail}}=2$
c0 is not positive definite.
v0, v, p, d, db, w, wb and nvp are set to zero.
W ifail = 3${\mathbf{ifail}}=3$
At lag k = nvp + 1nk$k={\mathbf{nvp}}+1\le {\mathbf{nk}}$, Dk${D}_{k}$ was found not to be positive definite. Up to lag nvp, v0, v, p, d, w and wb contain the values calculated so far and from lag nvp + 1${\mathbf{nvp}}+1$ to lag nk the matrices contain zero. db contains the backward prediction coefficients for lag nvp.

## Accuracy

The conditioning of the problem depends on the prediction error variance ratios. Very small values of these may indicate loss of accuracy in the computations.

The time taken by nag_tsa_multi_autocorr_part (g13db) is roughly proportional to nk2 × ns3${{\mathbf{nk}}}^{2}×{{\mathbf{ns}}}^{3}$.
If sample autocorrelation matrices are used as input, then the output will be relevant to the original series scaled by their standard deviations. If these autocorrelation matrices are produced by nag_tsa_multi_corrmat_cross (g13dm), you must replace the diagonal elements of C0${C}_{0}$ (otherwise used to hold the series variances) by 1$1$.

## Example

```function nag_tsa_multi_autocorr_part_example
c0 = [0.0109, -0.0077917, 0.0013004, 0.0012654;
-0.0077917, 0.05704, 0.002418, 0.014409;
0.0013004, 0.002418, 0.04396, -0.021421;
0.0012654, 0.014409, -0.021421, 0.072289];
c(:,:,1) = ...
[0.0045889, 0.0004651 -0.00013275,  0.0077531;
-0.0024419,  -0.011667,  -0.021956, -0.0045803;
0.001108, -0.0080479,   0.013621, -0.0085868;
-0.00050614,   0.014045, -0.0010087,   0.012269];
c(:,:,2) = ...
[0.0018652, -0.0064389,  0.0088307, -0.0024808;
-0.011865,  0.0072367,  -0.019802,  0.0059069;
-0.0080307,   0.014306,   0.014546,    0.01351;
-0.0021791,  -0.029528,  -0.015887, 0.00088308];
c(:,:,3) = ...
[-8.055e-005, -0.0037759,  0.0075463, -0.0042276;
0.0041447, -0.0037987,  0.0019332,  -0.017564;
-0.010582,  0.0067733,  0.0069832,  0.0061747;
0.0041352,  -0.016013,   0.017043,  -0.013412];
c(:,:,4) = ...
[0.00076079, -0.0010134,    0.01187, -0.0041651;
0.0036014, -0.0036375,  -0.025571,  0.0050218;
-0.013924,   0.011718, -0.0059088,  0.0059297;
0.010739,  -0.014571,   0.013816,  -0.012588];
c(:,:,5) = ...
[-0.00064365, -0.0044556,  0.0051334, 0.00071587;
0.0063617, 0.00015217,   0.002727, -0.0022261;
-0.0085855,  0.0014468, -0.0028698,  0.0044384;
0.0068339,  -0.002179,   0.013759, 0.00028217];
nl = int64(5);
nk = int64(3);
[p, v0, v, d, db, w, wb, nvp, ifail] = ...
nag_tsa_multi_autocorr_part(c0, c, nl, nk)
```
```

p =

0.6450
0.9267
0.8430

v0 =

1.3670e-06

v =

0.3550
0.0260
0.0041

d(:,:,1) =

0.0081   -0.0051    0.0016   -0.0003
-0.0051    0.0409    0.0076    0.0184
0.0016    0.0076    0.0383   -0.0189
-0.0003    0.0184   -0.0189    0.0676

d(:,:,2) =

0.0035   -0.0009   -0.0007   -0.0011
-0.0009    0.0195    0.0053    0.0057
-0.0007    0.0053    0.0190   -0.0107
-0.0011    0.0057   -0.0107    0.0406

d(:,:,3) =

0.0030   -0.0009   -0.0005    0.0007
-0.0009    0.0182    0.0087    0.0025
-0.0005    0.0087    0.0093   -0.0022
0.0007    0.0025   -0.0022    0.0225

db =

0.0033   -0.0039   -0.0011    0.0059
-0.0039    0.0189    0.0035   -0.0033
-0.0011    0.0035    0.0100   -0.0105
0.0059   -0.0033   -0.0105    0.0334

w(:,:,1) =

0.8186    0.2340   -0.1710    0.0926
0.0674   -0.4872   -0.1406    0.0429
0.1504    0.1192   -0.3672   -0.4209
-0.7097    0.0300    0.5978    0.3461

w(:,:,2) =

-0.3405   -0.1337    0.4061   -0.0218
-1.2757   -0.1359   -0.6578   -0.1127
-0.4544    0.1938    0.6342    0.3392
-0.4324   -0.5485   -0.6290    0.1667

w(:,:,3) =

0.1644    0.1386    0.0129    0.0346
0.3929    0.0741   -0.0880   -0.1536
-1.2924   -0.2449    0.3023    0.3944
0.8977   -0.3904    0.2515   -0.2830

wb(:,:,1) =

0.4154    0.0615    0.1532    0.0508
0.1237   -0.2647   -0.2272    0.4850
-0.8693   -0.4737    0.3792    0.1381
1.3078   -0.0918   -1.4540   -0.2197

wb(:,:,2) =

-0.0674   -0.1226   -0.1367   -0.0973
-1.2480    0.0309    0.5171   -0.2892
0.9804   -0.2019    0.1631   -0.1087
-1.6839   -0.7459    0.5290    0.4158

wb(:,:,3) =

0.0379    0.1049   -0.2164    0.0801
0.7539    0.2260   -0.2566   -0.4745
-0.0034    0.0564   -0.0882    0.1272
0.5502   -0.4123    0.7165   -0.1457

nvp =

3

ifail =

0

```
```function g13db_example
c0 = [0.0109, -0.0077917, 0.0013004, 0.0012654;
-0.0077917, 0.05704, 0.002418, 0.014409;
0.0013004, 0.002418, 0.04396, -0.021421;
0.0012654, 0.014409, -0.021421, 0.072289];
c(:,:,1) = ...
[0.0045889, 0.0004651 -0.00013275,  0.0077531;
-0.0024419,  -0.011667,  -0.021956, -0.0045803;
0.001108, -0.0080479,   0.013621, -0.0085868;
-0.00050614,   0.014045, -0.0010087,   0.012269];
c(:,:,2) = ...
[0.0018652, -0.0064389,  0.0088307, -0.0024808;
-0.011865,  0.0072367,  -0.019802,  0.0059069;
-0.0080307,   0.014306,   0.014546,    0.01351;
-0.0021791,  -0.029528,  -0.015887, 0.00088308];
c(:,:,3) = ...
[-8.055e-005, -0.0037759,  0.0075463, -0.0042276;
0.0041447, -0.0037987,  0.0019332,  -0.017564;
-0.010582,  0.0067733,  0.0069832,  0.0061747;
0.0041352,  -0.016013,   0.017043,  -0.013412];
c(:,:,4) = ...
[0.00076079, -0.0010134,    0.01187, -0.0041651;
0.0036014, -0.0036375,  -0.025571,  0.0050218;
-0.013924,   0.011718, -0.0059088,  0.0059297;
0.010739,  -0.014571,   0.013816,  -0.012588];
c(:,:,5) = ...
[-0.00064365, -0.0044556,  0.0051334, 0.00071587;
0.0063617, 0.00015217,   0.002727, -0.0022261;
-0.0085855,  0.0014468, -0.0028698,  0.0044384;
0.0068339,  -0.002179,   0.013759, 0.00028217];
nl = int64(5);
nk = int64(3);
[p, v0, v, d, db, w, wb, nvp, ifail] = g13db(c0, c, nl, nk)
```
```

p =

0.6450
0.9267
0.8430

v0 =

1.3670e-06

v =

0.3550
0.0260
0.0041

d(:,:,1) =

0.0081   -0.0051    0.0016   -0.0003
-0.0051    0.0409    0.0076    0.0184
0.0016    0.0076    0.0383   -0.0189
-0.0003    0.0184   -0.0189    0.0676

d(:,:,2) =

0.0035   -0.0009   -0.0007   -0.0011
-0.0009    0.0195    0.0053    0.0057
-0.0007    0.0053    0.0190   -0.0107
-0.0011    0.0057   -0.0107    0.0406

d(:,:,3) =

0.0030   -0.0009   -0.0005    0.0007
-0.0009    0.0182    0.0087    0.0025
-0.0005    0.0087    0.0093   -0.0022
0.0007    0.0025   -0.0022    0.0225

db =

0.0033   -0.0039   -0.0011    0.0059
-0.0039    0.0189    0.0035   -0.0033
-0.0011    0.0035    0.0100   -0.0105
0.0059   -0.0033   -0.0105    0.0334

w(:,:,1) =

0.8186    0.2340   -0.1710    0.0926
0.0674   -0.4872   -0.1406    0.0429
0.1504    0.1192   -0.3672   -0.4209
-0.7097    0.0300    0.5978    0.3461

w(:,:,2) =

-0.3405   -0.1337    0.4061   -0.0218
-1.2757   -0.1359   -0.6578   -0.1127
-0.4544    0.1938    0.6342    0.3392
-0.4324   -0.5485   -0.6290    0.1667

w(:,:,3) =

0.1644    0.1386    0.0129    0.0346
0.3929    0.0741   -0.0880   -0.1536
-1.2924   -0.2449    0.3023    0.3944
0.8977   -0.3904    0.2515   -0.2830

wb(:,:,1) =

0.4154    0.0615    0.1532    0.0508
0.1237   -0.2647   -0.2272    0.4850
-0.8693   -0.4737    0.3792    0.1381
1.3078   -0.0918   -1.4540   -0.2197

wb(:,:,2) =

-0.0674   -0.1226   -0.1367   -0.0973
-1.2480    0.0309    0.5171   -0.2892
0.9804   -0.2019    0.1631   -0.1087
-1.6839   -0.7459    0.5290    0.4158

wb(:,:,3) =

0.0379    0.1049   -0.2164    0.0801
0.7539    0.2260   -0.2566   -0.4745
-0.0034    0.0564   -0.0882    0.1272
0.5502   -0.4123    0.7165   -0.1457

nvp =

3

ifail =

0

```