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_forecast_state (g13ah)

## Purpose

nag_tsa_uni_arima_forecast_state (g13ah) produces forecasts of a time series, given a time series model which has already been fitted to the time series using nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af). The original observations are not required, since nag_tsa_uni_arima_forecast_state (g13ah) uses as input either the original state set produced by nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af) or the state set updated by a series of new observations using nag_tsa_uni_arima_update (g13ag). Standard errors of the forecasts are also provided.

## Syntax

[fva, fsd, ifail] = g13ah(st, mr, par, c, rms, nfv, 'nst', nst, 'npar', npar)
[fva, fsd, ifail] = nag_tsa_uni_arima_forecast_state(st, mr, par, c, rms, nfv, 'nst', nst, 'npar', npar)

## Description

The original time series is ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$ and parameters have been fitted to the model of this time series using nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af).
Forecasts of ${x}_{\mathit{t}}$, for $\mathit{t}=n+1,\dots ,n+L$, are calculated in five stages, as follows:
 (i) set ${a}_{t}=0$ for $t=N+1,N+2,\dots ,N+L$, where $N=n-d-\left(D×s\right)$ is the number of differenced values in the series; (ii) calculate the values of ${e}_{\mathit{t}}$, for $\mathit{t}=N+1,\dots ,N+L$, and ${e}_{\mathit{t}}={\varphi }_{1}×{e}_{t-1}+\cdots +{\varphi }_{p}×{e}_{t-p}+{a}_{t}-{\theta }_{1}×{a}_{t-1}-\cdots -{\theta }_{q}×{a}_{t-q}$; (iii) calculate the values of ${w}_{\mathit{t}}$, for $\mathit{t}=N+1,\dots ,N+L$, where ${w}_{t}={\Phi }_{1}×{w}_{t-s}+\cdots +{\Phi }_{P}×{w}_{t-s×P}+{e}_{t}-{\Theta }_{1}×{e}_{t-s}-\cdots -{\Theta }_{Q}×{e}_{t-s×Q}$ and ${w}_{t}$ for $t\le N$ are the first $s×P$ values in the state set, corrected for the constant; (iv) add the constant term $c$ to give the differenced series ${\nabla }^{d}{\nabla }_{s}^{D}{x}_{\mathit{t}}={w}_{\mathit{t}}+c$, for $\mathit{t}=N+1,\dots ,N+L$; (v) the differencing operations are reversed to reconstitute ${x}_{\mathit{t}}$, for $\mathit{t}=n+1,\dots ,n+L$.
The standard errors of these forecasts are given by ${s}_{\mathit{t}}={\left[V×\left({\psi }_{0}^{2}+{\psi }_{1}^{2}+\dots +{\psi }_{\mathit{t}-n-1}^{2}\right)\right]}^{1/2}$, for $\mathit{t}=n+1,\dots ,n+L$, where ${\psi }_{0}=1$, $V$ is the residual variance of ${a}_{t}$, and ${\psi }_{j}$ is the coefficient expressing the dependence of ${x}_{t}$ on ${a}_{t-j}$.
To calculate ${\psi }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,\left(L-1\right)$, the following device is used.
A copy of the state set is initialized to zero throughout and the calculations outlined above for the construction of forecasts are carried out with the settings ${a}_{N+1}=1$, and ${a}_{\mathit{t}}=0$, for $\mathit{t}=N+2,\dots ,N+L$.
The resulting quantities corresponding to the sequence ${x}_{N+1},{x}_{N+2},\dots ,{x}_{N+L}$ are precisely $1$, ${\psi }_{1},{\psi }_{2},\dots ,{\psi }_{L-1}$.
The supplied time series model is used throughout these calculations, with the exception that the constant term $c$ is taken to be zero.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{st}\left({\mathbf{nst}}\right)$ – double array
The state set derived from nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af) originally, or as modified using earlier calls of nag_tsa_uni_arima_update (g13ag).
2:     $\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$.
3:     $\mathrm{par}\left({\mathbf{npar}}\right)$ – double array
The 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 which specify the model and which were output originally by nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af).
4:     $\mathrm{c}$ – double scalar
$c$, the value of the model constant. This will have been output by nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af).
5:     $\mathrm{rms}$ – double scalar
$V$, the residual variance associated with the model.
If nag_tsa_uni_arima_estim_easy (g13af) was used to estimate the model, rms should be set to ${\mathbf{s}}/{\mathbf{ndf}}$, where s and ndf were output by nag_tsa_uni_arima_estim_easy (g13af).
If nag_tsa_uni_arima_estim (g13ae) was used to estimate the model, rms should be set to ${\mathbf{s}}/{\mathbf{icount}}\left(5\right)$, where s and ${\mathbf{icount}}\left(5\right)$ were output by nag_tsa_uni_arima_estim (g13ae).
Constraint: ${\mathbf{rms}}\ge 0.0$.
6:     $\mathrm{nfv}$int64int32nag_int scalar
$L$, the required number of forecasts.
Constraint: ${\mathbf{nfv}}>0$.

### Optional Input Parameters

1:     $\mathrm{nst}$int64int32nag_int scalar
Default: the dimension of the array st.
The number of values in the state set array st.
Constraint: ${\mathbf{nst}}=P×s+D×s+d+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(p,Q×s\right)$. (As returned by nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af)).
2:     $\mathrm{npar}$int64int32nag_int scalar
Default: the dimension of the array par.
The number of $\varphi$, $\theta$, $\Phi$ and $\Theta$ parameters in the model.
Constraint: ${\mathbf{npar}}=p+q+P+Q$.

### Output Parameters

1:     $\mathrm{fva}\left({\mathbf{nfv}}\right)$ – double array
nfv forecast values relating to the original undifferenced series.
2:     $\mathrm{fsd}\left({\mathbf{nfv}}\right)$ – double array
The standard errors associated with each of the nfv forecast values in fva.
3:     $\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 given in Arguments).
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{nst}}\ne P×s+D×s+d+q+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(Q×s,p\right)$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{nfv}}\le 0$.
${\mathbf{ifail}}=4$
 On entry, $\mathit{nwa}<4×{\mathbf{npar}}+3×{\mathbf{nst}}$.
${\mathbf{ifail}}=5$
 On entry, ${\mathbf{rms}}<0.0$.
${\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_forecast_state (g13ah) is approximately proportional to ${\mathbf{nfv}}×{\mathbf{npar}}$.

## Example

The following program is based on the data derived in the example used to illustrate nag_tsa_uni_arima_update (g13ag).
These consist of a set of orders indicating that there are two moving average parameters (one non-seasonal, and one seasonal with periodicity $12$).
The model constant is zero.
The state set contains $26$ values.
In addition the residual mean-square derived when the model was originally fitted is given.
Twelve forecasts and their associated errors are obtained.
```function g13ah_example

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

% state set from g13ae, g13af or g13ag
st = [0.0660;    -0.0513;     0.1715;    -0.0249;     0.0588;
0.1167;     0.1493;     0.0199;    -0.1884;    -0.1289;
-0.1172;     0.1122;     6.0039;     0.0443;    -0.0070;
0.0252;     0.0020;     0.0353;    -0.0460;     0.0374;
0.0151;    -0.0237;     0.0031;     0.0188;     0.0066;
0.0125];

% Orders
mr = [int64(0);1;1;0;1;1;12];

% Parameter estimates
par = [0.327; 0.6262];

% residual variance
rms = 0.0014;

c = 0;
nfv = int64(12);

% Produce forecasts
[fva, fsd, ifail] = g13ah( ...
st, mr, par, c, rms, nfv);

fprintf('The required %4d forecast values are as follows\n', nfv);
for j = 1:8:nfv
fprintf('%8.4f', fva(j:min(j+7,nfv)));
fprintf('\n');
end
fprintf('\nThe standard deviations corresponding to the forecasts are\n');
for j = 1:8:nfv
fprintf('%8.4f', fsd(j:min(j+7,nfv)));
fprintf('\n');
end

```
```g13ah example results

The required   12 forecast values are as follows
6.0381  5.9912  6.1469  6.1207  6.1574  6.3029  6.4288  6.4392
6.2657  6.1348  6.0059  6.1139

The standard deviations corresponding to the forecasts are
0.0374  0.0451  0.0517  0.0575  0.0627  0.0676  0.0721  0.0764
0.0805  0.0843  0.0880  0.0915
```