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 ${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) ${\nabla }^{d}{\nabla }_{s}^{D}{x}_{t}-c={w}_{t}$ 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}$, and $c$ is a constant. (b) ${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$; in the absence of seasonality it reduces to ${w}_{t}={e}_{t}$. (c) ${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$, 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 ${w}_{t}$, for $\left(N-s×P\right)\le t\le N$; (ii) the $\left(d+D×s\right)$ values required to reconstitute the original series ${x}_{t}$ from the differenced series ${w}_{t}$; (iii) the intermediate series ${e}_{t}$, for $N-\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right); (iv) the residual series ${a}_{t}$, for $\left(N-q\right), where $N=n-\left(d+D×s\right)$.
(b) A set of $L$ forecasts of ${x}_{t}$ and their estimated standard errors, ${s}_{t}$, for $\mathit{t}=n+1,\dots ,n+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:     $\mathrm{mr}\left(7\right)$int64int32nag_int array
The orders vector $\left(p,d,q,P,D,Q,s\right)$ of the ARIMA model, in the usual notation.
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:     $\mathrm{par}\left({\mathbf{npar}}\right)$ – double array
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.
3:     $\mathrm{c}$ – double scalar
$c$, the expected value of the differenced series (i.e., $c$ is the constant correction). Where there is no constant term, c must be set to $0.0$.
4:     $\mathrm{kfc}$int64int32nag_int scalar
Must be set to $0$ if c was not estimated, and $1$ if c was estimated. This is irrespective of whether or not ${\mathbf{c}}=0.0$. The only effect is that the residual degrees of freedom are one greater when ${\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: ${\mathbf{kfc}}=0$ or $1$.
5:     $\mathrm{x}\left({\mathbf{nx}}\right)$ – double array
The $n$ values of the original undifferenced time series.
6:     $\mathrm{ist}$int64int32nag_int scalar
The dimension of the array st.
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)$. The expression on the right-hand side of the inequality is returned in nst.
7:     $\mathrm{nfv}$int64int32nag_int scalar
The required number of forecasts. If ${\mathbf{nfv}}\le 0$, no forecasts will be computed.
8:     $\mathrm{ifv}$int64int32nag_int scalar
The dimension of the arrays fva and fsd.
Constraint: ${\mathbf{ifv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nfv}}\right)$.

### Optional Input Parameters

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

### Output Parameters

1:     $\mathrm{rms}$ – double scalar
The residual variance (mean square) associated with the model.
2:     $\mathrm{st}\left({\mathbf{ist}}\right)$ – double array
The nst values of the state set.
3:     $\mathrm{nst}$int64int32nag_int scalar
The number of values in the state set array st.
4:     $\mathrm{fva}\left({\mathbf{ifv}}\right)$ – double array
If ${\mathbf{nfv}}>0$, fva contains the nfv forecast values relating to the original undifferenced time series.
5:     $\mathrm{fsd}\left({\mathbf{ifv}}\right)$ – double array
If ${\mathbf{nfv}}>0$, fsd contains the estimated standard errors of the nfv forecast values.
6:     $\mathrm{isf}\left(4\right)$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$ On entry the set of parameter values of this type does not satisfy the stationarity or invertibility test conditions. $\phantom{-}0$ No parameter of this type is in the model. $\phantom{-}1$ Valid parameter values of this type have been supplied.
7:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{npar}}\ne p+q+P+Q$, or the orders vector mr is invalid (check the constraints in Arguments), or ${\mathbf{kfc}}\ne 0$ or $1$.
${\mathbf{ifail}}=2$
On entry, ${\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.
${\mathbf{ifail}}=3$
On entry, the workspace array w is too small.
${\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.
${\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.
${\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.
${\mathbf{ifail}}=7$
 On entry, ${\mathbf{ifv}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nfv}}\right)$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The computations are believed to be stable.

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

## Example

The data is that used in the example program for nag_tsa_uni_arima_estim_easy (g13af). Five forecast values and their standard errors, together with the state set, are computed and printed.
```function g13aj_example

fprintf('g13aj example results\n\n');

% orders
mr  = [int64(1);  1;  2;  0;  0;  0;  0];
% Parameter estimates
par = [-0.0547;     -0.5568;     -0.6636];

% data
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];

% From mr ...
ist = int64(4);

% Problem sizes
kfc = int64(1);
nfv = int64(5);
ifv = int64(nfv);
c   = 9.9807;

% Apply ARIMA model
[rms, st, nst, fva, fsd, isf, ifail] = ...
g13aj( ...
mr, par, c, kfc, x, ist, nfv, ifv);

%   Display results
fprintf('The residual mean square is %9.2f\n\n', rms);
fprintf('The state set consists of %4d values\n', nst);
for j = 1:6:nst
fprintf('%11.4f', st(j:min(j+5,nst)));
fprintf('\n');
end
fprintf('\nThe %4d forecast values and standard errors are -\n', nfv);
fprintf('%10.2f%10.2f\n', [fva fsd]');

```
```g13aj example results

The residual mean square is    375.91

The state set consists of    4 values
64.0000   -30.9807   -20.4495    -2.7212

The    5 forecast values and standard errors are -
60.59     19.39
69.50     34.99
79.54     54.25
89.51     67.87
99.50     79.20
```