# NAG FL Interfaceg13dnf (multi_​corrmat_​partlag)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g13dnf 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 g13dmf is usually made prior to calling this routine in order to calculate the sample cross-correlation matrices.

## 2Specification

Fortran Interface
 Subroutine g13dnf ( k, n, m, kmax, r0, r, x, work,
 Integer, Intent (In) :: k, n, m, kmax, lwork Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: maxlag Real (Kind=nag_wp), Intent (In) :: r0(kmax,k), r(kmax,kmax,m) Real (Kind=nag_wp), Intent (Inout) :: parlag(kmax,kmax,m) Real (Kind=nag_wp), Intent (Out) :: x(m), pvalue(m), work(lwork)
#include <nag.h>
 void g13dnf_ (const Integer *k, const Integer *n, const Integer *m, const Integer *kmax, const double r0[], const double r[], Integer *maxlag, double parlag[], double x[], double pvalue[], double work[], const Integer *lwork, Integer *ifail)
The routine may be called by the names g13dnf or nagf_tsa_multi_corrmat_partlag.

## 3Description

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.
1. (i)If ${W}_{t}$ follows a vector autoregressive model of order $p$, then $P\left(l\right)=0$ for $l>p$;
2. (ii)When $k=1$, $P\left(l\right)$ reduces to the univariate partial autocorrelation at lag $l$;
3. (iii)Each element of $P\left(l\right)$ is a properly normalized correlation coefficient;
4. (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 g13dnf. These may be computed by g13dmf. 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
 $X(s)=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.
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

## 5Arguments

1: $\mathbf{k}$Integer Input
On entry: $k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{k}}\ge 1$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations in each series.
Constraint: ${\mathbf{n}}\ge 2$.
3: $\mathbf{m}$Integer Input
On entry: $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}}$.
4: $\mathbf{kmax}$Integer Input
On entry: the first dimension of the arrays r0, r and parlag and the second dimension of the arrays r and parlag as declared in the (sub)program from which g13dnf is called.
Constraint: ${\mathbf{kmax}}\ge {\mathbf{k}}$.
5: $\mathbf{r0}\left({\mathbf{kmax}},{\mathbf{k}}\right)$Real (Kind=nag_wp) array Input
On entry: 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.
6: $\mathbf{r}\left({\mathbf{kmax}},{\mathbf{kmax}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\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 Section 9).
7: $\mathbf{maxlag}$Integer Output
On exit: 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, maxlag will be less than m.
8: $\mathbf{parlag}\left({\mathbf{kmax}},{\mathbf{kmax}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\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$.
9: $\mathbf{x}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{x}}\left(\mathit{l}\right)$ contains the ${\chi }^{2}$-statistic at lag $\mathit{l}$, for $\mathit{l}=1,2,\dots ,{\mathbf{maxlag}}$.
10: $\mathbf{pvalue}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\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}}$.
11: $\mathbf{work}\left({\mathbf{lwork}}\right)$Real (Kind=nag_wp) array Workspace
12: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which g13dnf is called.
Constraint: ${\mathbf{lwork}}\ge \left(5{\mathbf{m}}+6\right){{\mathbf{k}}}^{2}+{\mathbf{k}}$.
13: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{k}}\ge 1$.
On entry, ${\mathbf{kmax}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{kmax}}\ge {\mathbf{k}}$.
On entry, ${\mathbf{lwork}}=⟨\mathit{\text{value}}⟩$ and the minimum size $\text{required}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lwork}}\ge \left(5×{\mathbf{m}}+6\right)×{{\mathbf{k}}}^{2}+{\mathbf{k}}$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}<{\mathbf{n}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=2$
The recursive equations used to compute the partial lag correlation matrices are ill-conditioned (they have been computed up to lag $⟨\mathit{\text{value}}⟩$). All output quantities in the arrays parlag, x and pvalue up to and including lag maxlag will be correct.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

g13dnf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13dnf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 g13dmf, then care must be taken to ensure they are supplied as described in Section 5. 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 routine g13dbf 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 routine 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 g13dbf. Note that this is the ‘Yule–Walker’ estimate. Unlike the partial lag correlation matrices computed by g13dnf, 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 g13dbf takes the sample cross-covariance matrices as input whereas this routine requires the sample cross-correlation matrices to be input.

## 10Example

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.

### 10.1Program Text

Program Text (g13dnfe.f90)

### 10.2Program Data

Program Data (g13dnfe.d)

### 10.3Program Results

Program Results (g13dnfe.r)