# NAG FL Interfaceg13dpf (multi_​regmat_​partial)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g13dpf ( k, n, z, kmax, m, se, qq, x, work,
 Integer, Intent (In) :: k, n, kmax, m, lwork Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: maxlag, iwork(k*m) Real (Kind=nag_wp), Intent (In) :: z(kmax,n) Real (Kind=nag_wp), Intent (Inout) :: parlag(kmax,kmax,m), se(kmax,kmax,m), qq(kmax,kmax,m) Real (Kind=nag_wp), Intent (Out) :: x(m), pvalue(m), loglhd(m), work(lwork)
#include <nag.h>
 void g13dpf_ (const Integer *k, const Integer *n, const double z[], const Integer *kmax, const Integer *m, Integer *maxlag, double parlag[], double se[], double qq[], double x[], double pvalue[], double loglhd[], double work[], const Integer *lwork, Integer iwork[], Integer *ifail)
The routine may be called by the names g13dpf or nagf_tsa_multi_regmat_partial.

## 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 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.

## 4References

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

## 5Arguments

1: $\mathbf{k}$Integer Input
On entry: $k$, the number of time series.
Constraint: ${\mathbf{k}}\ge 1$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations in the time series.
Constraint: ${\mathbf{n}}\ge 4$.
3: $\mathbf{z}\left({\mathbf{kmax}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{kmax}$Integer Input
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: $\mathbf{m}$Integer Input
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: $\mathbf{maxlag}$Integer Output
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: $\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 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: $\mathbf{se}\left({\mathbf{kmax}},{\mathbf{kmax}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{qq}\left({\mathbf{kmax}},{\mathbf{kmax}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{x}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{pvalue}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{pvalue}}\left(l\right)$ contains the significance level of the statistic in the corresponding element of x.
12: $\mathbf{loglhd}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{work}\left({\mathbf{lwork}}\right)$Real (Kind=nag_wp) array Workspace
14: $\mathbf{lwork}$Integer Input
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: $\mathbf{iwork}\left({\mathbf{k}}×{\mathbf{m}}\right)$Integer array Workspace
16: $\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}}⟩$, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}-{\mathbf{m}}-\left({\mathbf{k}}×{\mathbf{m}}+1\right)\ge {\mathbf{k}}$.
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(k+1\right)k+l\left(4+k\right)+2{\left(mk+1\right)}^{2}$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 4$.
${\mathbf{ifail}}=2$
The recursive equations used to compute the partial autoregression matrices are ill-conditioned. They have been computed up to lag $⟨\mathit{\text{value}}⟩$. All output quantities in the arrays parlag, se, qq, x, pvalue and loglhd up to and including lag maxlag will be correct. For your settings of $k$ and $n$ the value returned in maxlag is the largest permissible value of $m$ for which the model is not overparameterised.
${\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 computations are believed to be stable.

## 8Parallelism and Performance

g13dpf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13dpf 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 $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.

## 10Example

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

### 10.1Program Text

Program Text (g13dpfe.f90)

### 10.2Program Data

Program Data (g13dpfe.d)

### 10.3Program Results

Program Results (g13dpfe.r)