NAG Library Routine Document

g13ahf (uni_arima_forecast_state)


    1  Purpose
    7  Accuracy


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.


Fortran Interface
Subroutine g13ahf ( st, nst, mr, par, npar, c, rms, nfv, fva, fsd, wa, nwa, ifail)
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)
C Header Interface
#include nagmk26.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 original time series is xt, for t=1,2,,n and parameters have been fitted to the model of this time series using g13aef or g13aff.
Forecasts of xt, for t=n+1,,n+L, are calculated in five stages, as follows:
(i) set at=0 for t=N+1,N+2,,N+L, where N=n-d-D×s is the number of differenced values in the series;
(ii) calculate the values of et, for t=N+1,,N+L, and et=ϕ1×et-1++ ϕp×et-p+at-θ1×at-1--θq×at-q;
(iii) calculate the values of wt, for t=N+1,,N+L, where wt=Φ1×wt-s++ ΦP×wt-s×P+et-Θ1×et-s--ΘQ×et-s×Q and wt for tN 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 dsDxt=wt+c, for t=N+1,,N+L;
(v) the differencing operations are reversed to reconstitute xt, for t=n+1,,n+L.
The standard errors of these forecasts are given by st = V× ψ02 + ψ12 ++ ψt-n-12 1/2 , for t=n+1,,n+L, where ψ0=1, V is the residual variance of at, and ψj is the coefficient expressing the dependence of xt on at-j.
To calculate ψj, for j=1,2,,L-1, 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 aN+1=1, and at=0, for t=N+2,,N+L.
The resulting quantities corresponding to the sequence xN+1,xN+2,,xN+L are precisely 1, ψ1,ψ2,,ψ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.




1:     stnst – 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: nst=P×s+D×s+d+q+maxp,Q×s. (As returned by g13aef or g13aff).
3:     mr7 – Integer arrayInput
On entry: the orders vector p,d,q,P,D,Q,s of the ARIMA model, in the usual notation.
  • p,d,q,P,D,Q,s0;
  • p+q+P+Q>0;
  • s1;
  • if s=0, P+D+Q=0;
  • if s>1, P+D+Q>0.
4:     parnpar – Real (Kind=nag_wp) arrayInput
On entry: the estimates of the p values of the ϕ parameters, the q values of the θ parameters, the P values of the Φ parameters and the Q values of the Θ parameters which specify the model and which were output originally by g13aef or g13aff.
5:     npar – IntegerInput
On entry: the number of ϕ, θ, Φ and Θ parameters in the model.
Constraint: 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 s/ndf, where s and ndf were output by g13aff.
If g13aef was used to estimate the model, rms should be set to s/icount5, where s and icount5 were output by g13aef.
Constraint: rms0.0.
8:     nfv – IntegerInput
On entry: L, the required number of forecasts.
Constraint: nfv>0.
9:     fvanfv – Real (Kind=nag_wp) arrayOutput
On exit: nfv forecast values relating to the original undifferenced series.
10:   fsdnfv – Real (Kind=nag_wp) arrayOutput
On exit: the standard errors associated with each of the nfv forecast values in fva.
11:   wanwa – 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: nwa4×npar+3×nst.
13:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry 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:
On entry,nparp+q+P+Q,
orthe orders vector mr is invalid (check the constraints given in Section 5).
On entry,nstP×s+D×s+d+q+maxQ×s,p.
On entry,nfv0.
On entry,nwa<4×npar+3×nst.
On entry,rms<0.0.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


The computations are believed to be stable.

Parallelism and Performance

g13ahf is not threaded in any implementation.

Further Comments

The time taken by g13ahf is approximately proportional to nfv×npar.


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.

Program Text

Program Text (g13ahfe.f90)

Program Data

Program Data (g13ahfe.d)

Program Results

Program Results (g13ahfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017