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_regmat_partial (g13dp)

## Purpose

nag_tsa_multi_regmat_partial (g13dp) 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.

## Syntax

[maxlag, parlag, se, qq, x, pvalue, loglhd, ifail] = g13dp(k, z, m, 'n', n)
[maxlag, parlag, se, qq, x, pvalue, loglhd, ifail] = nag_tsa_multi_regmat_partial(k, z, m, 'n', n)

## 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 functions nag_correg_linregm_obs_edit (g02dc) and nag_correg_linregm_var_del (g02df). They are calculated up to lag $m$, which is usually taken to be at most $n/4$.
The function 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 function also returns an estimate of the maximum of the log-likelihood function for each AR model that has been fitted.

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{k}$int64int32nag_int scalar
$k$, the number of time series.
Constraint: ${\mathbf{k}}\ge 1$.
2:     $\mathrm{z}\left(\mathit{kmax},{\mathbf{n}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
${\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$.
3:     $\mathrm{m}$int64int32nag_int scalar
$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}}$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the second dimension of the array z.
$n$, the number of observations in the time series.
Constraint: ${\mathbf{n}}\ge 4$.

### Output Parameters

1:     $\mathrm{maxlag}$int64int32nag_int scalar
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.
2:     $\mathrm{parlag}\left(\mathit{kmax},\mathit{kmax},{\mathbf{m}}\right)$ – double array
$\mathit{kmax}={\mathbf{k}}$.
${\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$.
3:     $\mathrm{se}\left(\mathit{kmax},\mathit{kmax},{\mathbf{m}}\right)$ – double array
$\mathit{kmax}={\mathbf{k}}$.
${\mathbf{se}}\left(i,j,l\right)$ contains an estimate of the standard error of the corresponding element in the array parlag.
4:     $\mathrm{qq}\left(\mathit{kmax},\mathit{kmax},{\mathbf{m}}\right)$ – double array
$\mathit{kmax}={\mathbf{k}}$.
${\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$.
5:     $\mathrm{x}\left({\mathbf{m}}\right)$ – double array
${\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}}$.
6:     $\mathrm{pvalue}\left({\mathbf{m}}\right)$ – double array
${\mathbf{pvalue}}\left(l\right)$ contains the significance level of the statistic in the corresponding element of x.
7:     $\mathrm{loglhd}\left({\mathbf{m}}\right)$ – double array
${\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}}$.
8:     $\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}}<4$, or $\mathit{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.
W  ${\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.
${\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 computations are believed to be stable.

The time taken is roughly proportional to $nmk$.
For each order of autoregressive model that has been estimated, nag_tsa_multi_regmat_partial (g13dp) 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.

## Example

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

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

z = [-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(z);
k = int64(k);
m = int64(10);

[maxlag, parlag, se, qq, x, pvalue, loglhd, ifail] = ...
g13dp(k, z, m);

fprintf('%31s%13s%10s%13s%8s\n','Partial Autoregression Matrices', ...
'Indicator', 'Residual', 'Chi-Square', 'Pvalue');
fprintf('%43s%12s%12s\n', 'Symbols', 'Variances', 'Statistic');
fprintf('%31s%13s%10s%13s%8s\n','-------------------------------', ...
'---------', '--------', '----------', '------')
for l = 1:maxlag
for j = 1:k
sum = parlag(1,j,l);
st(j) = '.';
if sum>1.96*se(1,j,l)
st(j) = '+';
end
if sum<-1.96*se(1,j,l)
st(j) = '-';
end
end
fprintf('\n Lag %2d :%8.3f%8.3f%15s%13.3f%13.3f%9.3f\n', ...
l, parlag(1,1:k,l), st(1:k), qq(1,1,l), x(l), pvalue(l));
fprintf('          (%6.3f)(%6.3f)\n', se(1,1:k,l));
for i = 2:k
for j = 1:k
sum = parlag(i,j,l);
st(j) = '.';
if sum>1.96*se(i,j,l)
st(j) = '+';
end
if sum<-1.96*se(i,j,l)
st(j) = '-';
end
end
fprintf('%17.3f%8.3f%15s%13.3f\n', parlag(i,1:k,l), st(1:k), qq(i,i,l));
fprintf('          (%6.3f)(%6.3f)\n', se(i,1:k,l));
end
end

```
```g13dp example results

Partial Autoregression Matrices    Indicator  Residual   Chi-Square  Pvalue
Symbols   Variances   Statistic
-------------------------------    ---------  --------   ----------  ------

Lag  1 :   0.757   0.062             +.        2.731       49.884    0.000
( 0.092)( 0.092)
0.061   0.570             .+        5.440
( 0.129)( 0.130)

Lag  2 :  -0.161  -0.135             ..        2.530        3.347    0.502
( 0.145)( 0.109)
-0.093  -0.065             ..        5.486
( 0.213)( 0.160)

Lag  3 :   0.237   0.044             ..        1.755       13.962    0.007
( 0.128)( 0.095)
0.047  -0.248             ..        5.291
( 0.222)( 0.165)

Lag  4 :  -0.098   0.152             ..        1.661        7.071    0.132
( 0.134)( 0.099)
0.402  -0.194             ..        4.786
( 0.228)( 0.168)

Lag  5 :   0.257  -0.026             ..        1.504        5.184    0.269
( 0.141)( 0.106)
0.400  -0.021             ..        4.447
( 0.242)( 0.183)

Lag  6 :  -0.075   0.112             ..        1.480        2.083    0.721
( 0.156)( 0.111)
0.196  -0.106             ..        4.425
( 0.269)( 0.192)

Lag  7 :  -0.054   0.097             ..        1.478        5.074    0.280
( 0.166)( 0.121)
0.574  -0.080             +.        3.838
( 0.267)( 0.195)

Lag  8 :   0.147   0.041             ..        1.415       10.991    0.027
( 0.188)( 0.128)
0.916  -0.242             +.        2.415
( 0.246)( 0.167)

Lag  9 :  -0.039   0.099             ..        1.322        3.936    0.415
( 0.251)( 0.140)
-0.500   0.173             ..        2.196
( 0.324)( 0.181)

Lag 10 :   0.189   0.131             ..        1.206        3.175    0.529
( 0.275)( 0.157)
-0.183  -0.040             ..        2.201
( 0.371)( 0.212)
```