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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_uni_arima_forcecast (g13aj)

## Purpose

nag_tsa_uni_arima_forcecast (g13aj) applies a fully specified seasonal ARIMA model to an observed time series, generates the state set for forecasting and (optionally) derives a specified number of forecasts together with their standard deviations.

## Syntax

[rms, st, nst, fva, fsd, isf, ifail] = g13aj(mr, par, c, kfc, x, ist, nfv, ifv, 'npar', npar, 'nx', nx)
[rms, st, nst, fva, fsd, isf, ifail] = nag_tsa_uni_arima_forcecast(mr, par, c, kfc, x, ist, nfv, ifv, 'npar', npar, 'nx', nx)

## Description

The time series x1,x2,,xn${x}_{1},{x}_{2},\dots ,{x}_{n}$ supplied to the function is assumed to follow a seasonal autoregressive integrated moving average (ARIMA) model with known parameters.
The model is defined by the following relations.
 (a) ∇d∇sDxt − c = wt${\nabla }^{d}{\nabla }_{s}^{D}{x}_{t}-c={w}_{t}$ where ∇d∇sDxt${\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}$, and c$c$ is a constant. (b) wt = Φ1wt − s + Φ2wt − 2 × s + ⋯ + ΦPwt − P × s + et − Θ1et − s − Θ2et − 2 × s − ⋯ − ΘQet − Q × s.${w}_{t}={\Phi }_{1}{w}_{t-s}+{\Phi }_{2}{w}_{t-2×s}+\cdots +{\Phi }_{P}{w}_{t-P×s}+{e}_{t}-{\Theta }_{1}{e}_{t-s}-{\Theta }_{2}{e}_{t-2×s}-\cdots -{\Theta }_{Q}{e}_{t-Q×s}\text{.}$ This equation describes the seasonal structure with seasonal period s$s$; in the absence of seasonality it reduces to wt = et${w}_{t}={e}_{t}$. (c) et = φ1et − 1 + φ2et − 2 + ⋯ + φpet − p + at − θ1at − 1 − θ2at − 2 − ⋯ − θqat − q.${e}_{t}={\varphi }_{1}{e}_{t-1}+{\varphi }_{2}{e}_{t-2}+\cdots +{\varphi }_{p}{e}_{t-p}+{a}_{t}-{\theta }_{1}{a}_{t-1}-{\theta }_{2}{a}_{t-2}-\cdots -{\theta }_{q}{a}_{t-q}\text{.}$ This equation describes the non-seasonal structure.
Given the series, the constant c$c$, and the model parameters Φ$\Phi$, Θ$\Theta$, φ$\varphi$, θ$\theta$, the function computes the following.
(a) The state set required for forecasting. This contains the minimum amount of information required for forecasting and comprises:
 (i) the differenced series wt${w}_{t}$, for (N − s × P) ≤ t ≤ N$\left(N-s×P\right)\le t\le N$; (ii) the (d + D × s)$\left(d+D×s\right)$ 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$N-\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right); (iv) the residual series at${a}_{t}$, for (N − q) < t ≤ N$\left(N-q\right), where N = n − (d + D × s)$N=n-\left(d+D×s\right)$.
(b) A set of L$L$ forecasts of xt${x}_{t}$ and their estimated standard errors, st${s}_{t}$, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$ (L$L$ may be zero).
The forecasts and estimated standard errors are generated from the state set, and are identical to those that would be produced from the same state set by nag_tsa_uni_arima_forecast_state (g13ah).
Use of nag_tsa_uni_arima_forcecast (g13aj) should be confined to situations in which the state set for forecasting is unknown. Forecasting from the series requires recalculation of the state set and this is relatively expensive.

## References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day

## 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, in the usual notation.
Constraints:
• p,d,q,P,D,Q,s0$p,d,q,P,D,Q,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 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
c$c$, the expected value of the differenced series (i.e., c$c$ is the constant correction). Where there is no constant term, c must be set to 0.0$0.0$.
4:     kfc – int64int32nag_int scalar
Must be set to 0$0$ if c was not estimated, and 1$1$ if c was estimated. This is irrespective of whether or not c = 0.0${\mathbf{c}}=0.0$. The only effect is that the residual degrees of freedom are one greater when kfc = 0${\mathbf{kfc}}=0$. Assuming the supplied time series to be the same as that to which the model was originally fitted, this ensures an unbiased estimate of the residual mean-square.
Constraint: kfc = 0${\mathbf{kfc}}=0$ or 1$1$.
5:     x(nx) – double array
The n$n$ values of the original undifferenced time series.
6:     ist – int64int32nag_int scalar
The dimension of the array st as declared in the (sub)program from which nag_tsa_uni_arima_forcecast (g13aj) 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)$. The expression on the right-hand side of the inequality is returned in nst.
7:     nfv – int64int32nag_int scalar
The required number of forecasts. If nfv0${\mathbf{nfv}}\le 0$, no forecasts will be computed.
8:     ifv – int64int32nag_int scalar
The dimension of the arrays fva and fsd as declared in the (sub)program from which nag_tsa_uni_arima_forcecast (g13aj) is called.
Constraint: ifvmax (1,nfv)${\mathbf{ifv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nfv}}\right)$.

### Optional Input Parameters

1:     npar – int64int32nag_int scalar
Default: The dimension of the array par.
The exact number of φ$\varphi$, θ$\theta$, Φ$\Phi$ and Θ$\Theta$ parameters.
Constraint: npar = p + q + P + Q${\mathbf{npar}}=p+q+P+Q$.
2:     nx – int64int32nag_int scalar
Default: The dimension of the array x.
n$n$, the length of the original undifferenced time series.

w iw

### Output Parameters

1:     rms – double scalar
The residual variance (mean square) associated with the model.
2:     st(ist) – double array
The nst values of the state set.
3:     nst – int64int32nag_int scalar
The number of values in the state set array st.
4:     fva(ifv) – double array
If nfv > 0${\mathbf{nfv}}>0$, fva contains the nfv forecast values relating to the original undifferenced time series.
5:     fsd(ifv) – double array
If nfv > 0${\mathbf{nfv}}>0$, fsd contains the estimated standard errors of the nfv forecast values.
6:     isf(4$4$) – int64int32nag_int array
Contains validity indicators, one for each of the four possible parameter types in the model (autoregressive, moving average, seasonal autoregressive, seasonal moving average), in that order.
Each indicator has the interpretation:
 − 1$-1$ On entry the set of parameter values of this type does not satisfy the stationarity or invertibility test conditions. − 0$\phantom{-}0$ No parameter of this type is in the model. − 1$\phantom{-}1$ Valid parameter values of this type have been supplied.
7:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
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 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, the workspace array w is too small.
ifail = 4${\mathbf{ifail}}=4$
On entry, the state set array st is too small. It must be at least as large as the exit value of nst.
ifail = 5${\mathbf{ifail}}=5$
This indicates a failure in nag_linsys_real_posdef_solve_1rhs (f04as) which is used to solve the equations giving estimates of the backforecasts.
ifail = 6${\mathbf{ifail}}=6$
On entry, valid values were not supplied for all parameter types in the model. Inspect array isf for further information on the parameter type(s) in error.
ifail = 7${\mathbf{ifail}}=7$
 On entry, ifv < max (1,nfv)${\mathbf{ifv}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nfv}}\right)$.

## Accuracy

The computations are believed to be stable.

The time taken by nag_tsa_uni_arima_forcecast (g13aj) is approximately proportional to n$n$ and the square of the number of backforecasts derived.

## Example

```function nag_tsa_uni_arima_forcecast_example
mr = [int64(1);1;2;0;0;0;0];
par = [-0.0547;
-0.5568;
-0.6636];
c = 9.9807;
kfc = int64(1);
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];
ist = int64(4);
nfv = int64(5);
ifv = int64(5);
[rms, st, nst, fva, fsd, isf, ifail] = ...
nag_tsa_uni_arima_forcecast(mr, par, c, kfc, x, ist, nfv, ifv)
```
```

rms =

375.9146

st =

64.0000
-30.9807
-20.4495
-2.7212

nst =

4

fva =

60.5899
69.4973
79.5367
89.5142
99.4951

fsd =

19.3885
34.9870
54.2475
67.8676
79.1975

isf =

1
1
0
0

ifail =

0

```
```function g13aj_example
mr = [int64(1);1;2;0;0;0;0];
par = [-0.0547;
-0.5568;
-0.6636];
c = 9.9807;
kfc = int64(1);
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];
ist = int64(4);
nfv = int64(5);
ifv = int64(5);
[rms, st, nst, fva, fsd, isf, ifail] = g13aj(mr, par, c, kfc, x, ist, nfv, ifv)
```
```

rms =

375.9146

st =

64.0000
-30.9807
-20.4495
-2.7212

nst =

4

fva =

60.5899
69.4973
79.5367
89.5142
99.4951

fsd =

19.3885
34.9870
54.2475
67.8676
79.1975

isf =

1
1
0
0

ifail =

0

```