NAG Library Routine Document
G13AJF
1 Purpose
G13AJF applies a fully specified seasonal ARIMA model to an observed time series, generates the state set for forecasting and (optionally) derives a specified number of forecasts together with their standard deviations.
2 Specification
SUBROUTINE G13AJF ( 
MR, PAR, NPAR, C, KFC, X, NX, RMS, ST, IST, NST, NFV, FVA, FSD, IFV, ISF, W, IW, IFAIL) 
INTEGER 
MR(7), NPAR, KFC, NX, IST, NST, NFV, IFV, ISF(4), IW, IFAIL 
REAL (KIND=nag_wp) 
PAR(NPAR), C, X(NX), RMS, ST(IST), FVA(IFV), FSD(IFV), W(IW) 

3 Description
The time series ${x}_{1},{x}_{2},\dots ,{x}_{n}$ supplied to the routine is assumed to follow a seasonal autoregressive integrated moving average (ARIMA) model with known parameters.
The model is defined by the following relations.
(a) 
${\nabla}^{d}{\nabla}_{s}^{D}{x}_{t}c={w}_{t}$ where ${\nabla}^{d}{\nabla}_{s}^{D}{x}_{t}$ is the result of applying nonseasonal differencing of order $d$ and seasonal differencing of seasonality $s$ and order $D$ to the series ${x}_{t}$, and $c$ is a constant. 
(b) 
${w}_{t}={\Phi}_{1}{w}_{ts}+{\Phi}_{2}{w}_{t2\times s}+\cdots +{\Phi}_{P}{w}_{tP\times s}+{e}_{t}{\Theta}_{1}{e}_{ts}{\Theta}_{2}{e}_{t2\times s}\cdots {\Theta}_{Q}{e}_{tQ\times s}\text{.}$ This equation describes the seasonal structure with seasonal period $s$; in the absence of seasonality it reduces to ${w}_{t}={e}_{t}$. 
(c) 
${e}_{t}={\varphi}_{1}{e}_{t1}+{\varphi}_{2}{e}_{t2}+\cdots +{\varphi}_{p}{e}_{tp}+{a}_{t}{\theta}_{1}{a}_{t1}{\theta}_{2}{a}_{t2}\cdots {\theta}_{q}{a}_{tq}\text{.}$ This equation describes the nonseasonal structure. 
Given the series, the constant
$c$, and the model parameters
$\Phi $,
$\Theta $,
$\varphi $,
$\theta $, the routine computes the following.
(a) 
The state set required for forecasting. This contains the minimum amount of information required for forecasting and comprises:
(i) 
the differenced series ${w}_{t}$, for $\left(Ns\times P\right)\le t\le N$; 
(ii) 
the $\left(d+D\times s\right)$ values required to reconstitute the original series ${x}_{t}$ from the differenced series ${w}_{t}$; 
(iii) 
the intermediate series ${e}_{t}$, for $N\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q\times s\right)<t\le N$; 
(iv) 
the residual series ${a}_{t}$, for $\left(Nq\right)<t\le N$, where $N=n\left(d+D\times s\right)$. 

(b) 
A set of $L$ forecasts of ${x}_{t}$ and their estimated standard errors, ${s}_{t}$, for $\mathit{t}=n+1,\dots ,n+L$ ($L$ may be zero).
The forecasts and estimated standard errors are generated from the state set, and are identical to those that would be produced from the same state set by G13AHF. 
Use of G13AJF should be confined to situations in which the state set for forecasting is unknown. Forecasting from the series requires recalculation of the state set and this is relatively expensive.
4 References
Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
5 Parameters
 1: $\mathrm{MR}\left(7\right)$ – 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$;
 $d+s\times \left(P+D\right)\le n$;
 $p+dq+s\times \left(P+DQ\right)\le n$.
 2: $\mathrm{PAR}\left({\mathbf{NPAR}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: 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, in that order.
 3: $\mathrm{NPAR}$ – INTEGERInput

On entry: the exact number of $\varphi $, $\theta $, $\Phi $ and $\Theta $ parameters.
Constraint:
${\mathbf{NPAR}}=p+q+P+Q$.
 4: $\mathrm{C}$ – REAL (KIND=nag_wp)Input

On entry:
$c$, the expected value of the differenced series (i.e.,
$c$ is the constant correction). Where there is no constant term,
C must be set to
$0.0$.
 5: $\mathrm{KFC}$ – INTEGERInput

On entry: must be set to
$0$ if
C was not estimated, and
$1$ if
C was estimated. This is irrespective of whether or not
${\mathbf{C}}=0.0$. The only effect is that the residual degrees of freedom are one greater when
${\mathbf{KFC}}=0$. Assuming the supplied time series to be the same as that to which the model was originally fitted, this ensures an unbiased estimate of the residual meansquare.
Constraint:
${\mathbf{KFC}}=0$ or $1$.
 6: $\mathrm{X}\left({\mathbf{NX}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the $n$ values of the original undifferenced time series.
 7: $\mathrm{NX}$ – INTEGERInput

On entry: $n$, the length of the original undifferenced time series.
 8: $\mathrm{RMS}$ – REAL (KIND=nag_wp)Output

On exit: the residual variance (mean square) associated with the model.
 9: $\mathrm{ST}\left({\mathbf{IST}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the
NST values of the state set.
 10: $\mathrm{IST}$ – INTEGERInput

On entry: the dimension of the array
ST as declared in the (sub)program from which G13AJF is called.
Constraint:
${\mathbf{IST}}\ge \left(P\times s\right)+d+\left(D\times s\right)+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q\times s\right)$. The expression on the righthand side of the inequality is returned in
NST.
 11: $\mathrm{NST}$ – INTEGEROutput

On exit: the number of values in the state set array
ST.
 12: $\mathrm{NFV}$ – INTEGERInput

On entry: the required number of forecasts. If ${\mathbf{NFV}}\le 0$, no forecasts will be computed.
 13: $\mathrm{FVA}\left({\mathbf{IFV}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: if
${\mathbf{NFV}}>0$,
FVA contains the
NFV forecast values relating to the original undifferenced time series.
 14: $\mathrm{FSD}\left({\mathbf{IFV}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: if
${\mathbf{NFV}}>0$,
FSD contains the estimated standard errors of the
NFV forecast values.
 15: $\mathrm{IFV}$ – INTEGERInput

On entry: the dimension of the arrays
FVA and
FSD as declared in the (sub)program from which G13AJF is called.
Constraint:
${\mathbf{IFV}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{NFV}}\right)$.
 16: $\mathrm{ISF}\left(4\right)$ – INTEGER arrayOutput

On exit: contains validity indicators, one for each of the four possible parameter types in the model (autoregressive, moving average, seasonal autoregressive, seasonal moving average), in that order.
Each indicator has the interpretation:
$1$ 
On entry the set of parameter values of this type does not satisfy the stationarity or invertibility test conditions. 
$\phantom{}0$ 
No parameter of this type is in the model. 
$\phantom{}1$ 
Valid parameter values of this type have been supplied. 
 17: $\mathrm{W}\left({\mathbf{IW}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace
 18: $\mathrm{IW}$ – INTEGERInput

On entry: the dimension of the array
W as declared in the (sub)program from which G13AJF is called.
Constraint:
${\mathbf{IW}}\ge 6\times n+5\times \left(p+q+P+Q\right)+{{Q}^{\prime}}^{2}+11\times {Q}^{\prime}+3\times {P}^{\prime}+7$,
where ${Q}^{\prime}=Q\times s+q$ and ${P}^{\prime}=P\times s+p$.
 19: $\mathrm{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 in Section 5), 
or  ${\mathbf{KFC}}\ne 0$ or $1$. 
 ${\mathbf{IFAIL}}=2$

On entry, ${\mathbf{NX}}dD\times s\le {\mathbf{NPAR}}+{\mathbf{KFC}}$, i.e., the number of terms in the differenced series is not greater than the number of parameters in the model. The model is overparameterised.
 ${\mathbf{IFAIL}}=3$

On entry, the workspace array
W is too small.
 ${\mathbf{IFAIL}}=4$

On entry, the state set array
ST is too small. It must be at least as large as the exit value of
NST.
 ${\mathbf{IFAIL}}=5$

This indicates a failure in
F04ASF which is used to solve the equations giving estimates of the backforecasts.
 ${\mathbf{IFAIL}}=6$

On entry, valid values were not supplied for all parameter types in the model. Inspect array
ISF for further information on the parameter type(s) in error.
 ${\mathbf{IFAIL}}=7$

On entry,  ${\mathbf{IFV}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{NFV}}\right)$. 
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The computations are believed to be stable.
8 Parallelism and Performance
G13AJF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G13AJF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
The time taken by G13AJF is approximately proportional to $n$ and the square of the number of backforecasts derived.
10 Example
The data is that used in the example program for
G13AFF. Five forecast values and their standard errors, together with the state set, are computed and printed.
10.1 Program Text
Program Text (g13ajfe.f90)
10.2 Program Data
Program Data (g13ajfe.d)
10.3 Program Results
Program Results (g13ajfe.r)