Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_uni_arima_estim (g13ae)

## Purpose

nag_tsa_uni_arima_estim (g13ae) 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 functions nag_tsa_uni_arima_update (g13ag) and nag_tsa_uni_arima_forecast_state (g13ah).
The estimation procedure is iterative, starting with initial parameter values such as may be obtained using nag_tsa_uni_arima_prelim (g13ad). 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 function.

## Syntax

[par, c, icount, ex, exr, al, s, g, sd, h, st, nst, itc, zsp, isf, ifail] = g13ae(mr, par, c, x, iex, igh, ist, piv, kpiv, zsp, kzsp, 'npar', npar, 'kfc', kfc, 'nx', nx, 'nit', nit)
[par, c, icount, ex, exr, al, s, g, sd, h, st, nst, itc, zsp, isf, ifail] = nag_tsa_uni_arima_estim(mr, par, c, x, iex, igh, ist, piv, kpiv, zsp, kzsp, 'npar', npar, 'kfc', kfc, 'nx', nx, 'nit', nit)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: nit and kfc optional
.

## Description

The time series x1,x2,,xn${x}_{1},{x}_{2},\dots ,{x}_{n}$ supplied to nag_tsa_uni_arima_estim (g13ae) is assumed to follow a seasonal autoregressive integrated moving average (ARIMA) model defined as follows:
 ∇d∇sDxt − c = wt, $∇d∇sDxt-c=wt,$
where dsDxt${\nabla }^{d}{\nabla }_{s}^{D}{x}_{t}$ is the result of applying non-seasonal differencing of order d$d$ and seasonal differencing of seasonality s$s$ and order D$D$ to the series xt${x}_{t}$, as outlined in the description of nag_tsa_uni_diff (g13aa). The differenced series is then of length N = nd$N=n-{d}^{\prime }$, where d = d + (D × s)${d}^{\prime }=d+\left(D×s\right)$ is the generalized order of differencing. The scalar c$c$ is the expected value of the differenced series, and the series w1,w2,,wN${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 wt${w}_{t}$ in terms of an uncorrelated series at${a}_{t}$, via an intermediate series et${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. $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${e}_{t}$ above is equated with wt${w}_{t}$:
 et = φ1et − 1 + φ2et − 2 + ⋯ + φpet − p + at − θ1at − 1 − θ2at − 2 − ⋯ − θqat − q. $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
$ϕ1,ϕ2,…,ϕp,θ1,θ2,…,θq, Φ1,Φ2,…,ΦP,Θ1,Θ2,…,ΘQ$
and (optionally) c$c$ are obtained by minimizing a quadratic form in the vector w = (w1,w2,,wN)$w={\left({w}_{1},{w}_{2},\dots ,{w}_{N}\right)}^{\prime }$.
This is QF = wV1w$QF={w}^{\prime }{V}^{-1}w$, where V$V$ is the covariance matrix of w$w$, and is a function of the model parameters. This matrix is not explicitly evaluated, since QF$QF$ may be expressed as a ‘sum of squares’ function. When moving average parameters θi${\theta }_{i}$ or Θi${\Theta }_{i}$ are present, so that the generalized moving average order q = q + s × Q${q}^{\prime }=q+s×Q$ is positive, backforecasts w1q,w2q,,w0${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
 N − q′ S(pm) = ∑ at2 − ∑ bt2, t = 1 − q′ t = 1 − q′ − p′
$S(pm)=∑t=1-q′Nat2-∑t=1-q′-p′ -q′bt2,$
where pm$pm$ is a combined vector of parameters, consisting of the backforecasts followed by the ARMA model parameters.
The terms at${a}_{t}$ correspond to the ARMA model residual series at${a}_{t}$, and p = p + s × P${p}^{\prime }=p+s×P$ is the generalized autoregressive order. The terms bt${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 at${a}_{t}$ and bt${b}_{t}$ are precisely:
• et = wtΦ1wtsΦ2wt2 × sΦPwtP × s + Θ1ets + Θ2et2 × s + + ΘQetQ × s${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 = 1q,2q,,n$t=1-{q}^{\prime },2-{q}^{\prime },\dots ,n$.
• at = etφ1et1φ2et2φpetp + θ1at1 + θ2at2 + + θqatq${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 = 1q,2q,,n$t=1-{q}^{\prime },2-{q}^{\prime },\dots ,n$.
• ft = wtΦ1wt + sΦ2wt + 2 × sΦPwt + P × s + Θ1fts + Θ2ft2 × s + + ΘQftQ × s${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 = (1qs × P),(2qs × P),,(q + P)$t=\left(1-{q}^{\prime }-s×P\right),\left(2-{q}^{\prime }-s×P\right),\dots ,\left(-{q}^{\prime }+P\right)$
• bt = ftφ1ft + 1φ2ft + 2φpft + p + θ1bt1 + θ2bt2 + + θqbtq${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 = (1qp),(2qp),,(q)$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:
• wi = 0${w}_{i}=0$ if i < 1q$i<1-{q}^{\prime }$
• ei = 0${e}_{i}=0$ if i < 1q$i<1-{q}^{\prime }$
• ai = 0${a}_{i}=0$ if i < 1q$i<1-{q}^{\prime }$
• fi = 0${f}_{i}=0$ if i < 1qs × P$i<1-{q}^{\prime }-s×P$
• bi = 0${b}_{i}=0$ if i < 1qp$i<1-{q}^{\prime }-{p}^{\prime }$
Minimization of S$S$ with respect to pm$pm$ uses an extension of the algorithm of Marquardt (1963).
The first derivatives of S$S$ with respect to the parameters are calculated as
 2 × ∑ at × at,i − 2 ∑ bt × bt,i = 2 × Gi, $2×∑at×at,i-2∑bt×bt,i=2×Gi,$
where at,i${a}_{t,i}$ and bt,i${b}_{t,i}$ are derivatives of at${a}_{t}$ and bt${b}_{t}$ with respect to the i$i$th parameter.
The second derivative of S$S$ is approximated by
 2 × ∑ at,i × at,j − 2 × ∑ bt,i × bt,j = 2 × Hij. $2×∑at,i×at,j-2×∑bt,i×bt,j=2×Hij.$
Successive parameter iterates are obtained by calculating a vector of corrections dpm$\mathit{dpm}$ by solving the equations
 (H + α × D) × dpm = − G, $(H+α×D)×dpm=-G,$
where G$G$ is a vector with elements Gi${G}_{i}$, H$H$ is a matrix with elements Hij${H}_{ij}$, α$\alpha$ is a scalar used to control the search and D$D$ is the diagonal matrix of H$H$.
The new parameter values are then pm + dpm$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$S$, then α$\alpha$ is reduced by a factor β$\beta$. If a step results in new parameter values which give an increased value of S$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$S$ is obtained, or α$\alpha$ reaches the limit of 109${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 α < 1.0$\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 , $erv = Smin / df ,$
where Smin${S}_{\mathrm{min}}$ is the final value of S$S$, and the residual number of degrees of freedom is given by
 df = N − p − q − P − Q   ( − 1​ if ​c​ is estimated) . $df = N-p-q-P-Q ( -1 ​ if ​ c ​ is estimated ) .$
The covariance matrix of the vector of estimates pm$pm$ is given by
 erv × H − 1 , $erv × H-1 ,$
where H$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${w}_{t}$ (now uncorrected for the constant), intermediate series et${e}_{t}$ and residual series at${a}_{t}$ are all available upon completion of the iterations over the range (extended by backforecasts)
 t = 1 − q′,2 − q′, … ,N. $t=1-q′,2-q′,…,N.$
The values at${a}_{t}$ can only properly be interpreted as residuals for t1 + pq$t\ge 1+{p}^{\prime }-{q}^{\prime }$, as the earlier values are corrupted by transients if p > 0${p}^{\prime }>0$.
In consequence of the manner in which differencing is implemented, the residual at${a}_{t}$ is the one step ahead forecast error for xt + d${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:
 (i) the differenced series wt${w}_{t}$, for (N − s × P) < t ≤ N$\left(N-s×P\right), (ii) the d′${d}^{\prime }$ values required to reconstitute the original series xt${x}_{t}$ from the differenced series wt${w}_{t}$, (iii) the intermediate series et${e}_{t}$, for (N − max (p, Q × s )) < t ≤ N $\left(N-\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)\right), (iv) the residual series at${a}_{t}$, for (N − q) < t ≤ N$\left(N-q\right).
This state set is available upon completion of the iterations. The function may be used purely for the construction of this state set, given a previously estimated model and time series xt${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, nag_tsa_uni_arima_update (g13ag) can be used.

## 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

## Parameters

### Compulsory Input Parameters

1:     mr(7$7$) – int64int32nag_int array
The orders vector (p,d,q,P,D,Q,s)$\left(p,d,q,P,D,Q,s\right)$ of the ARIMA model whose parameters are to be estimated. p$p$, q$q$, P$P$ and Q$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$, D$D$ and s$s$ refer respectively to the order of non-seasonal differencing, the order of seasonal differencing and the seasonal period.
Constraints:
• p$p$, d$d$, q$q$, P$P$, D$D$, Q$Q$, s0$s\ge 0$;
• p + q + P + Q > 0$p+q+P+Q>0$;
• s1$s\ne 1$;
• if s = 0$s=0$, P + D + Q = 0$P+D+Q=0$;
• if s > 1$s>1$, P + D + Q > 0$P+D+Q>0$;
• d + s × (P + D)n$d+s×\left(P+D\right)\le n$;
• p + dq + s × (P + DQ)n$p+d-q+s×\left(P+D-Q\right)\le n$.
2:     par(npar) – double array
npar, the dimension of the array, must satisfy the constraint npar = p + q + P + Q${\mathbf{npar}}=p+q+P+Q$.
The initial estimates of the p$p$ values of the φ$\varphi$ parameters, the q$q$ values of the θ$\theta$ parameters, the P$P$ values of the Φ$\Phi$ parameters and the Q$Q$ values of the Θ$\Theta$ parameters, in that order.
3:     c – double scalar
If kfc = 0${\mathbf{kfc}}=0$, c must contain the expected value, c$c$, of the differenced series.
If kfc = 1${\mathbf{kfc}}=1$, c must contain an initial estimate of c$c$.
4:     x(nx) – double array
The n$n$ values of the original undifferenced time series.
5:     iex – int64int32nag_int scalar
The dimension of the arrays ex, exr and al as declared in the (sub)program from which nag_tsa_uni_arima_estim (g13ae) is called.
Constraint: iexq + (Q × s) + n${\mathbf{iex}}\ge q+\left(Q×s\right)+n$, which is equivalent to the exit value of icount(4)${\mathbf{icount}}\left(4\right)$.
6:     igh – int64int32nag_int scalar
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 nag_tsa_uni_arima_estim (g13ae) is called.
Constraint: ighq + (Q × s) + npar + kfc${\mathbf{igh}}\ge q+\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}$ which is equivalent to the exit value of icount(6)${\mathbf{icount}}\left(6\right)$.
7:     ist – int64int32nag_int scalar
The dimension of the array st as declared in the (sub)program from which nag_tsa_uni_arima_estim (g13ae) is called.
Constraint: ist(P × s) + d + (D × s) + q + max (p,Q × s)${\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)$.
8:     piv – function handle or string containing name of m-file
piv is used to monitor the progress of the optimization.
piv(mr, par, npar, c, kfc, icount, s, g, h, ldh, igh, itc, zsp)

Input Parameters

1:     mr(7$7$) – int64int32nag_int array
2:     par(npar) – double array
3:     npar – int64int32nag_int scalar
4:     c – double scalar
5:     kfc – int64int32nag_int scalar
6:     icount(6$6$) – int64int32nag_int array
7:     s – double scalar
8:     g(igh) – double array
9:     h(ldh,igh) – double array
10:   ldh – int64int32nag_int scalar
11:   igh – int64int32nag_int scalar
12:   itc – int64int32nag_int scalar
13:   zsp(4$4$) – double array
All the parameters are defined as for nag_tsa_uni_arima_estim (g13ae) itself.
If kpiv = 0${\mathbf{kpiv}}=0$ a dummy piv must be supplied.
9:     kpiv – int64int32nag_int scalar
Must be nonzero if the progress of the optimization is to be monitored using piv. Otherwise kpiv must contain 0$0$.
10:   zsp(4$4$) – double array
When kzsp = 1${\mathbf{kzsp}}=1$, the first four elements of zsp must contain the four values used to guide the search procedure. These are as follows.
zsp(1)${\mathbf{zsp}}\left(1\right)$ contains α$\alpha$, the value used to constrain the magnitude of the search procedure steps.
zsp(2)${\mathbf{zsp}}\left(2\right)$ contains β$\beta$, the multiplier which regulates the value α$\alpha$.
zsp(3)${\mathbf{zsp}}\left(3\right)$ contains δ$\delta$, the value of the stationarity and invertibility test tolerance factor.
zsp(4)${\mathbf{zsp}}\left(4\right)$ contains γ$\gamma$, the value of the convergence criterion.
If kzsp1${\mathbf{kzsp}}\ne 1$ on entry, default values for zsp are supplied by the function.
These are 0.001$0.001$, 10.0$10.0$, 1000.0$1000.0$ and max (100 × machine precision,0.0000001) respectively.
Constraint: if kzsp = 1${\mathbf{kzsp}}=1$, zsp(1) > 0.0${\mathbf{zsp}}\left(1\right)>0.0$, zsp(2) > 1.0${\mathbf{zsp}}\left(2\right)>1.0$, zsp(3)1.0${\mathbf{zsp}}\left(3\right)\ge 1.0$, 0zsp(4) < 1.0$0\le {\mathbf{zsp}}\left(4\right)<1.0$.
11:   kzsp – int64int32nag_int scalar
The value 1$1$ if the function is to use the input values of zsp, and any other value if the default values of zsp are to be used.

### Optional Input Parameters

1:     npar – int64int32nag_int scalar
Default: The dimension of the array par.
The total number of φ$\varphi$, θ$\theta$, Φ$\Phi$ and Θ$\Theta$ parameters to be estimated.
Constraint: npar = p + q + P + Q${\mathbf{npar}}=p+q+P+Q$.
2:     kfc – int64int32nag_int scalar
Must be set to 1$1$ if the constant, c$c$, is to be estimated and 0$0$ if it is to be held fixed at its initial value.
Default: 1$1$
Constraint: kfc = 0${\mathbf{kfc}}=0$ or 1$1$.
3:     nx – int64int32nag_int scalar
Default: The dimension of the array x.
n$n$, the length of the original undifferenced time series.
4:     nit – int64int32nag_int scalar
The maximum number of iterations to be performed.
Default: 100$100$
Constraint: nit0${\mathbf{nit}}\ge 0$.

ldh wa iwa hc

### Output Parameters

1:     par(npar) – double array
The latest values of the estimates of these parameters.
2:     c – double scalar
If kfc = 0${\mathbf{kfc}}=0$, c is unchanged.
If kfc = 1${\mathbf{kfc}}=1$, c contains the latest estimate of c$c$.
Therefore, if c and kfc are both zero on entry, there is no constant correction.
3:     icount(6$6$) – int64int32nag_int array
Size of various output arrays.
icount(1)${\mathbf{icount}}\left(1\right)$
Contains q + (Q × s)$q+\left(Q×s\right)$, the number of backforecasts.
icount(2)${\mathbf{icount}}\left(2\right)$
Contains nd(D × s)$n-d-\left(D×s\right)$, the number of differenced values.
icount(3)${\mathbf{icount}}\left(3\right)$
Contains d + (D × s)$d+\left(D×s\right)$, the number of values of reconstitution information.
icount(4)${\mathbf{icount}}\left(4\right)$
Contains n + q + (Q × s)$n+q+\left(Q×s\right)$, the number of values held in each of the series ex, exr and al.
icount(5)${\mathbf{icount}}\left(5\right)$
Contains nd(D × s)pqPQkfc$n-d-\left(D×s\right)-p-q-P-Q-{\mathbf{kfc}}$, the number of degrees of freedom associated with S$S$.
icount(6)${\mathbf{icount}}\left(6\right)$
Contains icount(1) + npar + kfc${\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.
4:     ex(iex) – double array
The extended differenced series which is made up of:
icount(1)${\mathbf{icount}}\left(1\right)$ backforecast values of the differenced series.
icount(2)${\mathbf{icount}}\left(2\right)$ actual values of the differenced series.
icount(3)${\mathbf{icount}}\left(3\right)$ values of reconstitution information.
The total number of these values held in ex is icount(4)${\mathbf{icount}}\left(4\right)$.
If the function exits because of a faulty input parameter, the contents of ex will be indeterminate.
5:     exr(iex) – double array
The values of the model residuals which is made up of:
icount(1)${\mathbf{icount}}\left(1\right)$ residuals corresponding to the backforecasts in the differenced series.
icount(2)${\mathbf{icount}}\left(2\right)$ residuals corresponding to the actual values in the differenced series.
The remaining icount(3)${\mathbf{icount}}\left(3\right)$ values contain zeros.
If the function exits with ifail holding a value other than 0$0$ or 9$9$, the contents of exr will be indeterminate.
6:     al(iex) – double array
The intermediate series which is made up of:
icount(1)${\mathbf{icount}}\left(1\right)$ intermediate series values corresponding to the backforecasts in the differenced series.
icount(2)${\mathbf{icount}}\left(2\right)$ intermediate series values corresponding to the actual values in the differenced series.
The remaining icount(3)${\mathbf{icount}}\left(3\right)$ values contain zeros.
If the function exits with ${\mathbf{ifail}}\ne {\mathbf{0}}$, the contents of al will be indeterminate.
7:     s – double scalar
The residual sum of squares after the latest series of parameter estimates has been incorporated into the model. If the function exits with a faulty input parameter, s contains zero.
8:     g(igh) – double array
The latest value of the derivatives of S$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 function exits with a faulty input parameter.
9:     sd(igh) – double array
The standard deviations corresponding to each of the parameters being estimated (backforecasts, par parameters, and where relevant the constant, in that order).
If the function exits with ifail containing a value other than 0$0$ or 9$9$, or if the required number of iterations is zero, the contents of sd will be indeterminate.
10:   h(ldh,igh) – double array
ldh1 + q + (q × s) + npar + kfc$\mathit{ldh}\ge 1+\mathit{q}+\left(\mathit{q}×\mathit{s}\right)+{\mathbf{npar}}+{\mathbf{kfc}}$, which is equivalent to the exit value of icount(6)${\mathbf{icount}}\left(6\right)$.
The second derivative of S$S$ and correlation coefficients.
 (a) the latest values of an approximation to the second derivative of S$S$ with respect to each of the (q + Q × s + npar + kfc)$\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ parameters being estimated (backforecasts, par parameters, and where relevant the constant – in that order), and (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)$\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ rows and the first (q + Q × s + npar + kfc)$\left(q+Q×s+{\mathbf{npar}}+{\mathbf{kfc}}\right)$ columns of h. (Note that icount(6)${\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$0$ or 9$9$.
All the contents of h are indeterminate if the required number of iterations are zero. The (q + (Q × s) + npar + kfc + 1)$\left(q+\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}+1\right)$th row of h is used internally as workspace.
11:   st(ist) – double array
The nst values of the state set array. If the function exits with ifail containing a value other than 0$0$ or 9$9$, the contents of st will be indeterminate.
12:   nst – int64int32nag_int scalar
The number of values in the state set array st.
13:   itc – int64int32nag_int scalar
The number of iterations performed.
14:   zsp(4$4$) – double array
zsp contains the values, default or otherwise, used by the function.
15:   isf(4$4$) – int64int32nag_int array
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$-2$ On entry parameters of this type have initial estimates which do not satisfy the stationarity or invertibility test conditions. − 1$-1$ The search procedure has failed to converge because the latest set of parameter estimates of this type is invalid. − 0$\phantom{-}0$ No parameter of this type is in the model. − 1$\phantom{-}1$ Valid final estimates for parameters of this type have been obtained.
16:   ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_tsa_uni_arima_estim (g13ae) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, npar ≠ p + q + P + Q${\mathbf{npar}}\ne p+q+P+Q$, or the orders vector mr is invalid (check it against the constraints in Section [Parameters]), or kfc ≠ 0${\mathbf{kfc}}\ne 0$ or 1$1$.
ifail = 2${\mathbf{ifail}}=2$
On entry, nxdD × snpar + kfc${\mathbf{nx}}-d-D×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 over-parameterised.
ifail = 3${\mathbf{ifail}}=3$
 On entry, one or more of the user-supplied criteria for controlling the iterative process are invalid, or nit < 0${\mathbf{nit}}<0$, or if kzsp = 1${\mathbf{kzsp}}=1$, zsp(1) ≤ 0.0${\mathbf{zsp}}\left(1\right)\le 0.0$; or if kzsp = 1${\mathbf{kzsp}}=1$, zsp(2) ≤ 1.0${\mathbf{zsp}}\left(2\right)\le 1.0$; or if kzsp = 1${\mathbf{kzsp}}=1$, zsp(3) < 1.0${\mathbf{zsp}}\left(3\right)<1.0$; or if kzsp = 1${\mathbf{kzsp}}=1$, zsp(4) < 0.0${\mathbf{zsp}}\left(4\right)<0.0$; or if kzsp = 1${\mathbf{kzsp}}=1$, zsp(4) ≥ 1.0${\mathbf{zsp}}\left(4\right)\ge 1.0$.
ifail = 4${\mathbf{ifail}}=4$
On entry, the state set array st is too small. The output value of nst contains the required value (see the description of ist in Section [Parameters] for the formula).
ifail = 5${\mathbf{ifail}}=5$
On entry, the workspace array wa is too small. Check the value of iwa against the constraints in Section [Parameters].
W ifail = 6${\mathbf{ifail}}=6$
 On entry, iex < q + (Q × s) + nx${\mathbf{iex}}, or igh < q + (Q × s) + npar + kfc${\mathbf{igh}}, or ldh ≤ q + (Q × s) + npar + kfc$\mathit{ldh}\le q+\left(Q×s\right)+{\mathbf{npar}}+{\mathbf{kfc}}$.
W ifail = 7${\mathbf{ifail}}=7$
This indicates a failure in the search procedure, with zsp(1)1.0e09${\mathbf{zsp}}\left(1\right)\ge \text{1.0e09}$.
Some output parameters may contain meaningful values; see Section [Parameters] for details.
W ifail = 8${\mathbf{ifail}}=8$
This indicates a failure to invert H$H$.
Some output parameters may contain meaningful values; see Section [Parameters] for details.
W ifail = 9${\mathbf{ifail}}=9$
This indicates a failure in nag_linsys_real_posdef_solve_1rhs (f04as) which is used to solve the equations giving the latest estimates of the backforecasts.
Some output parameters may contain meaningful values; see Section [Parameters] for details.
W ifail = 10${\mathbf{ifail}}=10$
Satisfactory parameter estimates could not be obtained for all parameter types in the model. Inspect array isf for further information on the parameter type(s) in error.

## Accuracy

The computations are believed to be stable.

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

## Example

```function nag_tsa_uni_arima_estim_example
mr = [int64(1);1;2;0;0;0;0];
par = [0; 0; 0];
c = 0;
x = [-217;
-177;
-166;
-136;
-110;
-95;
-64;
-37;
-14;
-25;
-51;
-62;
-73;
-88;
-113;
-120;
-83;
-33;
-19;
21;
17;
44;
44;
78;
88;
122;
126;
114;
85;
64];
iex = int64(32);
igh = int64(6);
ist = int64(4);
kpiv = int64(0);
zsp = [0.001; 10; 1000; 0.0001];
kzsp = int64(1);
[parOut, cOut, icount, ex, exr, al, s, g, sd, h, st, nst, itc, zspOut, isf, ifail] = ...
nag_tsa_uni_arima_estim(mr, par, c, x, iex, igh, ist, @piv, kpiv, zsp, kzsp)

function [] = piv(mr, par, npar, c, kfc, icount, s, g, h, ih, igh, itc, zsp)

fprintf('Iteration %d  residual sum f squares = %16.4', itc, s);
```
```

parOut =

-0.0547
-0.5568
-0.6636

cOut =

9.9807

icount =

2
29
1
32
25
6

ex =

19.5250
5.8753
40.0000
11.0000
30.0000
26.0000
15.0000
31.0000
27.0000
23.0000
-11.0000
-26.0000
-11.0000
-11.0000
-15.0000
-25.0000
-7.0000
37.0000
50.0000
14.0000
40.0000
-4.0000
27.0000
0
34.0000
10.0000
34.0000
4.0000
-12.0000
-29.0000
-21.0000
64.0000

exr =

19.5250
-3.9279
19.5711
-5.6291
10.2221
15.1582
-9.3276
16.4285
15.2115
-5.4211
-27.3444
-18.3061
5.3890
-12.9812
-22.4767
-15.2183
4.4944
33.6867
19.7586
-27.1470
32.2426
-12.2765
1.6941
-1.8465
23.3772
-10.4576
14.3302
-5.7061
-28.6401
-20.4502
-2.7215
0

al =

19.5250
5.8753
30.0193
1.0193
20.0193
16.0193
5.0193
21.0193
17.0193
13.0193
-20.9807
-35.9807
-20.9807
-20.9807
-24.9807
-34.9807
-16.9807
27.0193
40.0193
4.0193
30.0193
-13.9807
17.0193
-9.9807
24.0193
0.0193
24.0193
-5.9807
-21.9807
-38.9807
-30.9807
0

s =

9.3979e+03

g =

-0.1512
-0.2343
-6.4097
13.5617
-72.6232
-0.1642

sd =

14.8379
15.1887
0.3507
0.2709
0.1695
7.3893

h =

1.0e+04 *

0.0002   -0.0001    0.0000    0.0002   -0.0001    0.0000
0.0000    0.0002   -0.0000   -0.0000    0.0002    0.0001
-0.0000    0.0000    0.9042   -0.9682    0.0546    0.0001
-0.0000    0.0000    0.0001    1.7031   -0.5676    0.0007
-0.0000   -0.0000    0.0000    0.0000    1.7028    0.0006
-0.0000   -0.0000   -0.0000   -0.0000   -0.0000    0.0007
-0.0000   -0.0000   -0.0000   -0.0000   -0.0000    0.0000

st =

64.0000
-30.9807
-20.4502
-2.7215

nst =

4

itc =

16

zspOut =

1.0e+03 *

0.0000
0.0100
1.0000
0.0000

isf =

1
1
0
0

ifail =

0

```
```function g13ae_example
mr = [int64(1);1;2;0;0;0;0];
par = [0; 0; 0];
c = 0;
x = [-217;
-177;
-166;
-136;
-110;
-95;
-64;
-37;
-14;
-25;
-51;
-62;
-73;
-88;
-113;
-120;
-83;
-33;
-19;
21;
17;
44;
44;
78;
88;
122;
126;
114;
85;
64];
iex = int64(32);
igh = int64(6);
ist = int64(4);
kpiv = int64(0);
zsp = [0.001; 10; 1000; 0.0001];
kzsp = int64(1);
[parOut, cOut, icount, ex, exr, al, s, g, sd, h, st, nst, itc, zspOut, isf, ifail] = ...
g13ae(mr, par, c, x, iex, igh, ist, @piv, kpiv, zsp, kzsp)

function [] = piv(mr, par, npar, c, kfc, icount, s, g, h, ih, igh, itc, zsp)

fprintf('Iteration %d  residual sum f squares = %16.4', itc, s);
```
```

parOut =

-0.0547
-0.5568
-0.6636

cOut =

9.9807

icount =

2
29
1
32
25
6

ex =

19.5250
5.8753
40.0000
11.0000
30.0000
26.0000
15.0000
31.0000
27.0000
23.0000
-11.0000
-26.0000
-11.0000
-11.0000
-15.0000
-25.0000
-7.0000
37.0000
50.0000
14.0000
40.0000
-4.0000
27.0000
0
34.0000
10.0000
34.0000
4.0000
-12.0000
-29.0000
-21.0000
64.0000

exr =

19.5250
-3.9279
19.5711
-5.6291
10.2221
15.1582
-9.3276
16.4285
15.2115
-5.4211
-27.3444
-18.3061
5.3890
-12.9812
-22.4767
-15.2183
4.4944
33.6867
19.7586
-27.1470
32.2426
-12.2765
1.6941
-1.8465
23.3772
-10.4576
14.3302
-5.7061
-28.6401
-20.4502
-2.7215
0

al =

19.5250
5.8753
30.0193
1.0193
20.0193
16.0193
5.0193
21.0193
17.0193
13.0193
-20.9807
-35.9807
-20.9807
-20.9807
-24.9807
-34.9807
-16.9807
27.0193
40.0193
4.0193
30.0193
-13.9807
17.0193
-9.9807
24.0193
0.0193
24.0193
-5.9807
-21.9807
-38.9807
-30.9807
0

s =

9.3979e+03

g =

-0.1512
-0.2343
-6.4097
13.5617
-72.6232
-0.1642

sd =

14.8379
15.1887
0.3507
0.2709
0.1695
7.3893

h =

1.0e+04 *

0.0002   -0.0001    0.0000    0.0002   -0.0001    0.0000
0.0000    0.0002   -0.0000   -0.0000    0.0002    0.0001
-0.0000    0.0000    0.9042   -0.9682    0.0546    0.0001
-0.0000    0.0000    0.0001    1.7031   -0.5676    0.0007
-0.0000   -0.0000    0.0000    0.0000    1.7028    0.0006
-0.0000   -0.0000   -0.0000   -0.0000   -0.0000    0.0007
-0.0000   -0.0000   -0.0000   -0.0000   -0.0000    0.0000

st =

64.0000
-30.9807
-20.4502
-2.7215

nst =

4

itc =

16

zspOut =

1.0e+03 *

0.0000
0.0100
1.0000
0.0000

isf =

1
1
0
0

ifail =

0

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013