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 r1,r2,,rK${r}_{1},{r}_{2},\dots ,{r}_{K}$, relating to lags 1,2,,K$1,2,\dots ,K$. These will generally (but not necessarily) be sample values such as may be obtained from a time series xt${x}_{t}$ using nag_tsa_uni_autocorr (g13ab).
The partial autocorrelation coefficient at lag l$l$ may be identified with the parameter pl,l${p}_{l,l}$ in the autoregression
 xt = cl + pl,1 xt − 1 + pl,2 xt − 2 + ⋯ + pl,l xt − l + el,t $xt = cl + pl,1 xt-1 + pl,2 xt-2 +⋯+ pl,l xt-l + el,t$
where el,t${e}_{l,t}$ is the predictor error.
The first subscript l$l$ of pl,l${p}_{l,l}$ and el,t${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$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 $ri = pl,1 ri-1 + pl,2 ri-2 +⋯+ pl,l ri-l , i=1,2,…,l$
taking rj = r|j|${r}_{j}={r}_{|j|}$ when j < 0$j<0$, and r0 = 1${r}_{0}=1$.
The predictor error variance ratio vl = var(el,t) / var(xt)${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 . $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,,(L1)$l=1,2,\dots ,\left(L-1\right)$, where L$L$ is the number of partial autocorrelation coefficients required, is initialized by setting p1,1 = r1${p}_{1,1}={r}_{1}$ and v1 = 1r12${v}_{1}=1-{r}_{1}^{2}$.
Then
 p l + 1 , l + 1 = (r l + 1 − p l , 1 rl − p l , 2 r l − 1 − ⋯ − p l , l r1) / vl p l + 1 , j = p l , j − p l + 1 , l + 1 p l , l + 1 − j ,   j = 1,2, … ,l v l + 1 = vl ( 1 − p l + 1 , l + 1 ) (1 + p l + 1 , l + 1 ) .
$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 |pl,l|1$|{p}_{l,l}|\ge 1$ occurs, say when l = l0$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 pLj${p}_{Lj}$, for j = 1,2,,L$\mathit{j}=1,2,\dots ,L$, or pl01,j${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:     r(nk) – double array
nk, the dimension of the array, must satisfy the constraint nk > 0${\mathbf{nk}}>0$.
The autocorrelation coefficient relating to lag k$\mathit{k}$, for k = 1,2,,K$\mathit{k}=1,2,\dots ,K$.
2:     nl – int64int32nag_int scalar
L$L$, the number of partial autocorrelation coefficients required.
Constraint: 0 < nlnk$0<{\mathbf{nl}}\le {\mathbf{nk}}$.

### Optional Input Parameters

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

None.

### Output Parameters

1:     p(nl) – double array
p(l)${\mathbf{p}}\left(\mathit{l}\right)$ contains the partial autocorrelation coefficient at lag l$\mathit{l}$, pl,l${p}_{\mathit{l},\mathit{l}}$, for l = 1,2,,nvl$\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
2:     v(nl) – double array
v(l)${\mathbf{v}}\left(\mathit{l}\right)$ contains the predictor error variance ratio vl${v}_{\mathit{l}}$, for l = 1,2,,nvl$\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
3:     ar(nl) – double array
The autoregressive parameters of maximum order, i.e., pLj${p}_{L\mathit{j}}$ if ${\mathbf{ifail}}={\mathbf{0}}$, or pl01,j${p}_{{l}_{0}-1,\mathit{j}}$ if ${\mathbf{ifail}}={\mathbf{3}}$, for j = 1,2,,nvl$\mathit{j}=1,2,\dots ,{\mathbf{nvl}}$.
4:     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 l0${l}_{0}$ (see Section [Description]), nvl is returned as l01${l}_{0}-1$.
5:     ifail – int64int32nag_int scalar
${\mathrm{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.

ifail = 1${\mathbf{ifail}}=1$
 On entry, nk ≤ 0${\mathbf{nk}}\le 0$, or nl ≤ 0${\mathbf{nl}}\le 0$, or nk < nl${\mathbf{nk}}<{\mathbf{nl}}$.
ifail = 2${\mathbf{ifail}}=2$
On entry, the autocorrelation coefficient of lag 1$1$ has an absolute value greater than or equal to 1.0$1.0$; no recursions could be performed.
W ifail = 3${\mathbf{ifail}}=3$
Recursion has been prematurely terminated; the supplied autocorrelation coefficients do not form a positive definite sequence (see Section [Description]). Parameter nvl returns the number of valid values computed.

## Accuracy

The computations are believed to be stable.

The time taken by nag_tsa_uni_autocorr_part (g13ac) is proportional to (nvl)2${\left({\mathbf{nvl}}\right)}^{2}$.

## Example

```function nag_tsa_uni_autocorr_part_example
r = [0.8004;
0.4355;
0.0328;
-0.2835;
-0.4505;
-0.4242;
-0.2419;
-0.055;
0.3783;
0.5857];
nl = int64(5);
[p, v, ar, nvl, ifail] = nag_tsa_uni_autocorr_part(r, nl)
```
```

p =

0.8004
-0.5708
-0.2388
-0.0494
-0.0321

v =

0.3594
0.2423
0.2284
0.2279
0.2276

ar =

1.1076
-0.2899
-0.1925
-0.0138
-0.0321

nvl =

5

ifail =

0

```
```function g13ac_example
r = [0.8004;
0.4355;
0.0328;
-0.2835;
-0.4505;
-0.4242;
-0.2419;
-0.055;
0.3783;
0.5857];
nl = int64(5);
[p, v, ar, nvl, ifail] = g13ac(r, nl)
```
```

p =

0.8004
-0.5708
-0.2388
-0.0494
-0.0321

v =

0.3594
0.2423
0.2284
0.2279
0.2276

ar =

1.1076
-0.2899
-0.1925
-0.0138
-0.0321

nvl =

5

ifail =

0

```