# NAG FL Interfaceg13aef (uni_​arima_​estim)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g13aef ( mr, par, npar, c, kfc, x, nx, ex, exr, al, iex, s, g, igh, sd, h, ldh, st, ist, nst, piv, kpiv, nit, itc, zsp, kzsp, isf, wa, iwa, hc,
 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
#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.

## 3Description

The time series ${x}_{1},{x}_{2},\dots ,{x}_{n}$ supplied to g13aef is assumed to follow a seasonal autoregressive integrated moving average (ARIMA) model defined as follows:
 $∇d∇sDxt-c=wt,$
where ${\nabla }^{d}{\nabla }_{s}^{D}{x}_{t}$ is the result of applying non-seasonal differencing of order $d$ and seasonal differencing of seasonality $s$ and order $D$ to the series ${x}_{t}$, as outlined in the description of g13aaf. The differenced series is then of length $N=n-{d}^{\prime }$, where ${d}^{\prime }=d+\left(D×s\right)$ is the generalized order of differencing. The scalar $c$ is the expected value of the differenced series, and the series ${w}_{1},{w}_{2},\dots ,{w}_{N}$ follows a zero-mean stationary autoregressive moving average (ARMA) model defined by a pair of recurrence equations. These express ${w}_{t}$ in terms of an uncorrelated series ${a}_{t}$, via an intermediate series ${e}_{t}$. 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 ${e}_{t}$ above is equated with ${w}_{t}$:
 $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={\left({w}_{1},{w}_{2},\dots ,{w}_{N}\right)}^{\prime }$.
This is $QF={w}^{\prime }{V}^{-1}w$, 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 ${\theta }_{i}$ or ${\Theta }_{i}$ are present, so that the generalized moving average order ${q}^{\prime }=q+s×Q$ is positive, backforecasts ${w}_{1-{q}^{\prime }},{w}_{2-{q}^{\prime }},\dots ,{w}_{0}$ are introduced as nuisance parameters. The ‘sum of squares’ function may then be written as
 $S(pm)=∑t=1-q′Nat2-∑t=1-q′-p′ -q′bt2,$
where $pm$ is a combined vector of parameters, consisting of the backforecasts followed by the ARMA model parameters.
The terms ${a}_{t}$ correspond to the ARMA model residual series ${a}_{t}$, and ${p}^{\prime }=p+s×P$ is the generalized autoregressive order. The terms ${b}_{t}$ 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 ${a}_{t}$ and ${b}_{t}$ are precisely:
• ${e}_{t}={w}_{t}-{\Phi }_{1}{w}_{t-s}-{\Phi }_{2}{w}_{t-2×s}-\cdots -{\Phi }_{P}{w}_{t-P×s}+{\Theta }_{1}{e}_{t-s}+{\Theta }_{2}{e}_{t-2×s}+\cdots +{\Theta }_{Q}{e}_{t-Q×s}$,
for $t=1-{q}^{\prime },2-{q}^{\prime },\dots ,n$.
• ${a}_{t}={e}_{t}-{\varphi }_{1}{e}_{t-1}-{\varphi }_{2}{e}_{t-2}-\cdots -{\varphi }_{p}{e}_{t-p}+{\theta }_{1}{a}_{t-1}+{\theta }_{2}{a}_{t-2}+\cdots +{\theta }_{q}{a}_{t-q}$,
for $t=1-{q}^{\prime },2-{q}^{\prime },\dots ,n$.
• ${f}_{t}={w}_{t}-{\Phi }_{1}{w}_{t+s}-{\Phi }_{2}{w}_{t+2×s}-\cdots -{\Phi }_{P}{w}_{t+P×s}+{\Theta }_{1}{f}_{t-s}+{\Theta }_{2}{f}_{t-2×s}+\cdots +{\Theta }_{Q}{f}_{t-Q×s}$,
for $t=\left(1-{q}^{\prime }-s×P\right),\left(2-{q}^{\prime }-s×P\right),\dots ,\left(-{q}^{\prime }+P\right)$
• ${b}_{t}={f}_{t}-{\varphi }_{1}{f}_{t+1}-{\varphi }_{2}{f}_{t+2}-\cdots -{\varphi }_{p}{f}_{t+p}+{\theta }_{1}{b}_{t-1}+{\theta }_{2}{b}_{t-2}+\cdots +{\theta }_{q}{b}_{t-q}$,
for $t=\left(1-{q}^{\prime }-{p}^{\prime }\right),\left(2-{q}^{\prime }-{p}^{\prime }\right),\dots ,\left(-{q}^{\prime }\right)$.
For all four of these equations, the following conditions hold:
• ${w}_{i}=0$ if $i<1-{q}^{\prime }$
• ${e}_{i}=0$ if $i<1-{q}^{\prime }$
• ${a}_{i}=0$ if $i<1-{q}^{\prime }$
• ${f}_{i}=0$ if $i<1-{q}^{\prime }-s×P$
• ${b}_{i}=0$ if $i<1-{q}^{\prime }-{p}^{\prime }$
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-2∑bt×bt,i=2×Gi,$
where ${a}_{t,i}$ and ${b}_{t,i}$ are derivatives of ${a}_{t}$ and ${b}_{t}$ with respect to the $i$th 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 $\mathit{dpm}$ by solving the equations
 $(H+α×D)×dpm=-G,$
where $G$ is a vector with elements ${G}_{i}$, $H$ is a matrix with elements ${H}_{ij}$, $\alpha$ is a scalar used to control the search and $D$ is the diagonal matrix of $H$.
The new parameter values are then $pm+\mathit{dpm}$.
The scalar $\alpha$ 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 $\alpha$ is reduced by a factor $\beta$. 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, $\alpha$ is increased by the factor $\beta$, 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 $\alpha$ reaches the limit of ${10}^{9}$, 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 $\gamma$, while $\alpha <1.0$.
The stationarity and invertibility conditions are tested to within a specified tolerance multiple $\delta$ 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 ${S}_{\mathrm{min}}$ 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 ${w}_{t}$ (now uncorrected for the constant), intermediate series ${e}_{t}$ and residual series ${a}_{t}$ are all available upon completion of the iterations over the range (extended by backforecasts)
 $t=1-q′,2-q′,…,N.$
The values ${a}_{t}$ can only properly be interpreted as residuals for $t\ge 1+{p}^{\prime }-{q}^{\prime }$, as the earlier values are corrupted by transients if ${p}^{\prime }>0$.
In consequence of the manner in which differencing is implemented, the residual ${a}_{t}$ is the one step ahead forecast error for ${x}_{t+{d}^{\prime }}$.
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 ${w}_{t}$, for $\left(N-s×P\right),
2. (ii)the ${d}^{\prime }$ values required to reconstitute the original series ${x}_{t}$ from the differenced series ${w}_{t}$,
3. (iii)the intermediate series ${e}_{t}$, for $\left(N-\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)\right),
4. (iv)the residual series ${a}_{t}$, for $\left(N-q\right).
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 ${x}_{t}$, 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.

## 4References

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

## 5Arguments

1: $\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 whose parameters are to be estimated. $p$, $q$, $P$ and $Q$ refer respectively to the number of autoregressive ($\varphi$), moving average $\left(\theta \right)$, seasonal autoregressive ($\Phi$) and seasonal moving average ($\Theta$) 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$, $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×\left(P+D\right)\le n$;
• $p+d-q+s×\left(P+D-Q\right)\le n$.
2: $\mathbf{par}\left({\mathbf{npar}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: the initial 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, in that order.
On exit: the latest values of the estimates of these parameters.
3: $\mathbf{npar}$Integer Input
On entry: the total number of $\varphi$, $\theta$, $\Phi$ and $\Theta$ parameters to be estimated.
Constraint: ${\mathbf{npar}}=p+q+P+Q$.
4: $\mathbf{c}$Real (Kind=nag_wp) Input/Output
On entry: if ${\mathbf{kfc}}=0$, c must contain the expected value, $c$, of the differenced series.
If ${\mathbf{kfc}}=1$, c must contain an initial estimate of $c$.
On exit: if ${\mathbf{kfc}}=0$, c is unchanged.
If ${\mathbf{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: $\mathbf{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: ${\mathbf{kfc}}=0$ or $1$.
6: $\mathbf{x}\left({\mathbf{nx}}\right)$Real (Kind=nag_wp) array Input
On entry: the $n$ values of the original undifferenced time series.
7: $\mathbf{nx}$Integer Input
On entry: $n$, the length of the original undifferenced time series.
8: $\mathbf{icount}\left(6\right)$Integer array Output
On exit: size of various output arrays.
${\mathbf{icount}}\left(1\right)$
Contains $q+\left(Q×s\right)$, the number of backforecasts.
${\mathbf{icount}}\left(2\right)$
Contains $n-d-\left(D×s\right)$, the number of differenced values.
${\mathbf{icount}}\left(3\right)$
Contains $d+\left(D×s\right)$, the number of values of reconstitution information.
${\mathbf{icount}}\left(4\right)$
Contains $n+q+\left(Q×s\right)$, the number of values held in each of the series ex, exr and al.
${\mathbf{icount}}\left(5\right)$
Contains $n-d-\left(D×s\right)-p-q-P-Q-{\mathbf{kfc}}$, the number of degrees of freedom associated with $S$.
${\mathbf{icount}}\left(6\right)$
Contains ${\mathbf{icount}}\left(1\right)+{\mathbf{npar}}+{\mathbf{kfc}}$, the number of parameters being estimated.
These values are always computed regardless of the exit value of ifail.
9: $\mathbf{ex}\left({\mathbf{iex}}\right)$Real (Kind=nag_wp) array Output
On exit: the extended differenced series which is made up of:
${\mathbf{icount}}\left(1\right)$ backforecast values of the differenced series.
${\mathbf{icount}}\left(2\right)$ actual values of the differenced series.
${\mathbf{icount}}\left(3\right)$ values of reconstitution information.
The total number of these values held in ex is ${\mathbf{icount}}\left(4\right)$.
If the routine exits because of a faulty input parameter, the contents of ex will be indeterminate.
10: $\mathbf{exr}\left({\mathbf{iex}}\right)$Real (Kind=nag_wp) array Output
On exit: the values of the model residuals which is made up of:
${\mathbf{icount}}\left(1\right)$ residuals corresponding to the backforecasts in the differenced series.
${\mathbf{icount}}\left(2\right)$ residuals corresponding to the actual values in the differenced series.
The remaining ${\mathbf{icount}}\left(3\right)$ 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: $\mathbf{al}\left({\mathbf{iex}}\right)$Real (Kind=nag_wp) array Output
On exit: the intermediate series which is made up of:
${\mathbf{icount}}\left(1\right)$ intermediate series values corresponding to the backforecasts in the differenced series.
${\mathbf{icount}}\left(2\right)$ intermediate series values corresponding to the actual values in the differenced series.
The remaining ${\mathbf{icount}}\left(3\right)$ values contain zeros.
If the routine exits with ${\mathbf{ifail}}\ne {\mathbf{0}}$, the contents of al will be indeterminate.
12: $\mathbf{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: ${\mathbf{iex}}\ge q+\left(Q×s\right)+n$, which is equivalent to the exit value of ${\mathbf{icount}}\left(4\right)$.
13: $\mathbf{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: $\mathbf{g}\left({\mathbf{igh}}\right)$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: $\mathbf{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: ${\mathbf{igh}}\ge q+\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}$ which is equivalent to the exit value of ${\mathbf{icount}}\left(6\right)$.
16: $\mathbf{sd}\left({\mathbf{igh}}\right)$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: $\mathbf{h}\left({\mathbf{ldh}},{\mathbf{igh}}\right)$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 $\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ 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 $\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ rows and the first $\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ columns of h. (Note that ${\mathbf{icount}}\left(6\right)$ 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 $\left(q+\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}+1\right)$th row of h is used internally as workspace.
18: $\mathbf{ldh}$Integer Input
On entry: the first dimension of the array h and
Constraint: ${\mathbf{ldh}}\ge 1+\mathit{q}+\left(\mathit{Q}×\mathit{s}\right)+{\mathbf{npar}}+{\mathbf{kfc}}$, which is equivalent to the exit value of ${\mathbf{icount}}\left(6\right)$.
19: $\mathbf{st}\left({\mathbf{ist}}\right)$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: $\mathbf{ist}$Integer Input
On entry: the dimension of the array st as declared in the (sub)program from which g13aef is called.
Constraint: ${\mathbf{ist}}\ge \left(P×s\right)+d+\left(D×s\right)+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)$.
21: $\mathbf{nst}$Integer Output
On exit: the number of values in the state set array st.
22: $\mathbf{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, 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)
 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: $\mathbf{mr}\left(7\right)$Integer array Input
2: $\mathbf{par}\left({\mathbf{npar}}\right)$Real (Kind=nag_wp) array Input
3: $\mathbf{npar}$Integer Input
4: $\mathbf{c}$Real (Kind=nag_wp) Input
5: $\mathbf{kfc}$Integer Input
6: $\mathbf{icount}\left(6\right)$Integer array Input
7: $\mathbf{s}$Real (Kind=nag_wp) Input
8: $\mathbf{g}\left({\mathbf{igh}}\right)$Real (Kind=nag_wp) array Input
9: $\mathbf{h}\left({\mathbf{ldh}},{\mathbf{igh}}\right)$Real (Kind=nag_wp) array Input
10: $\mathbf{ldh}$Integer Input
11: $\mathbf{igh}$Integer Input
12: $\mathbf{itc}$Integer Input
13: $\mathbf{zsp}\left(4\right)$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 ${\mathbf{kpiv}}=0$ a dummy piv must be supplied.
23: $\mathbf{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: $\mathbf{nit}$Integer Input
On entry: the maximum number of iterations to be performed.
Constraint: ${\mathbf{nit}}\ge 0$.
25: $\mathbf{itc}$Integer Output
On exit: the number of iterations performed.
26: $\mathbf{zsp}\left(4\right)$Real (Kind=nag_wp) array Input/Output
On entry: when ${\mathbf{kzsp}}=1$, the first four elements of zsp must contain the four values used to guide the search procedure. These are as follows.
${\mathbf{zsp}}\left(1\right)$ contains $\alpha$, the value used to constrain the magnitude of the search procedure steps.
${\mathbf{zsp}}\left(2\right)$ contains $\beta$, the multiplier which regulates the value $\alpha$.
${\mathbf{zsp}}\left(3\right)$ contains $\delta$, the value of the stationarity and invertibility test tolerance factor.
${\mathbf{zsp}}\left(4\right)$ contains $\gamma$, the value of the convergence criterion.
If ${\mathbf{kzsp}}\ne 1$ on entry, default values for zsp are supplied by the routine.
These are $0.001$, $10.0$, $1000.0$ and respectively.
On exit: zsp contains the values, default or otherwise, used by the routine.
Constraints:
if ${\mathbf{kzsp}}=1$,
• ${\mathbf{zsp}}\left(1\right)>0.0$, ;
• ${\mathbf{zsp}}\left(2\right)>1.0$, ;
• ${\mathbf{zsp}}\left(3\right)\ge 1.0$, ;
• $0\le {\mathbf{zsp}}\left(4\right)<1.0$.
27: $\mathbf{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: $\mathbf{isf}\left(4\right)$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. $\phantom{-}0$ No parameter of this type is in the model. $\phantom{-}1$ Valid final estimates for parameters of this type have been obtained.
29: $\mathbf{wa}\left({\mathbf{iwa}}\right)$Real (Kind=nag_wp) array Workspace
30: $\mathbf{iwa}$Integer Input
On entry: the dimension of the array wa as declared in the (sub)program from which g13aef is called.
Constraint: ${\mathbf{iwa}}\ge \left({F}_{1}×{F}_{2}\right)+\left(9×{\mathbf{npar}}\right)\text{,}$
 where ${F}_{1}={\mathbf{nx}}+1+p+\left(P×s\right)+q+\left(Q×s\right)$; and ${F}_{2}=8$ if ${\mathbf{kfc}}=1$; ${F}_{2}=7$ if ${\mathbf{kfc}}=0$, $Q>0$; ${F}_{2}=6$ if ${\mathbf{kfc}}=0$, $Q=0$, $P>0$; ${F}_{2}=5$ if ${\mathbf{kfc}}=0$, $Q=0$, $P=0$, $q>0$; ${F}_{2}=4$ otherwise.
31: $\mathbf{hc}\left({\mathbf{ldh}},{\mathbf{igh}}\right)$Real (Kind=nag_wp) array Workspace
32: $\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 $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. 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:
Note: in some cases g13aef may return useful information.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{kfc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{kfc}}=0$ or $1$.
On entry, ${\mathbf{npar}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{npar}}=p+q+P+Q$.
The orders vector mr is invalid.
${\mathbf{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., ${\mathbf{npar}}+{\mathbf{kfc}}\ge {\mathbf{nx}}-d-D×s$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{nit}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nit}}\ge 0$.
On entry, ${\mathbf{zsp}}\left(1\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{zsp}}\left(1\right)>0.0$.
On entry, ${\mathbf{zsp}}\left(2\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{zsp}}\left(2\right)>1.0$.
On entry, ${\mathbf{zsp}}\left(3\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{zsp}}\left(3\right)\ge 1.0$.
On entry, ${\mathbf{zsp}}\left(4\right)=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0\le {\mathbf{zsp}}\left(4\right)<1.0$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{ist}}=⟨\mathit{\text{value}}⟩$ and the minimum size $\text{required}=⟨\mathit{\text{value}}⟩$ (the minimum size required is returned in nst).
Constraint: ${\mathbf{ist}}\ge \left(P×s\right)+d+\left(D×s\right)+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{iwa}}=⟨\mathit{\text{value}}⟩$ and the minimum size $\text{required}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{iwa}}\ge \left({F}_{1}×{F}_{2}\right)+\left(9×{\mathbf{npar}}\right)$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{iex}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{iex}}\ge q×\left(Q×s\right)+{\mathbf{nx}}$.
On entry, ${\mathbf{igh}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{igh}}\ge q×\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}$.
On entry, ${\mathbf{ldh}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldh}}\ge q×\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}$.
${\mathbf{ifail}}=7$
A failure in the search procedure has occurred. Some output arguments may contain meaningful values.
${\mathbf{ifail}}=8$
Failure to invert $H$. Some output arguments may contain meaningful values.
${\mathbf{ifail}}=9$
Unable to calculate the latest estimates of the backforecasts.
Some output arguments may contain meaningful values.
${\mathbf{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.
${\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

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.

The time taken by g13aef is approximately proportional to ${\mathbf{nx}}×{\mathbf{itc}}×\phantom{\rule{0ex}{0ex}}{\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)}^{2}$.

## 10Example

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 $\left(\varphi \right)$, and two moving average $\left(\theta \right)$. No seasonal effects are taken into account.
The constant is estimated. Up to $25$ iterations are allowed.
The initial estimates of ${\varphi }_{1}$, ${\theta }_{1}$, ${\theta }_{2}$ and $c$ are zero.

### 10.1Program Text

Program Text (g13aefe.f90)

### 10.2Program Data

Program Data (g13aefe.d)

### 10.3Program Results

Program Results (g13aefe.r)