G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13DPF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G13DPF calculates the sample partial autoregression matrices of a multivariate time series. A set of likelihood ratio statistics and their significance levels are also returned. These quantities are useful for determining whether the series follows an autoregressive model and, if so, of what order.

## 2  Specification

 SUBROUTINE G13DPF ( K, N, Z, KMAX, M, MAXLAG, PARLAG, SE, QQ, X, PVALUE, LOGLHD, WORK, LWORK, IWORK, IFAIL)
 INTEGER K, N, KMAX, M, MAXLAG, LWORK, IWORK(K*M), IFAIL REAL (KIND=nag_wp) Z(KMAX,N), PARLAG(KMAX,KMAX,M), SE(KMAX,KMAX,M), QQ(KMAX,KMAX,M), X(M), PVALUE(M), LOGLHD(M), WORK(LWORK)

## 3  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 a vector of $k$ time series. The partial autoregression matrix at lag $l$, ${P}_{l}$, is defined to be the last matrix coefficient when a vector autoregressive model of order $l$ is fitted to the series. ${P}_{l}$ has the property that if ${W}_{t}$ follows a vector autoregressive model of order $p$ then ${P}_{l}=0$ for $l>p$.
Sample estimates of the partial autoregression matrices may be obtained by fitting autoregressive models of successively higher orders by multivariate least squares; see Tiao and Box (1981) and Wei (1990). These models are fitted using a $QR$ algorithm based on the routines G02DCF and G02DFF. They are calculated up to lag $m$, which is usually taken to be at most $n/4$.
The routine also returns the asymptotic standard errors of the elements of ${\stackrel{^}{P}}_{l}$ and an estimate of the residual variance-covariance matrix ${\stackrel{^}{\Sigma }}_{l}$, for $l=1,2,\dots ,m$. If ${S}_{l}$ denotes the residual sum of squares and cross-products matrix after fitting an $\text{AR}\left(l\right)$ model to the series then under the null hypothesis ${H}_{0}:{P}_{l}=0$ the test statistic
 $Xl= - n-m-1 -12-lk log Sl Sl-1$
is asymptotically distributed as ${\chi }^{2}$ with ${k}^{2}$ degrees of freedom. ${X}_{l}$ provides a useful diagnostic aid in determining the order of an autoregressive model. (Note that ${\stackrel{^}{\Sigma }}_{l}={S}_{l}/\left(n-l\right)$.) The routine also returns an estimate of the maximum of the log-likelihood function for each AR model that has been fitted.

## 4  References

Tiao G C and Box G E P (1981) Modelling multiple time series with applications J. Am. Stat. Assoc. 76 802–816
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley

## 5  Parameters

1:     K – INTEGERInput
On entry: $k$, the number of time series.
Constraint: ${\mathbf{K}}\ge 1$.
2:     N – INTEGERInput
On entry: $n$, the number of observations in the time series.
Constraint: ${\mathbf{N}}\ge 4$.
3:     Z(KMAX,N) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{Z}}\left(\mathit{i},\mathit{t}\right)$ must contain the observation ${w}_{\mathit{i}\mathit{t}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n$.
4:     KMAX – INTEGERInput
On entry: the first dimension of the arrays Z, PARLAG, SE and QQ and the second dimension of the arrays PARLAG, SE and QQ as declared in the (sub)program from which G13DPF is called.
Constraint: ${\mathbf{KMAX}}\ge {\mathbf{K}}$.
5:     M – INTEGERInput
On entry: $m$, the number of partial autoregression matrices to be computed. If in doubt set ${\mathbf{M}}=10$.
Constraint: ${\mathbf{M}}\ge 1$ and ${\mathbf{N}}-{\mathbf{M}}-\left({\mathbf{K}}×{\mathbf{M}}+1\right)\ge {\mathbf{K}}$.
6:     MAXLAG – INTEGEROutput
On exit: the maximum lag up to which partial autoregression matrices (along with their likelihood ratio 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.
7:     PARLAG(KMAX,KMAX,M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{PARLAG}}\left(i,j,l\right)$ contains an estimate of the $\left(i,j\right)$th element of the partial autoregression matrix at lag $l$, ${\stackrel{^}{P}}_{l}\left(ij\right)$, for $l=1,2,\dots ,{\mathbf{MAXLAG}}$, $i=1,2,\dots ,k$ and $j=1,2,\dots ,k$.
8:     SE(KMAX,KMAX,M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{SE}}\left(i,j,l\right)$ contains an estimate of the standard error of the corresponding element in the array PARLAG.
9:     QQ(KMAX,KMAX,M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{QQ}}\left(\mathit{i},\mathit{j},\mathit{l}\right)$ contains an estimate of the $\left(\mathit{i},\mathit{j}\right)$th element of the corresponding variance-covariance matrix ${\stackrel{^}{\Sigma }}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{MAXLAG}}$, $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,k$.
10:   X(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{X}}\left(\mathit{l}\right)$ contains ${X}_{\mathit{l}}$, the likelihood ratio statistic at lag $\mathit{l}$, for $\mathit{l}=1,2,\dots ,{\mathbf{MAXLAG}}$.
11:   PVALUE(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{PVALUE}}\left(l\right)$ contains the significance level of the statistic in the corresponding element of X.
12:   LOGLHD(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{LOGLHD}}\left(\mathit{l}\right)$ contains an estimate of the maximum of the log-likelihood function when an $\text{AR}\left(\mathit{l}\right)$ model has been fitted to the series, for $\mathit{l}=1,2,\dots ,{\mathbf{MAXLAG}}$.
13:   WORK(LWORK) – REAL (KIND=nag_wp) arrayWorkspace
14:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which G13DPF is called.
Constraint: ${\mathbf{LWORK}}\ge \left(k+1\right)k+l\left(4+k\right)+2{l}^{2}$, where $l=mk+1$.
15:   IWORK(${\mathbf{K}}×{\mathbf{M}}$) – INTEGER arrayWorkspace
16:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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}}<1$, or ${\mathbf{N}}<4$, or ${\mathbf{KMAX}}<{\mathbf{K}}$, or ${\mathbf{M}}<1$, or ${\mathbf{N}}-{\mathbf{M}}-\left({\mathbf{K}}×{\mathbf{M}}+1\right)<{\mathbf{K}}$, or LWORK is too small.
${\mathbf{IFAIL}}=2$
The recursive equations used to compute the sample partial autoregression matrices have broken down at lag ${\mathbf{MAXLAG}}+1$. This exit could occur if the regression model is overparameterised. For your settings of $k$ and $n$ the value returned by MAXLAG is the largest permissible value of $m$ for which the model is not overparameterised. All output quantities in the arrays PARLAG, SE, QQ, X, PVALUE and LOGLHD up to and including lag MAXLAG will be correct.

## 7  Accuracy

The computations are believed to be stable.

The time taken is roughly proportional to $nmk$.
For each order of autoregressive model that has been estimated, G13DPF returns the maximum of the log-likelihood function. An alternative means of choosing the order of a vector AR process is to choose the order for which Akaike's information criterion is smallest. That is, choose the value of $l$ for which $-2×{\mathbf{LOGLHD}}\left(l\right)+2l{k}^{2}$ is smallest. You should be warned that this does not always lead to the same choice of $l$ as indicated by the sample partial autoregression matrices and the likelihood ratio statistics.

## 9  Example

This example computes the sample partial autoregression matrices of two time series of length $48$ up to lag $10$.

### 9.1  Program Text

Program Text (g13dpfe.f90)

### 9.2  Program Data

Program Data (g13dpfe.d)

### 9.3  Program Results

Program Results (g13dpfe.r)