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_uni_autocorr_part (g13ac)

## Purpose

nag_tsa_uni_autocorr_part (g13ac) calculates partial autocorrelation coefficients given a set of autocorrelation coefficients. It also calculates the predictor error variance ratios for increasing order of finite lag autoregressive predictor, and the autoregressive parameters associated with the predictor of maximum order.

## Syntax

[p, v, ar, nvl, ifail] = g13ac(r, nl, 'nk', nk)
[p, v, ar, nvl, ifail] = nag_tsa_uni_autocorr_part(r, nl, 'nk', nk)

## Description

The data consist of values of autocorrelation coefficients ${r}_{1},{r}_{2},\dots ,{r}_{K}$, relating to lags $1,2,\dots ,K$. These will generally (but not necessarily) be sample values such as may be obtained from a time series ${x}_{t}$ using nag_tsa_uni_autocorr (g13ab).
The partial autocorrelation coefficient at lag $l$ may be identified with the parameter ${p}_{l,l}$ in the autoregression
 $xt = cl + pl,1 xt-1 + pl,2 xt-2 +⋯+ pl,l xt-l + el,t$
where ${e}_{l,t}$ is the predictor error.
The first subscript $l$ of ${p}_{l,l}$ and ${e}_{l,t}$ emphasizes the fact that the parameters will in general alter as further terms are introduced into the equation (i.e., as $l$ is increased).
The parameters are determined from the autocorrelation coefficients by the Yule–Walker equations
 $ri = pl,1 ri-1 + pl,2 ri-2 +⋯+ pl,l ri-l , i=1,2,…,l$
taking ${r}_{j}={r}_{\left|j\right|}$ when $j<0$, and ${r}_{0}=1$.
The predictor error variance ratio ${v}_{l}=\mathrm{var}\left({e}_{l,t}\right)/\mathrm{var}\left({x}_{t}\right)$ is defined by
 $vl = 1- pl,1 r1 - pl,2 r2 -⋯- pl,l rl .$
The above sets of equations are solved by a recursive method (the Durbin–Levinson algorithm). The recursive cycle applied for $l=1,2,\dots ,\left(L-1\right)$, where $L$ is the number of partial autocorrelation coefficients required, is initialized by setting ${p}_{1,1}={r}_{1}$ and ${v}_{1}=1-{r}_{1}^{2}$.
Then
 $p l + 1 , l + 1 = r l + 1 - p l , 1 r l - p l , 2 r l - 1 - ⋯ - p l , l r 1 / v l p l + 1 , j = p l , j - p l + 1 , l + 1 p l , l + 1 - j , j=1,2,…,l v l + 1 = v l 1 - p l + 1 , l + 1 1 + p l + 1 , l + 1 .$
If the condition $\left|{p}_{l,l}\right|\ge 1$ occurs, say when $l={l}_{0}$, it indicates that the supplied autocorrelation coefficients do not form a positive definite sequence (see Hannan (1960)), and the recursion is not continued. The autoregressive parameters are overwritten at each recursive step, so that upon completion the only available values are ${p}_{Lj}$, for $\mathit{j}=1,2,\dots ,L$, or ${p}_{{l}_{0}-1,j}$ if the recursion has been prematurely halted.

## References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Durbin J (1960) The fitting of time series models Rev. Inst. Internat. Stat. 28 233
Hannan E J (1960) Time Series Analysis Methuen

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{r}\left({\mathbf{nk}}\right)$ – double array
The autocorrelation coefficient relating to lag $\mathit{k}$, for $\mathit{k}=1,2,\dots ,K$.
2:     $\mathrm{nl}$int64int32nag_int scalar
$L$, the number of partial autocorrelation coefficients required.
Constraint: $0<{\mathbf{nl}}\le {\mathbf{nk}}$.

### Optional Input Parameters

1:     $\mathrm{nk}$int64int32nag_int scalar
Default: the dimension of the array r.
$K$, the number of lags. The lags range from $1$ to $K$ and do not include zero.
Constraint: ${\mathbf{nk}}>0$.

### Output Parameters

1:     $\mathrm{p}\left({\mathbf{nl}}\right)$ – double array
${\mathbf{p}}\left(\mathit{l}\right)$ contains the partial autocorrelation coefficient at lag $\mathit{l}$, ${p}_{\mathit{l},\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
2:     $\mathrm{v}\left({\mathbf{nl}}\right)$ – double array
${\mathbf{v}}\left(\mathit{l}\right)$ contains the predictor error variance ratio ${v}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
3:     $\mathrm{ar}\left({\mathbf{nl}}\right)$ – double array
The autoregressive parameters of maximum order, i.e., ${p}_{L\mathit{j}}$ if ${\mathbf{ifail}}={\mathbf{0}}$, or ${p}_{{l}_{0}-1,\mathit{j}}$ if ${\mathbf{ifail}}={\mathbf{3}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nvl}}$.
4:     $\mathrm{nvl}$int64int32nag_int scalar
The number of valid values in each of p, v and ar. Thus in the case of premature termination at iteration ${l}_{0}$ (see Description), nvl is returned as ${l}_{0}-1$.
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{nk}}\le 0$, or ${\mathbf{nl}}\le 0$, or ${\mathbf{nk}}<{\mathbf{nl}}$.
${\mathbf{ifail}}=2$
On entry, the autocorrelation coefficient of lag $1$ has an absolute value greater than or equal to $1.0$; no recursions could be performed.
W  ${\mathbf{ifail}}=3$
Recursion has been prematurely terminated; the supplied autocorrelation coefficients do not form a positive definite sequence (see Description). Argument nvl returns the number of valid values computed.
${\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 by nag_tsa_uni_autocorr_part (g13ac) is proportional to ${\left({\mathbf{nvl}}\right)}^{2}$.

## Example

This example uses an input series of $10$ sample autocorrelation coefficients derived from the original series of sunspot numbers generated by the nag_tsa_uni_autocorr (g13ab) example program. The results show five values of each of the three output arrays: partial autocorrelation coefficients, predictor error variance ratios and autoregressive parameters. All of these were valid.
```function g13ac_example

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

% coefficients for all 49 lags
r = [ 0.8004    0.4355    0.0328   -0.2835   -0.4505 ...
-0.4242   -0.2419    0.0550    0.3783    0.5857 ...
0.6123    0.4389    0.1538   -0.1626   -0.3828 ...
-0.4637   -0.4133   -0.2630   -0.0711    0.1217 ...
0.2547    0.2681    0.1211   -0.0683   -0.2248 ...
-0.3187   -0.3365   -0.2748   -0.1696   -0.0500 ...
0.0605    0.1131    0.1132    0.0604   -0.0171 ...
-0.0909   -0.1269   -0.1345   -0.1056   -0.0581 ...
-0.0119    0.0272    0.0496    0.0592    0.0167 ...
-0.0138   -0.0328   -0.0383   -0.0287];

nl = int64(5);

% Calculate partial ACF
[p, v, ar, nvl, ifail] = g13ac( ...
r, nl, 'nk', int64(10));

% Display results
fprintf('Lag  Partial    Predictor error  Autoregressive\n');
fprintf('     autocorrn  variance ratio   parameter\n\n');
ivar = double([1:nvl])';
fprintf('%2d%9.3f%16.3f%14.3f\n',[ivar p v ar]');

% For plotting use all posible lags
nl = int64(numel(r));
[p, v, ar, nvl, ifail] = g13ac( ...
r, nl);

fig1 = figure;
refline = 1.96/sqrt(50);
hold on
h = bar(p,0.1);
h.FaceColor = [1 0 0];
h.EdgeColor = [1 0 0];
h.ShowBaseLine = 'off';
plot([0 50],[refline refline],'green');
plot([0 50],[-refline -refline],'green');
axis([0 50 -0.6 1]);
ax = gca;
ax.YTick = [-0.6:0.2:1];
ax.XTick = [0:10:50];
xlabel('Lag');
ylabel('PACF');
title('Partial autocorrelation coefficients');
hold off

```
```g13ac example results

Lag  Partial    Predictor error  Autoregressive
autocorrn  variance ratio   parameter

1    0.800           0.359         1.108
2   -0.571           0.242        -0.290
3   -0.239           0.228        -0.193
4   -0.049           0.228        -0.014
5   -0.032           0.228        -0.032
```
This plot shows the partial autocorrelations for all possible lag values. Reference lines are given at $±{z}_{0.975}/\sqrt{n}$.