﻿ g13ac Method
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

C#
```public static void g13ac(
double[] r,
int nk,
int nl,
double[] p,
double[] v,
double[] ar,
out int nvl,
out int ifail
)```
Visual Basic
```Public Shared Sub g13ac ( _
r As Double(), _
nk As Integer, _
nl As Integer, _
p As Double(), _
v As Double(), _
ar As Double(), _
<OutAttribute> ByRef nvl As Integer, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g13ac(
array<double>^ r,
int nk,
int nl,
array<double>^ p,
array<double>^ v,
array<double>^ ar,
[OutAttribute] int% nvl,
[OutAttribute] int% ifail
)```
F#
```static member g13ac :
r : float[] *
nk : int *
nl : int *
p : float[] *
v : float[] *
ar : float[] *
nvl : int byref *
ifail : int byref -> unit
```

#### Parameters

r
Type: array<System..::..Double>[]()[][]
An array of size [nk]
On entry: the autocorrelation coefficient relating to lag $\mathit{k}$, for $\mathit{k}=1,2,\dots ,K$.
nk
Type: System..::..Int32
On entry: $K$, the number of lags. The lags range from $1$ to $K$ and do not include zero.
Constraint: ${\mathbf{nk}}>0$.
nl
Type: System..::..Int32
On entry: $L$, the number of partial autocorrelation coefficients required.
Constraint: $0<{\mathbf{nl}}\le {\mathbf{nk}}$.
p
Type: array<System..::..Double>[]()[][]
An array of size [nl]
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}}$.
v
Type: array<System..::..Double>[]()[][]
An array of size [nl]
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}}$.
ar
Type: array<System..::..Double>[]()[][]
An array of size [nl]
On exit: the autoregressive parameters of maximum order, i.e., ${p}_{L\mathit{j}}$ if ${\mathbf{ifail}}={0}$, or ${p}_{{l}_{0}-1,\mathit{j}}$ if ${\mathbf{ifail}}={3}$, for $\mathit{j}=1,2,\dots ,{\mathbf{nvl}}$.
nvl
Type: System..::..Int32%
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 [Description]), nvl is returned as ${l}_{0}-1$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# 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 g13ab.
The partial autocorrelation coefficient at lag $l$ may be identified with the parameter ${p}_{l,l}$ in the autoregression
 $xt=cl+pl,1xt-1+pl,2xt-2+⋯+pl,lxt-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,1ri-1+pl,2ri-2+⋯+pl,lri-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,1r1-pl,2r2-⋯-pl,lrl.$
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
 $pl+1,l+1=rl+1-pl,1rl-pl,2rl-1-⋯-pl,lr1/vlpl+1,j=pl,j-pl+1,l+1pl,l+1-j, j=1,2,…,lvl+1=vl1-pl+1,l+11+pl+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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\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 [Description]). Parameter nvl returns the number of valid values computed.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The computations are believed to be stable.

# Parallelism and Performance

None.

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