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_corrmat_partlag (g13dn)

## Purpose

nag_tsa_multi_corrmat_partlag (g13dn) calculates the sample partial lag correlation matrices of a multivariate time series. A set of ${\chi }^{2}$-statistics and their significance levels are also returned. A call to nag_tsa_multi_corrmat_cross (g13dm) is usually made prior to calling this function in order to calculate the sample cross-correlation matrices.

## Syntax

[maxlag, parlag, x, pvalue, ifail] = g13dn(n, m, r0, r, 'k', k)
[maxlag, parlag, x, pvalue, ifail] = nag_tsa_multi_corrmat_partlag(n, m, r0, r, 'k', k)

## Description

Let ${W}_{\mathit{t}}={\left({w}_{1\mathit{t}},{w}_{2\mathit{t}},\dots ,{w}_{\mathit{k}\mathit{t}}\right)}^{\mathrm{T}}$, for $\mathit{t}=1,2,\dots ,n$, denote $n$ observations of a vector of $k$ time series. The partial lag correlation matrix at lag $l$, $P\left(l\right)$, is defined to be the correlation matrix between ${W}_{t}$ and ${W}_{t+l}$, after removing the linear dependence on each of the intervening vectors ${W}_{t+1},{W}_{t+2},\dots ,{W}_{t+l-1}$. It is the correlation matrix between the residual vectors resulting from the regression of ${W}_{t+l}$ on the carriers ${W}_{t+l-1},\dots ,{W}_{t+1}$ and the regression of ${W}_{t}$ on the same set of carriers; see Heyse and Wei (1985).
$P\left(l\right)$ has the following properties.
 (i) If ${W}_{t}$ follows a vector autoregressive model of order $p$, then $P\left(l\right)=0$ for $l>p$; (ii) When $k=1$, $P\left(l\right)$ reduces to the univariate partial autocorrelation at lag $l$; (iii) Each element of $P\left(l\right)$ is a properly normalized correlation coefficient; (iv) When $l=1$, $P\left(l\right)$ is equal to the cross-correlation matrix at lag $1$ (a natural property which also holds for the univariate partial autocorrelation function).
Sample estimates of the partial lag correlation matrices may be obtained using the recursive algorithm described in Wei (1990). They are calculated up to lag $m$, which is usually taken to be at most $n/4$. Only the sample cross-correlation matrices ($\stackrel{^}{R}\left(\mathit{l}\right)$, for $\mathit{l}=0,1,\dots ,m$) and the standard deviations of the series are required as input to nag_tsa_multi_corrmat_partlag (g13dn). These may be computed by nag_tsa_multi_corrmat_cross (g13dm). Under the hypothesis that ${W}_{t}$ follows an autoregressive model of order $s-1$, the elements of the sample partial lag matrix $\stackrel{^}{P}\left(s\right)$, denoted by ${\stackrel{^}{P}}_{ij}\left(s\right)$, are asymptotically Normally distributed with mean zero and variance $1/n$. In addition the statistic
 $Xs=n∑i=1k∑j=1kP^ij s 2$
has an asymptotic ${\chi }^{2}$-distribution with ${k}^{2}$ degrees of freedom. These quantities, $X\left(l\right)$, are useful as a diagnostic aid for determining whether the series follows an autoregressive model and, if so, of what order.

## References

Heyse J F and Wei W W S (1985) The partial lag autocorrelation function Technical Report No. 32 Department of Statistics, Temple University, Philadelphia
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of observations in each series.
Constraint: ${\mathbf{n}}\ge 2$.
2:     $\mathrm{m}$int64int32nag_int scalar
$m$, the number of partial lag correlation matrices to be computed. Note this also specifies the number of sample cross-correlation matrices that must be contained in the array r.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
3:     $\mathrm{r0}\left(\mathit{kmax},{\mathbf{k}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
If $i\ne j$, then ${\mathbf{r0}}\left(i,j\right)$ must contain the $\left(i,j\right)$th element of the sample cross-correlation matrix at lag zero, ${\stackrel{^}{R}}_{ij}\left(0\right)$. If $i=j$, then ${\mathbf{r0}}\left(i,i\right)$ must contain the standard deviation of the $i$th series.
4:     $\mathrm{r}\left(\mathit{kmax},\mathit{kmax},{\mathbf{m}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
${\mathbf{r}}\left(i,j,l\right)$ must contain the $\left(i,j\right)$th element of the sample cross-correlation at lag $l$, ${\stackrel{^}{R}}_{\mathit{i}\mathit{j}}\left(\mathit{l}\right)$, for $\mathit{l}=1,2,\dots ,m$, $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,k$, where series $\mathit{j}$ leads series $\mathit{i}$ (see Further Comments).

### Optional Input Parameters

1:     $\mathrm{k}$int64int32nag_int scalar
Default: the first dimension of the arrays r0, r and the second dimension of the array r0. (An error is raised if these dimensions are not equal.)
$k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{k}}\ge 1$.

### Output Parameters

1:     $\mathrm{maxlag}$int64int32nag_int scalar
The maximum lag up to which partial lag correlation matrices (along with ${\chi }^{2}$-statistics and their significance levels) have been successfully computed. On a successful exit maxlag will equal m. If ${\mathbf{ifail}}={\mathbf{2}}$ on exit, then maxlag will be less than m.
2:     $\mathrm{parlag}\left(\mathit{kmax},\mathit{kmax},{\mathbf{m}}\right)$ – double array
${\mathbf{parlag}}\left(i,j,l\right)$ contains the $\left(i,j\right)$th element of the sample partial lag correlation matrix at lag $l$, ${\stackrel{^}{P}}_{\mathit{i}\mathit{j}}\left(\mathit{l}\right)$, for $\mathit{l}=1,2,\dots ,{\mathbf{maxlag}}$, $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,k$.
3:     $\mathrm{x}\left({\mathbf{m}}\right)$ – double array
${\mathbf{x}}\left(\mathit{l}\right)$ contains the ${\chi }^{2}$-statistic at lag $\mathit{l}$, for $\mathit{l}=1,2,\dots ,{\mathbf{maxlag}}$.
4:     $\mathrm{pvalue}\left({\mathbf{m}}\right)$ – double array
${\mathbf{pvalue}}\left(\mathit{l}\right)$ contains the significance level of the corresponding ${\chi }^{2}$-statistic in x, for $\mathit{l}=1,2,\dots ,{\mathbf{maxlag}}$.
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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.

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{k}}<1$, or ${\mathbf{n}}<2$, or ${\mathbf{m}}<1$, or ${\mathbf{m}}\ge {\mathbf{n}}$, or $\mathit{kmax}<{\mathbf{k}}$, or $\mathit{lwork}<\left(5{\mathbf{m}}+6\right){{\mathbf{k}}}^{2}+{\mathbf{k}}$.
W  ${\mathbf{ifail}}=2$
The recursive equations used to compute the sample partial lag correlation matrices have broken down at lag ${\mathbf{maxlag}}+1$. All output quantities in the arrays parlag, x and pvalue up to and including lag maxlag will be correct.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The accuracy will depend upon the accuracy of the sample cross-correlations.

The time taken is roughly proportional to ${m}^{2}{k}^{3}$.
If you have calculated the sample cross-correlation matrices in the arrays r0 and r, without calling nag_tsa_multi_corrmat_cross (g13dm), then care must be taken to ensure they are supplied as described in Arguments. In particular, for $l\ge 1$, ${\stackrel{^}{R}}_{ij}\left(l\right)$ must contain the sample cross-correlation coefficient between ${w}_{i\left(t-l\right)}$ and ${w}_{jt}$.
The function nag_tsa_multi_autocorr_part (g13db) computes squared partial autocorrelations for a specified number of lags. It may also be used to estimate a sequence of partial autoregression matrices at lags $1,2,\dots \text{}$ by making repeated calls to the function with the argument nk set to $1,2,\dots \text{}$. The $\left(i,j\right)$th element of the sample partial autoregression matrix at lag $l$ is given by $W\left(i,j,l\right)$ when nk is set equal to $l$ on entry to nag_tsa_multi_autocorr_part (g13db). Note that this is the ‘Yule–Walker’ estimate. Unlike the partial lag correlation matrices computed by nag_tsa_multi_corrmat_partlag (g13dn), when ${W}_{t}$ follows an autoregressive model of order $s-1$, the elements of the sample partial autoregressive matrix at lag $s$ do not have variance $1/n$, making it very difficult to spot a possible cut-off point. The differences between these matrices are discussed further by Wei (1990).
Note that nag_tsa_multi_autocorr_part (g13db) takes the sample cross-covariance matrices as input whereas this function requires the sample cross-correlation matrices to be input.

## Example

This example computes the sample partial lag correlation matrices of two time series of length $48$, up to lag $10$. The matrices, their ${\chi }^{2}$-statistics and significance levels and a plot of symbols indicating which elements of the sample partial lag correlation matrices are significant are printed. Three * represent significance at the $0.5$% level, two * represent significance at the 1% level and a single * represents significance at the 5% level. The * are plotted above or below the central line depending on whether the elements are significant in a positive or negative direction.
```function g13dn_example

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

w = [-1.49, -1.62, 5.20, 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.40, 2.26, 3.34, 5.09, 5.00, ...
4.78,  4.11, 3.45, 1.65, 1.29, 4.09, 6.32, 7.50, 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.00, 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.40, 6.24, 7.93, 4.04, 3.73, 5.60, 5.35, 6.81, ...
8.27,  7.68, 6.65, 6.08,10.25, 9.14,17.75,13.30, 9.63, 6.80, 4.08, ...
5.06,  4.94, 6.65, 7.94,10.76,11.89, 5.85, 9.01, 7.50,10.02,10.38, ...
8.15, 8.37, 10.73, 12.14];
[k,n] = size(w);
k = int64(k);
n = int64(n);
m = int64(10);
matrix = 'R';

% Calculate cross correlations
[wmean, r0, r, ifail] = g13dm( ...
matrix, k, m, w);

% Calculate sample partial lag correlation matrices
[maxlag, parlag, x, pvalue, ifail] = ...
g13dn( ...
n, m, r0, r);

disp('Partial Lag Correlation Matrices');
for l = 1:m
fprintf('Lag = %d\n',l);
disp(parlag(:,:,l));
end
sn1 = 1/sqrt(double(n));
fprintf('Standard error = 1/sqrt(n) = %7.4f\n\n',sn1);

disp('Tables Of Indicator Symbols');
fprintf('\nFor Lags 1 to %d\n',m);
lhs = {'              0.005  :'; '        +     0.01   :';
'              0.05   :';
'   Sig. Level        :- - - - - - - - - -  Lags';
'              0.05   :';
'        -     0.01   :'; '              0.005  :'};
c = sn1*[3.29, 2.58, 1.96, 0, -1.96, -2.58, -3.29];
for i = 1:k
for j=1:k
if i==j
fprintf('\nAuto-correlation function for series %d\n', i);
else
fprintf('\nCross-correlation function for series %d and series %d\n', ...
i, j);
end
rhs = lhs;
for t = 1:m
for u = 1:3
if parlag(i,j,t)>c(u)
rhs{u} = strcat(rhs{u},'*');
end
end
for u = 5:7
if parlag(i,j,t)<c(u)
rhs{u} = strcat(rhs{u},'*');
end
end
end
fprintf('\n');
fprintf('%s\n',rhs{1:end});
end
end

fprintf('\n Lag     Chi-square statistic     P-value\n\n');
ilag = double([1:m]);
fprintf('%4d%18.3f%19.4f\n',[ilag; x'; pvalue']);

```
```g13dn example results

Partial Lag Correlation Matrices
Lag = 1
0.7359    0.1743
0.2114    0.5546

Lag = 2
-0.1869   -0.0832
-0.1805   -0.0724

Lag = 3
0.2775   -0.0069
0.0837   -0.2133

Lag = 4
-0.0843    0.2269
0.1284   -0.1764

Lag = 5
0.2361    0.2384
-0.0468   -0.0455

Lag = 6
-0.0164    0.0873
0.0996   -0.0809

Lag = 7
-0.0355    0.2611
0.1258    0.0120

Lag = 8
0.0767    0.3814
0.0268   -0.1492

Lag = 9
-0.0651   -0.3868
0.1887    0.0564

Lag = 10
-0.0261   -0.2861
0.0279   -0.1729

Standard error = 1/sqrt(n) =  0.1443

Tables Of Indicator Symbols

For Lags 1 to 10

Auto-correlation function for series 1

0.005  :*
+     0.01   :*
0.05   :*
Sig. Level        :- - - - - - - - - -  Lags
0.05   :
-     0.01   :
0.005  :

Cross-correlation function for series 1 and series 2

0.005  :
+     0.01   :*
0.05   :*
Sig. Level        :- - - - - - - - - -  Lags
0.05   :**
-     0.01   :*
0.005  :

Cross-correlation function for series 2 and series 1

0.005  :
+     0.01   :
0.05   :
Sig. Level        :- - - - - - - - - -  Lags
0.05   :
-     0.01   :
0.005  :

Auto-correlation function for series 2

0.005  :*
+     0.01   :*
0.05   :*
Sig. Level        :- - - - - - - - - -  Lags
0.05   :
-     0.01   :
0.005  :

Lag     Chi-square statistic     P-value

1            44.363             0.0000
2             3.825             0.4302
3             6.220             0.1833
4             5.096             0.2776
5             5.609             0.2303
6             1.169             0.8832
7             4.098             0.3929
8             8.368             0.0790
9             9.248             0.0552
10             5.434             0.2456
```