# NAG CL Interfaceg13acc (uni_​autocorr_​part)

## 1Purpose

g13acc 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 arguments associated with the predictor of maximum order.

## 2Specification

 #include
 void g13acc (const double r[], Integer nk, Integer nl, double p[], double v[], double ar[], Integer *nvl, NagError *fail)
The function may be called by the names: g13acc, nag_tsa_uni_autocorr_part or nag_tsa_auto_corr_part.

## 3Description

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 g13abc.
The partial autocorrelation coefficient at lag $l$ may be identified with the argument ${p}_{l,l}$ in the autoregression
 $x t = c l + p l,1 x t-1 + p l,2 x t-2 + ⋯ + p l,l x t-l + e l,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 arguments will in general alter as further terms are introduced into the equation (i.e., as $l$ is increased).
The arguments are determined from the autocorrelation coefficients by the Yule–Walker equations
 $r i = p l,1 r i-1 + p l,2 r i-2 + ⋯ + p l,l r i-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
 $v l = 1 - p l,1 r 1 - p l,2 r 2 - ⋯ - p l,l r l .$
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 arguments are overwritten at each recursive step, so that upon completion the only available values are ${p}_{L\mathit{j}}$, 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

## 5Arguments

1: $\mathbf{r}\left[{\mathbf{nk}}\right]$const double Input
On entry: ${\mathbf{r}}\left[\mathit{k}-1\right]$ contains the autocorrelation coefficient relating to lag $\mathit{k}$, for $\mathit{k}=1,2,\dots ,K$.
2: $\mathbf{nk}$Integer Input
On entry: the number of lags, $K$. The lags range from 1 to $K$ and do not include zero.
Constraint: ${\mathbf{nk}}>0$.
3: $\mathbf{nl}$Integer Input
On entry: the number of partial autocorrelation coefficients required, $L$.
Constraint: $0<{\mathbf{nl}}\le {\mathbf{nk}}$.
4: $\mathbf{p}\left[{\mathbf{nl}}\right]$double Output
On exit: ${\mathbf{p}}\left[\mathit{l}-1\right]$ contains the partial autocorrelation coefficient at lag $\mathit{l}$, ${p}_{\mathit{l},\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
5: $\mathbf{v}\left[{\mathbf{nl}}\right]$double Output
On exit: ${\mathbf{v}}\left[\mathit{l}-1\right]$ contains the predictor error variance ratio ${v}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nvl}}$.
6: $\mathbf{ar}\left[{\mathbf{nl}}\right]$double Output
On exit: the autoregressive arguments of maximum order, i.e., ${p}_{L\mathit{j}}$ if ${\mathbf{fail}}\mathbf{.}\mathbf{code}=\mathrm{NE_NOERROR}$, or ${p}_{{l}_{0}-1,\mathit{j}}$ if ${\mathbf{fail}}\mathbf{.}\mathbf{code}={\mathbf{NE_CORR_NOT_POS_DEF}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nvl}}$.
7: $\mathbf{nvl}$Integer * Output
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: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{nk}}=〈\mathit{\text{value}}〉$ while ${\mathbf{nl}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{nk}}\ge {\mathbf{nl}}$.
NE_CORR_NOT_POS_DEF
Recursion has been prematurely terminated; the supplied autocorrelation coefficients do not form a positive definite sequence. Parameter nvl returns the number of valid values computed.
NE_INT_ARG_LE
On entry, ${\mathbf{nk}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nk}}>0$.
On entry, ${\mathbf{nl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nl}}>0$.
NE_INVALID_AUTOCO_COEF
On entry, the autocorrelation coefficient of lag 1 has an absolute value greater than or equal to 1.0; no recursions could be performed.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

g13acc is not threaded in any implementation.

The time taken by g13acc is proportional to ${{\mathbf{nvl}}}^{2}$.

## 10Example

In the example below the input series is the set of 10 sample autocorrelation coefficients derived from the original series of sunspot numbers by g13abc example program. The results show 5 values of each of the three output arrays – partial autocorrelation coefficients, predictor error variance ratios and autoregressive arguments. All of these were valid.

### 10.1Program Text

Program Text (g13acce.c)

### 10.2Program Data

Program Data (g13acce.d)

### 10.3Program Results

Program Results (g13acce.r)