# NAG FL Interfaceg13ahf (uni_​arima_​forecast_​state)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g13ahf ( st, nst, mr, par, npar, c, rms, nfv, fva, fsd, wa, nwa,
 Integer, Intent (In) :: nst, mr(7), npar, nfv, nwa Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: st(nst), par(npar), c, rms Real (Kind=nag_wp), Intent (Out) :: fva(nfv), fsd(nfv), wa(nwa)
#include <nag.h>
 void g13ahf_ (const double st[], const Integer *nst, const Integer mr[], const double par[], const Integer *npar, const double *c, const double *rms, const Integer *nfv, double fva[], double fsd[], double wa[], const Integer *nwa, Integer *ifail)
The routine may be called by the names g13ahf or nagf_tsa_uni_arima_forecast_state.

## 3Description

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:
1. (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;
2. (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}$;
3. (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;
4. (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$;
5. (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}+\cdots +{\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.

## 5Arguments

1: $\mathbf{st}\left({\mathbf{nst}}\right)$Real (Kind=nag_wp) array Input
On entry: the state set derived from g13aef or g13aff originally, or as modified using earlier calls of g13agf.
2: $\mathbf{nst}$Integer Input
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: $\mathbf{mr}\left(7\right)$Integer array Input
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: $\mathbf{par}\left({\mathbf{npar}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{npar}$Integer Input
On entry: the number of $\varphi$, $\theta$, $\Phi$ and $\Theta$ parameters in the model.
Constraint: ${\mathbf{npar}}=p+q+P+Q$.
6: $\mathbf{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: $\mathbf{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: $\mathbf{nfv}$Integer Input
On entry: $L$, the required number of forecasts.
Constraint: ${\mathbf{nfv}}>0$.
9: $\mathbf{fva}\left({\mathbf{nfv}}\right)$Real (Kind=nag_wp) array Output
On exit: nfv forecast values relating to the original undifferenced series.
10: $\mathbf{fsd}\left({\mathbf{nfv}}\right)$Real (Kind=nag_wp) array Output
On exit: the standard errors associated with each of the nfv forecast values in fva.
11: $\mathbf{wa}\left({\mathbf{nwa}}\right)$Real (Kind=nag_wp) array Workspace
12: $\mathbf{nwa}$Integer Input
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: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{npar}}=p+q+P+Q$.
The orders vector mr is invalid.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{nst}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nst}}=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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nfv}}>0$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{nwa}}=⟨\mathit{\text{value}}⟩$ and the minimum size $\text{required}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nwa}}\ge 4×{\mathbf{npar}}+3×{\mathbf{nst}}$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{rms}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{rms}}\ge 0.0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

g13ahf is not threaded in any implementation.

The time taken by g13ahf is approximately proportional to ${\mathbf{nfv}}×{\mathbf{npar}}$.

## 10Example

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.

### 10.1Program Text

Program Text (g13ahfe.f90)

### 10.2Program Data

Program Data (g13ahfe.d)

### 10.3Program Results

Program Results (g13ahfe.r)