G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13ACF

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

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

## 2  Specification

 SUBROUTINE G13ACF ( R, NK, NL, P, V, AR, NVL, IFAIL)
 INTEGER NK, NL, NVL, IFAIL REAL (KIND=nag_wp) R(NK), P(NL), V(NL), AR(NL)

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

## 5  Parameters

1:     R(NK) – REAL (KIND=nag_wp) arrayInput
On entry: the autocorrelation coefficient relating to lag $\mathit{k}$, for $\mathit{k}=1,2,\dots ,K$.
2:     NK – INTEGERInput
On entry: $K$, the number of lags. The lags range from $1$ to $K$ and do not include zero.
Constraint: ${\mathbf{NK}}>0$.
3:     NL – INTEGERInput
On entry: $L$, the number of partial autocorrelation coefficients required.
Constraint: $0<{\mathbf{NL}}\le {\mathbf{NK}}$.
4:     P(NL) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\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}}$.
5:     V(NL) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{V}}\left(\mathit{l}\right)$ contains the predictor error variance ratio ${v}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{NVL}}$.
6:     AR(NL) – REAL (KIND=nag_wp) arrayOutput
On exit: 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}}$.
7:     NVL – INTEGEROutput
On exit: the number of valid values in each of P, V and AR. Thus in the case of premature termination at iteration ${l}_{0}$ (see Section 3), NVL is returned as ${l}_{0}-1$.
8:     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{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.
${\mathbf{IFAIL}}=3$
Recursion has been prematurely terminated; the supplied autocorrelation coefficients do not form a positive definite sequence (see Section 3). Parameter NVL returns the number of valid values computed.

## 7  Accuracy

The computations are believed to be stable.

The time taken by G13ACF is proportional to ${\left({\mathbf{NVL}}\right)}^{2}$.

## 9  Example

This example uses an input series of $10$ sample autocorrelation coefficients derived from the original series of sunspot numbers generated by the G13ABF 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.

### 9.1  Program Text

Program Text (g13acfe.f90)

### 9.2  Program Data

Program Data (g13acfe.d)

### 9.3  Program Results

Program Results (g13acfe.r)