g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_arma_time_series (g05hac)

## 1  Purpose

nag_arma_time_series (g05hac) generates an autoregressive moving average (ARMA) time series with Normally distributed errors (or residuals). It initializes the series to a stationary position and sets up a reference vector enabling the function to be called repeatedly, adding terms to the previous series at each call.

## 2  Specification

 #include #include
 void nag_arma_time_series (Nag_Boolean start, Integer p, Integer q, const double phi[], const double theta[], double mean, double vara, Integer n, double w[], double ref[], NagError *fail)

## 3  Description

An ARMA model, denoted by ARMA$\left(p,q\right)$, is a mixture of an autoregressive process of order $p$ (AR) and a moving average (MA) process of order $q$ and can be written as
 $x n - μ = ϕ 1 x n-1 - μ + ⋯ + ϕ p x n-p - μ + a n - θ 1 a n-1 ⋯ - θ q a n-q$
where ${x}_{n}$ are the realization of the series, $\mu$ is the mean of the series and ${a}_{n}$ are the errors (or residuals, also often called the white noise) which are independently distributed as normal with mean zero and variance ${\sigma }^{2}$. The arguments ${\varphi }_{i}$ are the autoregressive arguments and the arguments ${\theta }_{i}$ are the moving average arguments.
The function sets up initial values corresponding to a stationary position using the method described by Tunnicliffe–Wilson (1979). It generates $n$ terms of the time series by first calculating the next term in the autoregressive series and then applying the moving-average summation and storing the result.

## 4  References

Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Tunnicliffe–Wilson G (1979) Some efficient computational procedures for high order ARMA models J. Statist. Comput. Simulation 8 301–309

## 5  Arguments

1:     startNag_BooleanInput
On entry: start must be Nag_TRUE if a new series is to begin, if start is Nag_FALSE a previously generated series will be continued. If start is Nag_FALSE then the scalar arguments p, q, mean and vara and the contents of the array arguments, phi and theta must not be changed.
2:     pIntegerInput
On entry: the number of autoregressive coefficients supplied.
Constraint: ${\mathbf{p}}\ge 0$.
3:     qIntegerInput
On entry: the number of moving-average coefficients supplied.
Constraint: ${\mathbf{q}}\ge 0$.
4:     phi[p]const doubleInput
On entry: the autoregressive coefficients of the model, if any, ${\mathbf{phi}}\left[i-1\right]$ must contain ${\varphi }_{i}$, for $i=1,2,\dots ,p$.
5:     theta[q]const doubleInput
On entry: the moving-average coefficients of the model, if any, ${\mathbf{theta}}\left[i-1\right]$ must contain ${\theta }_{i}$, for $i=1,2,\dots ,q$.
6:     meandoubleInput
On entry: the mean of the time series.
On entry: the variance of the errors, ${\sigma }^{2}$.
Constraint: ${\mathbf{vara}}>0.0$.
8:     nIntegerInput
On entry: the number of observations to be generated.
Constraint: ${\mathbf{n}}\ge 1$.
9:     w[n]doubleOutput
On exit: the realization of the time series.
10:   ref[$5×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{p}},{\mathbf{q}}\right)+7$]doubleOutput
On exit: the reference vector and the recent history of the series.
11:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge 0$.
On entry, ${\mathbf{q}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{q}}\ge 0$.
NE_REAL_ARG_LE
On entry, vara must not be less than or equal to 0.0: ${\mathbf{vara}}=〈\mathit{\text{value}}〉$.
NE_REF_VEC
The reference vector set up by the previous call of this function has become corrupt.
NE_START_P_Q
The function has been called either with ${\mathbf{start}}=\mathrm{Nag_FALSE}$ the first time or at least one of p or q has been changed in a subsequent call with ${\mathbf{start}}=\mathrm{Nag_FALSE}$.
NE_STATIONARITY
The input series does not constitute a stationary time-series model.

Not applicable.

None.

## 9  Example

The program below shows two calls of nag_arma_time_series (g05hac). In the first call an ARMA series is generated. In the second call terms are added to the already existing series.

### 9.1  Program Text

Program Text (g05hace.c)

None.

### 9.3  Program Results

Program Results (g05hace.r)