G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13AHF

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

G13AHF produces forecasts of a time series, given a time series model which has already been fitted to the time series using G13AEF or G13AFF. The original observations are not required, since G13AHF uses as input either the original state set produced by G13AEF or G13AFF or the state set updated by a series of new observations using G13AGF. Standard errors of the forecasts are also provided.

## 2  Specification

 SUBROUTINE G13AHF ( ST, NST, MR, PAR, NPAR, C, RMS, NFV, FVA, FSD, WA, NWA, IFAIL)
 INTEGER NST, MR(7), NPAR, NFV, NWA, IFAIL REAL (KIND=nag_wp) ST(NST), PAR(NPAR), C, RMS, FVA(NFV), FSD(NFV), WA(NWA)

## 3  Description

The original time series is ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$ and parameters have been fitted to the model of this time series using G13AEF or G13AFF.
Forecasts of ${x}_{\mathit{t}}$, for $\mathit{t}=n+1,\dots ,n+L$, are calculated in five stages, as follows:
 (i) set ${a}_{t}=0$ for $t=N+1,N+2,\dots ,N+L$, where $N=n-d-\left(D×s\right)$ is the number of differenced values in the series; (ii) calculate the values of ${e}_{\mathit{t}}$, for $\mathit{t}=N+1,\dots ,N+L$, and ${e}_{\mathit{t}}={\varphi }_{1}×{e}_{t-1}+\cdots +\phantom{\rule{0ex}{0ex}}{\varphi }_{p}×{e}_{t-p}+{a}_{t}-{\theta }_{1}×{a}_{t-1}-\cdots -{\theta }_{q}×{a}_{t-q}$; (iii) calculate the values of ${w}_{\mathit{t}}$, for $\mathit{t}=N+1,\dots ,N+L$, where ${w}_{t}={\Phi }_{1}×{w}_{t-s}+\cdots +\phantom{\rule{0ex}{0ex}}{\Phi }_{P}×{w}_{t-s×P}+{e}_{t}-{\Theta }_{1}×{e}_{t-s}-\cdots -{\Theta }_{Q}×{e}_{t-s×Q}$ and ${w}_{t}$ for $t\le N$ are the first $s×P$ values in the state set, corrected for the constant; (iv) add the constant term $c$ to give the differenced series ${\nabla }^{d}{\nabla }_{s}^{D}{x}_{\mathit{t}}={w}_{\mathit{t}}+c$, for $\mathit{t}=N+1,\dots ,N+L$; (v) the differencing operations are reversed to reconstitute ${x}_{\mathit{t}}$, for $\mathit{t}=n+1,\dots ,n+L$.
The standard errors of these forecasts are given by ${s}_{\mathit{t}}={\left[V×\left({\psi }_{0}^{2}+{\psi }_{1}^{2}+\dots +{\psi }_{\mathit{t}-n-1}^{2}\right)\right]}^{1/2}$, for $\mathit{t}=n+1,\dots ,n+L$, where ${\psi }_{0}=1$, $V$ is the residual variance of ${a}_{t}$, and ${\psi }_{j}$ is the coefficient expressing the dependence of ${x}_{t}$ on ${a}_{t-j}$.
To calculate ${\psi }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,\left(L-1\right)$, the following device is used.
A copy of the state set is initialized to zero throughout and the calculations outlined above for the construction of forecasts are carried out with the settings ${a}_{N+1}=1$, and ${a}_{\mathit{t}}=0$, for $\mathit{t}=N+2,\dots ,N+L$.
The resulting quantities corresponding to the sequence ${x}_{N+1},{x}_{N+2},\dots ,{x}_{N+L}$ are precisely $1$, ${\psi }_{1},{\psi }_{2},\dots ,{\psi }_{L-1}$.
The supplied time series model is used throughout these calculations, with the exception that the constant term $c$ is taken to be zero.

None.

## 5  Parameters

1:     ST(NST) – REAL (KIND=nag_wp) arrayInput
On entry: the state set derived from G13AEF or G13AFF originally, or as modified using earlier calls of G13AGF.
2:     NST – INTEGERInput
On entry: the number of values in the state set array ST.
Constraint: ${\mathbf{NST}}=P×s+D×s+d+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)$. (As returned by G13AEF or G13AFF).
3:     MR($7$) – INTEGER arrayInput
On entry: the orders vector $\left(p,d,q,P,D,Q,s\right)$ of the ARIMA model, in the usual notation.
Constraints:
• $p,d,q,P,D,Q,s\ge 0$;
• $p+q+P+Q>0$;
• $s\ne 1$;
• if $s=0$, $P+D+Q=0$;
• if $s>1$, $P+D+Q>0$.
4:     PAR(NPAR) – REAL (KIND=nag_wp) arrayInput
On entry: the estimates of the $p$ values of the $\varphi$ parameters, the $q$ values of the $\theta$ parameters, the $P$ values of the $\Phi$ parameters and the $Q$ values of the $\Theta$ parameters which specify the model and which were output originally by G13AEF or G13AFF.
5:     NPAR – INTEGERInput
On entry: the number of $\varphi$, $\theta$, $\Phi$ and $\Theta$ parameters in the model.
Constraint: ${\mathbf{NPAR}}=p+q+P+Q$.
6:     C – REAL (KIND=nag_wp)Input
On entry: $c$, the value of the model constant. This will have been output by G13AEF or G13AFF.
7:     RMS – REAL (KIND=nag_wp)Input
On entry: $V$, the residual variance associated with the model.
If G13AFF was used to estimate the model, RMS should be set to ${\mathbf{S}}/{\mathbf{NDF}}$, where S and NDF were output by G13AFF.
If G13AEF was used to estimate the model, RMS should be set to ${\mathbf{S}}/{\mathbf{ICOUNT}}\left(5\right)$, where S and ${\mathbf{ICOUNT}}\left(5\right)$ were output by G13AEF.
Constraint: ${\mathbf{RMS}}\ge 0.0$.
8:     NFV – INTEGERInput
On entry: $L$, the required number of forecasts.
Constraint: ${\mathbf{NFV}}>0$.
9:     FVA(NFV) – REAL (KIND=nag_wp) arrayOutput
On exit: NFV forecast values relating to the original undifferenced series.
10:   FSD(NFV) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard errors associated with each of the NFV forecast values in FVA.
11:   WA(NWA) – REAL (KIND=nag_wp) arrayWorkspace
12:   NWA – INTEGERInput
On entry: the dimension of the array WA as declared in the (sub)program from which G13AHF is called.
Constraint: ${\mathbf{NWA}}\ge \left(4×{\mathbf{NPAR}}+3×{\mathbf{NST}}\right)$.
13:   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{NPAR}}\ne p+q+P+Q$, or the orders vector MR is invalid (check the constraints given in Section 5).
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{NST}}\ne P×s+D×s+d+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(Q×s,p\right)$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{NFV}}\le 0$.
${\mathbf{IFAIL}}=4$
 On entry, ${\mathbf{NWA}}<4×{\mathbf{NPAR}}+3×{\mathbf{NST}}$.
${\mathbf{IFAIL}}=5$
 On entry, ${\mathbf{RMS}}<0.0$.

## 7  Accuracy

The computations are believed to be stable.

The time taken by G13AHF is approximately proportional to ${\mathbf{NFV}}×{\mathbf{NPAR}}$.

## 9  Example

The following program is based on the data derived in the example used to illustrate G13AGF.
These consist of a set of orders indicating that there are two moving average parameters (one non-seasonal, and one seasonal with periodicity $12$).
The model constant is zero.
The state set contains $26$ values.
In addition the residual mean-square derived when the model was originally fitted is given.
Twelve forecasts and their associated errors are obtained.

### 9.1  Program Text

Program Text (g13ahfe.f90)

### 9.2  Program Data

Program Data (g13ahfe.d)

### 9.3  Program Results

Program Results (g13ahfe.r)