g13as is a diagnostic checking method suitable for use after fitting a Box–Jenkins ARMA model to a univariate time series using
(G13AEF not in this release)

**g13af**. The residual autocorrelation function is returned along with an estimate of its asymptotic standard errors and correlations. Also, g13as calculates the Box–Ljung portmanteau statistic and its significance level for testing model adequacy.# Syntax

C# |
---|

public static void g13as( int n, double[] v, int[] mr, int m, double[] par, int ishow, double[] r, double[,] rcm, out double chi, out int idf, out double siglev, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g13as ( _ n As Integer, _ v As Double(), _ mr As Integer(), _ m As Integer, _ par As Double(), _ ishow As Integer, _ r As Double(), _ rcm As Double(,), _ <OutAttribute> ByRef chi As Double, _ <OutAttribute> ByRef idf As Integer, _ <OutAttribute> ByRef siglev As Double, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g13as( int n, array<double>^ v, array<int>^ mr, int m, array<double>^ par, int ishow, array<double>^ r, array<double,2>^ rcm, [OutAttribute] double% chi, [OutAttribute] int% idf, [OutAttribute] double% siglev, [OutAttribute] int% ifail ) |

F# |
---|

static member g13as : n : int * v : float[] * mr : int[] * m : int * par : float[] * ishow : int * r : float[] * rcm : float[,] * chi : float byref * idf : int byref * siglev : float byref * ifail : int byref -> unit |

#### Parameters

- n
- Type: System..::..Int32
*On entry*: $n$, the number of observations in the residual series.*Constraint*: ${\mathbf{n}}\ge 3$.

- v
- Type: array<System..::..Double>[]()[][]An array of size [n]
*On entry*: ${\mathbf{v}}\left[\mathit{t}-1\right]$ must contain an estimate of ${\epsilon}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.*Constraint*: ${\mathbf{v}}$ must contain at least two distinct elements.

- mr
- Type: array<System..::..Int32>[]()[][]An array of size [$7$]
*On entry*: the orders vector ($p$, $d$, $q$, $P$, $D$, $Q$, $s$) as supplied to (G13AEF not in this release)**g13af**.*Constraints*:- $p,q,P,Q,s\ge 0$;
- $p+q+P+Q>0$;
- if $s=0$, then $P=0$ and $Q=0$.

- m
- Type: System..::..Int32
*On entry*: the value of $m$, the number of residual autocorrelations to be computed. See [Choice of $m$] for advice on the value of m.*Constraint*: $\mathbf{\_npar}<{\mathbf{m}}<{\mathbf{n}}$.

- par
- Type: array<System..::..Double>[]()[][]An array of size [dim1]
**Note:**dim1 must satisfy the constraint: $\mathbf{\_npar}={\mathbf{mr}}\left[0\right]+{\mathbf{mr}}\left[2\right]+{\mathbf{mr}}\left[3\right]+{\mathbf{mr}}\left[5\right]$*On entry*: the parameter estimates in the order ${\varphi}_{1},{\varphi}_{2},\dots ,{\varphi}_{p}$, ${\theta}_{1},{\theta}_{2},\dots ,{\theta}_{q}$, ${\Phi}_{1},{\Phi}_{2},\dots ,{\Phi}_{P}$, ${\Theta}_{1},{\Theta}_{2},\dots ,{\Theta}_{Q}$ only.*Constraint*: the elements in par must satisfy the stationarity and invertibility conditions.

- ishow
- Type: System..::..Int32

- r
- Type: array<System..::..Double>[]()[][]An array of size [m]
*On exit*: an estimate of the residual autocorrelation coefficient at lag $\mathit{l}$, for $\mathit{l}=1,2,\dots ,m$. If ${\mathbf{ifail}}={3}$ on exit then all elements of r are set to zero.

- rcm
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]
**Note:**dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$*On exit*: the estimated standard errors and correlations of the elements in the array r. The correlation between ${\mathbf{r}}\left[i-1\right]$ and ${\mathbf{r}}\left[j-1\right]$ is returned as ${\mathbf{rcm}}[i-1,j-1]$ except that if $i=j$ then ${\mathbf{rcm}}[i-1,j-1]$ contains the standard error of ${\mathbf{r}}\left[i-1\right]$. If on exit, ${\mathbf{ifail}}\ge {5}$, then all off-diagonal elements of rcm are set to zero and all diagonal elements are set to $1/\sqrt{n}$.

- chi
- Type: System..::..Double%
*On exit*: the value of the portmanteau statistic, ${Q}_{\left(m\right)}$. If ${\mathbf{ifail}}={3}$ on exit then chi is returned as zero.

- idf
- Type: System..::..Int32%
*On exit*: the number of degrees of freedom of chi.

- siglev
- Type: System..::..Double%

- 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

Consider the univariate multiplicative autoregressive-moving average model

where ${W}_{t}$, for $\mathit{t}=1,2,\dots ,n$, denotes a time series and ${\epsilon}_{t}$, for $\mathit{t}=1,2,\dots ,n$, is a residual series assumed to be normally distributed with zero mean and variance ${\sigma}^{2}$ ($\text{}>0$). The ${\epsilon}_{t}$'s are also assumed to be uncorrelated. Here $\mu $ is the overall mean term, $s$ is the seasonal period and $B$ is the backward shift operator such that ${B}^{r}{W}_{t}={W}_{t-r}$. The polynomials in (1) are defined as follows:

is the non-seasonal autoregressive (AR) operator;

is the non-seasonal moving average (MA) operator;

is the seasonal AR operator; and

is the seasonal MA operator. The model (1) is assumed to be stationary, that is the zeros of $\varphi \left(B\right)$ and $\Phi \left({B}^{s}\right)$ are assumed to lie outside the unit circle. The model (1) is also assumed to be invertible, that is the zeros of $\theta \left(B\right)$ and $\Theta \left({B}^{s}\right)$ are assumed to lie outside the unit circle. When both $\Phi \left({B}^{s}\right)$ and $\Theta \left({B}^{s}\right)$ are absent from the model, that is when $P=Q=0$, then the model is said to be non-seasonal.

$$\varphi \left(B\right)\Phi \left({B}^{s}\right)\left({W}_{t}-\mu \right)=\theta \left(B\right)\Theta \left({B}^{s}\right){\epsilon}_{t}$$ | (1) |

$$\varphi \left(B\right)=1-{\varphi}_{1}B-{\varphi}_{2}{B}^{2}-\cdots -{\varphi}_{p}{B}^{p}$$ |

$$\theta \left(B\right)=1-{\theta}_{1}B-{\theta}_{2}{B}^{2}-\cdots -{\theta}_{q}{B}^{q}$$ |

$$\Phi \left({B}^{s}\right)=1-{\Phi}_{1}{B}^{s}-{\Phi}_{2}{B}^{2s}-\cdots -{\Phi}_{P}{B}^{Ps}$$ |

$$\Theta \left({B}^{s}\right)=1-{\Theta}_{1}{B}^{s}-{\Theta}_{2}{B}^{2s}-\cdots -{\Theta}_{Q}{B}^{Qs}$$ |

The estimated residual autocorrelation coefficient at lag $l$, ${\hat{r}}_{l}$, is computed as:

where ${\hat{\epsilon}}_{t}$ denotes an estimate of the $t$th residual, ${\epsilon}_{t}$, and $\stackrel{-}{\epsilon}={\displaystyle \sum _{t=1}^{n}}{\hat{\epsilon}}_{t}/n$. A portmanteau statistic, ${Q}_{\left(m\right)}$, is calculated from the formula (see Box and Ljung (1978)):

$${\hat{r}}_{l}=\frac{\sum _{t=l+1}^{n}\left({\hat{\epsilon}}_{t-l}-\stackrel{-}{\epsilon}\right)\left({\hat{\epsilon}}_{t}-\stackrel{-}{\epsilon}\right)}{\sum _{t=1}^{n}{\left({\hat{\epsilon}}_{t}-\stackrel{-}{\epsilon}\right)}^{2}}\text{, \hspace{1em}}l=1,2,\dots $$ |

$${Q}_{\left(m\right)}=n\left(n+2\right)\sum _{l=1}^{m}{\hat{r}}_{l}^{2}/\left(n-l\right)$$ |

$$\mathrm{Var}\left(\hat{r}\right)=\left[{I}_{m}-X{\left({X}^{\mathrm{T}}X\right)}^{-1}{X}^{\mathrm{T}}\right]/n\text{.}$$ |

# References

Box G E P and Ljung G M (1978) On a measure of lack of fit in time series models

*Biometrika***65**297–303McLeod A I (1978) On the distribution of the residual autocorrelations in Box–Jenkins models

*J. Roy. Statist. Soc. Ser. B***40**296–302# Error Indicators and Warnings

**Note:**g13as may return useful information for one or more of the following detected errors or warnings.

Errors or warnings detected by the method:

Some error messages may refer to parameters that are dropped from this interface
(NPAR, LDRCM) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{mr}}\left[0\right]<0$, or ${\mathbf{mr}}\left[2\right]<0$, or ${\mathbf{mr}}\left[3\right]<0$, or ${\mathbf{mr}}\left[5\right]<0$, or ${\mathbf{mr}}\left[6\right]<0$, or ${\mathbf{mr}}\left[6\right]=0$ and either ${\mathbf{mr}}\left[3\right]>0$ or ${\mathbf{mr}}\left[5\right]>0$, or ${\mathbf{mr}}\left[0\right]={\mathbf{mr}}\left[2\right]={\mathbf{mr}}\left[3\right]={\mathbf{mr}}\left[5\right]=0$, or ${\mathbf{m}}\ge {\mathbf{n}}$, or ${\mathbf{n}}<3$, or liw is too small, or lwork is too small.

- ${\mathbf{ifail}}=2$
- On entry, the autoregressive (or moving average) parameters are extremely close to or outside the stationarity (or invertibility) region. To proceed, you must supply different parameter estimates in the array par.

- ${\mathbf{ifail}}=3$

- ${\mathbf{ifail}}=4$
- This is an unlikely exit brought about by an excessive number of iterations being needed to evaluate the zeros of the AR or MA polynomials. All output parameters are undefined.

- ${\mathbf{ifail}}=5$
- On entry, one or more of the AR operators has a factor in common with one or more of the MA operators. To proceed, this common factor must be deleted from the model. In this case, the off-diagonal elements of rcm are returned as zero and the diagonal elements set to $1/\sqrt{n}$. All other output quantities will be correct.

- ${\mathbf{ifail}}=6$

- ${\mathbf{ifail}}=-9000$
- An error occured, see message report.
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-4000$
- Invalid dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-8000$
- Negative dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$

# Accuracy

The computations are believed to be stable.

# Parallelism and Performance

None.

# Further Comments

# Timing

The time taken by g13as depends upon the number of residual autocorrelations to be computed, $m$.

# Choice of $m$

The number of residual autocorrelations to be computed, $m$ should be chosen to ensure that when the ARMA model (1) is written as either an infinite order autoregressive process:

or as an infinite order moving average process:

then the two sequences $\left\{{\pi}_{1},{\pi}_{2},\dots \right\}$ and $\left\{{\psi}_{1},{\psi}_{2},\dots \right\}$ are such that ${\pi}_{j}$ and ${\psi}_{j}$ are approximately zero for $j>m$. An overestimate of $m$ is therefore preferable to an under-estimate of $m$. In many instances the choice $m=10$ will suffice. In practice, to be on the safe side, you should try setting $m=20$.

$${W}_{t}-\mu =\sum _{j=1}^{\infty}{\pi}_{j}\left({W}_{t-j}-\mu \right)+{\epsilon}_{t}$$ |

$${W}_{t}-\mu =\sum _{j=1}^{\infty}{\psi}_{j}{\epsilon}_{t-j}+{\epsilon}_{t}$$ |

# Approximate Standard Errors

When ${\mathbf{ifail}}={5}$ or ${6}$ all the standard errors in rcm are set to $1/\sqrt{n}$. This is the asymptotic standard error of ${\hat{r}}_{l}$ when all the autoregressive and moving average parameters are assumed to be known rather than estimated.

# Alternative Applications

# Example

This example fits an ARIMA$\left(1,1,2\right)$ model to a series of $30$ observations. $10$ residual autocorrelations are computed.

Example program (C#): g13ase.cs