NAG FL Interface
g13aef (uni_​arima_​estim)

1 Purpose

g13aef fits a seasonal autoregressive integrated moving average (ARIMA) model to an observed time series, using a nonlinear least squares procedure incorporating backforecasting. Parameter estimates are obtained, together with appropriate standard errors. The residual series is returned, and information for use in forecasting the time series is produced for use by the routines g13agf and g13ahf.
The estimation procedure is iterative, starting with initial parameter values such as may be obtained using g13adf. It continues until a specified convergence criterion is satisfied, or until a specified number of iterations has been carried out. The progress of the procedure can be monitored by means of a user-supplied routine.

2 Specification

Fortran Interface
Subroutine g13aef ( mr, par, npar, c, kfc, x, nx, icount, ex, exr, al, iex, s, g, igh, sd, h, ldh, st, ist, nst, piv, kpiv, nit, itc, zsp, kzsp, isf, wa, iwa, hc, ifail)
Integer, Intent (In) :: mr(7), npar, kfc, nx, iex, igh, ldh, ist, kpiv, nit, kzsp, iwa
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: icount(6), nst, itc, isf(4)
Real (Kind=nag_wp), Intent (In) :: x(nx)
Real (Kind=nag_wp), Intent (Inout) :: par(npar), c, h(ldh,igh), zsp(4), hc(ldh,igh)
Real (Kind=nag_wp), Intent (Out) :: ex(iex), exr(iex), al(iex), s, g(igh), sd(igh), st(ist), wa(iwa)
External :: piv
C Header Interface
#include <nag.h>
void  g13aef_ (const Integer mr[], double par[], const Integer *npar, double *c, const Integer *kfc, const double x[], const Integer *nx, Integer icount[], double ex[], double exr[], double al[], const Integer *iex, double *s, double g[], const Integer *igh, double sd[], double h[], const Integer *ldh, double st[], const Integer *ist, Integer *nst,
void (NAG_CALL *piv)(const Integer mr[], const double par[], const Integer *npar, const double *c, const Integer *kfc, const Integer icount[], const double *s, const double g[], const double h[], const Integer *ldh, const Integer *igh, const Integer *itc, const double zsp[]),
const Integer *kpiv, const Integer *nit, Integer *itc, double zsp[], const Integer *kzsp, Integer isf[], double wa[], const Integer *iwa, double hc[], Integer *ifail)
The routine may be called by the names g13aef or nagf_tsa_uni_arima_estim.

3 Description

The time series x1,x2,,xn supplied to g13aef is assumed to follow a seasonal autoregressive integrated moving average (ARIMA) model defined as follows:
dsDxt-c=wt,  
where dsDxt is the result of applying non-seasonal differencing of order d and seasonal differencing of seasonality s and order D to the series xt, as outlined in the description of g13aaf. The differenced series is then of length N=n-d, where d=d+D×s is the generalized order of differencing. The scalar c is the expected value of the differenced series, and the series w1,w2,,wN follows a zero-mean stationary autoregressive moving average (ARMA) model defined by a pair of recurrence equations. These express wt in terms of an uncorrelated series at, via an intermediate series et. The first equation describes the seasonal structure:
wt=Φ1wt-s+Φ2wt-2×s++ΦPwt-P×s+et-Θ1et-s-Θ2et-2×s--ΘQet-Q×s.  
The second equation describes the non-seasonal structure. If the model is purely non-seasonal the first equation is redundant and et above is equated with wt:
et=ϕ1et-1+ϕ2et-2++ϕpet-p+at-θ1at-1-θ2at-2--θqat-q.  
Estimates of the model parameters defined by
ϕ1,ϕ2,,ϕp,θ1,θ2,,θq, Φ1,Φ2,,ΦP,Θ1,Θ2,,ΘQ  
and (optionally) c are obtained by minimizing a quadratic form in the vector w=w1,w2,,wN.
This is QF=wV-1w, where V is the covariance matrix of w, and is a function of the model parameters. This matrix is not explicitly evaluated, since QF may be expressed as a ‘sum of squares’ function. When moving average parameters θi or Θi are present, so that the generalized moving average order q=q+s×Q is positive, backforecasts w1-q,w2-q,,w0 are introduced as nuisance parameters. The ‘sum of squares’ function may then be written as
Spm=t=1-qNat2-t=1-q-p -qbt2,  
where pm is a combined vector of parameters, consisting of the backforecasts followed by the ARMA model parameters.
The terms at correspond to the ARMA model residual series at, and p=p+s×P is the generalized autoregressive order. The terms bt are only present if autoregressive parameters are in the model, and serve to correct for transient errors introduced at the start of the autoregression.
The equations defining at and bt are precisely:
For all four of these equations, the following conditions hold:
Minimization of S with respect to pm uses an extension of the algorithm of Marquardt (1963).
The first derivatives of S with respect to the parameters are calculated as
2×at×at,i-2bt×bt,i=2×Gi,  
where at,i and bt,i are derivatives of at and bt with respect to the ith parameter.
The second derivative of S is approximated by
2×at,i×at,j-2×bt,i×bt,j=2×Hij.  
Successive parameter iterates are obtained by calculating a vector of corrections dpm by solving the equations
H+α×D×dpm=-G,  
where G is a vector with elements Gi, H is a matrix with elements Hij, α is a scalar used to control the search and D is the diagonal matrix of H.
The new parameter values are then pm+dpm.
The scalar α controls the step size, to which it is inversely related.
If a step results in new parameter values which give a reduced value of S, then α is reduced by a factor β. If a step results in new parameter values which give an increased value of S, or in ARMA model parameters which in any way contravene the stationarity and invertibility conditions, then the new parameters are rejected, α is increased by the factor β, and the revised equations are solved for a new parameter correction.
This action is repeated until either a reduced value of S is obtained, or α reaches the limit of 109, which is used to indicate a failure of the search procedure.
This failure may be due to a badly conditioned sum of squares function or to too strict a convergence criterion. Convergence is deemed to have occurred if the fractional reduction in the residual sum of squares in successive iterations is less than a value γ, while α<1.0.
The stationarity and invertibility conditions are tested to within a specified tolerance multiple δ of machine accuracy. Upon convergence, or completion of the specified maximum number of iterations without convergence, statistical properties of the estimates are derived. In the latter case the sequence of iterates should be checked to ensure that convergence is adequate for practical purposes, otherwise these properties are not reliable.
The estimated residual variance is
erv = Smin / df ,  
where Smin is the final value of S, and the residual number of degrees of freedom is given by
df = N-p-q-P-Q -1 ​ if ​ c ​ is estimated .  
The covariance matrix of the vector of estimates pm is given by
erv × H-1 ,  
where H is evaluated at the final parameter values.
From this expression are derived the vector of standard deviations, and the correlation matrix for the whole parameter set. These are asymptotic approximations.
The differenced series wt (now uncorrected for the constant), intermediate series et and residual series at are all available upon completion of the iterations over the range (extended by backforecasts)
t=1-q,2-q,,N.  
The values at can only properly be interpreted as residuals for t1+p-q, as the earlier values are corrupted by transients if p>0.
In consequence of the manner in which differencing is implemented, the residual at is the one step ahead forecast error for xt+d.
For convenient application in forecasting, the following quantities constitute the ‘state set’, which contains the minimum amount of time series information needed to construct forecasts:
  1. (i)the differenced series wt, for N-s×P<tN,
  2. (ii)the d values required to reconstitute the original series xt from the differenced series wt,
  3. (iii)the intermediate series et, for N - maxp, Q × s < t N ,
  4. (iv)the residual series at, for N-q<tN.
This state set is available upon completion of the iterations. The routine may be used purely for the construction of this state set, given a previously estimated model and time series xt, by requesting zero iterations. Backforecasts are estimated, but the model parameter values are unchanged. If later observations become available and it is desired to update the state set, g13agf can be used.

4 References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Marquardt D W (1963) An algorithm for least squares estimation of nonlinear parameters J. Soc. Indust. Appl. Math. 11 431

5 Arguments

1: mr7 Integer array Input
On entry: the orders vector p,d,q,P,D,Q,s of the ARIMA model whose parameters are to be estimated. p, q, P and Q refer respectively to the number of autoregressive (ϕ), moving average θ, seasonal autoregressive (Φ) and seasonal moving average (Θ) parameters. d, D and s refer respectively to the order of non-seasonal differencing, the order of seasonal differencing and the seasonal period.
Constraints:
  • 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;
  • d+s×P+Dn;
  • p+d-q+s×P+D-Qn.
2: parnpar Real (Kind=nag_wp) array Input/Output
On entry: the initial 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, in that order.
On exit: the latest values of the estimates of these parameters.
3: npar Integer Input
On entry: the total number of ϕ, θ, Φ and Θ parameters to be estimated.
Constraint: npar=p+q+P+Q.
4: c Real (Kind=nag_wp) Input/Output
On entry: if kfc=0, c must contain the expected value, c, of the differenced series.
If kfc=1, c must contain an initial estimate of c.
On exit: if kfc=0, c is unchanged.
If kfc=1, c contains the latest estimate of c.
Therefore, if c and kfc are both zero on entry, there is no constant correction.
5: kfc Integer Input
On entry: must be set to 1 if the constant, c, is to be estimated and 0 if it is to be held fixed at its initial value.
Constraint: kfc=0 or 1.
6: xnx Real (Kind=nag_wp) array Input
On entry: the n values of the original undifferenced time series.
7: nx Integer Input
On entry: n, the length of the original undifferenced time series.
8: icount6 Integer array Output
On exit: size of various output arrays.
icount1
Contains q+Q×s, the number of backforecasts.
icount2
Contains n-d-D×s, the number of differenced values.
icount3
Contains d+D×s, the number of values of reconstitution information.
icount4
Contains n+q+Q×s, the number of values held in each of the series ex, exr and al.
icount5
Contains n-d-D×s-p-q-P-Q-kfc, the number of degrees of freedom associated with S.
icount6
Contains icount1+npar+kfc, the number of parameters being estimated.
These values are always computed regardless of the exit value of ifail.
9: exiex Real (Kind=nag_wp) array Output
On exit: the extended differenced series which is made up of:
icount1 backforecast values of the differenced series.
icount2 actual values of the differenced series.
icount3 values of reconstitution information.
The total number of these values held in ex is icount4.
If the routine exits because of a faulty input parameter, the contents of ex will be indeterminate.
10: exriex Real (Kind=nag_wp) array Output
On exit: the values of the model residuals which is made up of:
icount1 residuals corresponding to the backforecasts in the differenced series.
icount2 residuals corresponding to the actual values in the differenced series.
The remaining icount3 values contain zeros.
If the routine exits with ifail holding a value other than 0 or 9, the contents of exr will be indeterminate.
11: aliex Real (Kind=nag_wp) array Output
On exit: the intermediate series which is made up of:
icount1 intermediate series values corresponding to the backforecasts in the differenced series.
icount2 intermediate series values corresponding to the actual values in the differenced series.
The remaining icount3 values contain zeros.
If the routine exits with ifail0, the contents of al will be indeterminate.
12: iex Integer Input
On entry: the dimension of the arrays ex, exr and al as declared in the (sub)program from which g13aef is called.
Constraint: iexq+Q×s+n, which is equivalent to the exit value of icount4.
13: s Real (Kind=nag_wp) Output
On exit: the residual sum of squares after the latest series of parameter estimates has been incorporated into the model. If the routine exits with a faulty input parameter, s contains zero.
14: gigh Real (Kind=nag_wp) array Output
On exit: the latest value of the derivatives of S with respect to each of the parameters being estimated (backforecasts, par parameters, and where relevant the constant – in that order). The contents of g will be indeterminate if the routine exits with a faulty input parameter.
15: igh Integer Input
On entry: the dimension of the arrays g and sd and the second dimension of the arrays h and hc as declared in the (sub)program from which g13aef is called.
Constraint: ighq+Q×s+npar+kfc which is equivalent to the exit value of icount6.
16: sdigh Real (Kind=nag_wp) array Output
On exit: the standard deviations corresponding to each of the parameters being estimated (backforecasts, par parameters, and where relevant the constant, in that order).
If the routine exits with ifail containing a value other than 0 or 9, or if the required number of iterations is zero, the contents of sd will be indeterminate.
17: hldhigh Real (Kind=nag_wp) array Output
On exit: the second derivative of S and correlation coefficients.
  1. (a)the latest values of an approximation to the second derivative of S with respect to each of the q+Q×s+npar+kfc parameters being estimated (backforecasts, par parameters, and where relevant the constant – in that order), and
  2. (b)the correlation coefficients relating to each pair of these parameters.
These are held in a matrix defined by the first q+Q×s+npar+kfc rows and the first q+Q×s+npar+kfc columns of h. (Note that icount6 contains the value of this expression.) The values of (a) are contained in the upper triangle, and the values of (b) in the strictly lower triangle.
These correlation coefficients are zero during intermediate printout using piv, and indeterminate if ifail contains on exit a value other than 0 or 9.
All the contents of h are indeterminate if the required number of iterations are zero. The q+Q×s+npar+kfc+1th row of h is used internally as workspace.
18: ldh Integer Input
On entry: the first dimension of the array h and
Constraint: ldh1+q+Q×s+npar+kfc, which is equivalent to the exit value of icount6.
19: stist Real (Kind=nag_wp) array Output
On exit: the nst values of the state set array. If the routine exits with ifail containing a value other than 0 or 9, the contents of st will be indeterminate.
20: ist Integer Input
On entry: the dimension of the array st as declared in the (sub)program from which g13aef is called.
Constraint: istP×s+d+D×s+q+maxp,Q×s.
21: nst Integer Output
On exit: the number of values in the state set array st.
22: piv Subroutine, supplied by the NAG Library or the user. External Procedure
piv is used to monitor the progress of the optimization.
The specification of piv is:
Fortran Interface
Subroutine piv ( mr, par, npar, c, kfc, icount, s, g, h, ldh, igh, itc, zsp)
Integer, Intent (In) :: mr(7), npar, kfc, icount(6), ldh, igh, itc
Real (Kind=nag_wp), Intent (In) :: par(npar), c, s, g(igh), h(ldh,igh), zsp(4)
C Header Interface
void  piv_ (const Integer mr[], const double par[], const Integer *npar, const double *c, const Integer *kfc, const Integer icount[], const double *s, const double g[], const double h[], const Integer *ldh, const Integer *igh, const Integer *itc, const double zsp[])
piv is called on each iteration by g13aef when the input value of kpiv is nonzero and is bypassed when it is 0.
The routine g13afz may be used as piv. It prints the heading
G13AFZ MONITORING OUTPUT - ITERATION n
followed by the parameter values and the residual sum of squares. Output is directed to the advisory channel defined by x04abf.
1: mr7 Integer array Input
2: parnpar Real (Kind=nag_wp) array Input
3: npar Integer Input
4: c Real (Kind=nag_wp) Input
5: kfc Integer Input
6: icount6 Integer array Input
7: s Real (Kind=nag_wp) Input
8: gigh Real (Kind=nag_wp) array Input
9: hldhigh Real (Kind=nag_wp) array Input
10: ldh Integer Input
11: igh Integer Input
12: itc Integer Input
13: zsp4 Real (Kind=nag_wp) array Input
On entry: all the arguments are defined as for g13aef itself.
piv must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which g13aef is called. Arguments denoted as Input must not be changed by this procedure.
If kpiv=0 a dummy piv must be supplied.
23: kpiv Integer Input
On entry: must be nonzero if the progress of the optimization is to be monitored using piv. Otherwise kpiv must contain 0.
24: nit Integer Input
On entry: the maximum number of iterations to be performed.
Constraint: nit0.
25: itc Integer Output
On exit: the number of iterations performed.
26: zsp4 Real (Kind=nag_wp) array Input/Output
On entry: when kzsp=1, the first four elements of zsp must contain the four values used to guide the search procedure. These are as follows.
zsp1 contains α, the value used to constrain the magnitude of the search procedure steps.
zsp2 contains β, the multiplier which regulates the value α.
zsp3 contains δ, the value of the stationarity and invertibility test tolerance factor.
zsp4 contains γ, the value of the convergence criterion.
If kzsp1 on entry, default values for zsp are supplied by the routine.
These are 0.001, 10.0, 1000.0 and max100×machine precision, 0.0000001 respectively.
On exit: zsp contains the values, default or otherwise, used by the routine.
Constraints:
if kzsp=1,
  • zsp1>0.0, ;
  • zsp2>1.0, ;
  • zsp31.0, ;
  • 0zsp4<1.0.
27: kzsp Integer Input
On entry: the value 1 if the routine is to use the input values of zsp, and any other value if the default values of zsp are to be used.
28: isf4 Integer array Output
On exit: contains success/failure indicators, one for each of the four types of parameter in the model (autoregressive, moving average, seasonal autoregressive, seasonal moving average), in that order.
Each indicator has the interpretation:
-2 On entry parameters of this type have initial estimates which do not satisfy the stationarity or invertibility test conditions.
-1 The search procedure has failed to converge because the latest set of parameter estimates of this type is invalid.
-0 No parameter of this type is in the model.
-1 Valid final estimates for parameters of this type have been obtained.
29: waiwa Real (Kind=nag_wp) array Workspace
30: iwa Integer Input
On entry: the dimension of the array wa as declared in the (sub)program from which g13aef is called.
Constraint: iwaF1×F2+9×npar,
where F1=nx+1+p+P×s+q+Q×s;
and F2=8 if kfc=1;
F2=7 if kfc=0, Q>0;
F2=6 if kfc=0, Q=0, P>0;
F2=5 if kfc=0, Q=0, P=0, q>0;
F2=4 otherwise.
31: hcldhigh Real (Kind=nag_wp) array Workspace
32: 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 -1 is recommended since useful values can be provided in some output arguments even when ifail0 on exit. 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).

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:
Note: in some cases g13aef may return useful information.
ifail=1
On entry, kfc=value.
Constraint: kfc=0 or 1.
On entry, npar=value.
Constraint: npar=p+q+P+Q.
The orders vector mr is invalid.
ifail=2
The model is over-parameterised. The number of parameters in the model is greater than the number of terms in the differenced series, i.e., npar+kfcnx-d-D×s.
ifail=3
On entry, nit=value.
Constraint: nit0.
On entry, zsp1=value.
Constraint: zsp1>0.0.
On entry, zsp2=value.
Constraint: zsp2>1.0.
On entry, zsp3=value.
Constraint: zsp31.0.
On entry, zsp4=value.
Constraint: 0.0zsp4<1.0.
ifail=4
On entry, ist=value and the minimum size required=value (the minimum size required is returned in nst).
Constraint: istP×s+d+D×s+q+maxp,Q×s.
ifail=5
On entry, iwa=value and the minimum size required=value.
Constraint: iwaF1×F2+9×npar.
ifail=6
On entry, iex=value.
Constraint: iexq×Q×s+nx.
On entry, igh=value.
Constraint: ighq×Q×s+npar+kfc.
On entry, ldh=value.
Constraint: ldhq×Q×s+npar+kfc.
ifail=7
A failure in the search procedure has occurred. Some output arguments may contain meaningful values.
ifail=8
Failure to invert H. Some output arguments may contain meaningful values.
ifail=9
Unable to calculate the latest estimates of the backforecasts.
Some output arguments may contain meaningful values.
ifail=10
Satisfactory parameter estimates could not be obtained for all parameter types in the model. Inspect array isf for futher information on the parameter type(s) in error.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The computations are believed to be stable.

8 Parallelism and Performance

g13aef is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13aef 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 implementation-specific information.

9 Further Comments

The time taken by g13aef is approximately proportional to nx×itc× q+Q×s+npar+kfc 2.

10 Example

The following program reads 30 observations from a time series relating to the rate of the earth's rotation about its polar axis. Differencing of order 1 is applied, and the number of non-seasonal parameters is 3, one autoregressive ϕ, and two moving average θ. No seasonal effects are taken into account.
The constant is estimated. Up to 25 iterations are allowed.
The initial estimates of ϕ1, θ1, θ2 and c are zero.

10.1 Program Text

Program Text (g13aefe.f90)

10.2 Program Data

Program Data (g13aefe.d)

10.3 Program Results

Program Results (g13aefe.r)