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 xt${x}_{\mathit{t}}$, for t = 1,2,,n$\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 xt${x}_{\mathit{t}}$, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$, are calculated in five stages, as follows:
 (i) set at = 0${a}_{t}=0$ for t = N + 1,N + 2, … ,N + L$t=N+1,N+2,\dots ,N+L$, where N = n − d − (D × s)$N=n-d-\left(D×s\right)$ is the number of differenced values in the series; (ii) calculate the values of et${e}_{\mathit{t}}$, for t = N + 1, … ,N + L$\mathit{t}=N+1,\dots ,N+L$, and et = φ1 × et − 1 + ⋯ + φp × et − p + at − θ1 × at − 1 − ⋯ − θq × at − q${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 wt${w}_{\mathit{t}}$, for t = N + 1, … ,N + L$\mathit{t}=N+1,\dots ,N+L$, where wt = Φ1 × wt − s + ⋯ + ΦP × wt − s × P + et − Θ1 × et − s − ⋯ − ΘQ × et − s × Q${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 wt${w}_{t}$ for t ≤ N$t\le N$ are the first s × P$s×P$ values in the state set, corrected for the constant; (iv) add the constant term c$c$ to give the differenced series ∇d∇sDxt = wt + c${\nabla }^{d}{\nabla }_{s}^{D}{x}_{\mathit{t}}={w}_{\mathit{t}}+c$, for t = N + 1, … ,N + L$\mathit{t}=N+1,\dots ,N+L$; (v) the differencing operations are reversed to reconstitute xt${x}_{\mathit{t}}$, for t = n + 1, … ,n + L$\mathit{t}=n+1,\dots ,n+L$.
The standard errors of these forecasts are given by st = [ V × (ψ02 + ψ12 + + ψtn12) ]1 / 2 ${s}_{\mathit{t}}={\left[V×\left({\psi }_{0}^{2}+{\psi }_{1}^{2}+\dots +{\psi }_{\mathit{t}-n-1}^{2}\right)\right]}^{1/2}$, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$, where ψ0 = 1${\psi }_{0}=1$, V$V$ is the residual variance of at${a}_{t}$, and ψj${\psi }_{j}$ is the coefficient expressing the dependence of xt${x}_{t}$ on atj${a}_{t-j}$.
To calculate ψj${\psi }_{\mathit{j}}$, for j = 1,2,,(L1)$\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 aN + 1 = 1${a}_{N+1}=1$, and at = 0${a}_{\mathit{t}}=0$, for t = N + 2,,N + L$\mathit{t}=N+2,\dots ,N+L$.
The resulting quantities corresponding to the sequence xN + 1,xN + 2,,xN + L${x}_{N+1},{x}_{N+2},\dots ,{x}_{N+L}$ are precisely 1$1$, ψ1,ψ2,,ψL1${\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$c$ is taken to be zero.

None.

## Parameters

### Compulsory Input Parameters

1:     st(nst) – double array
nst, the dimension of the array, must satisfy the constraint nst = P × s + D × s + d + q + max (p,Q × s)${\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)).
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:     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$.
3:     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 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 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:     c – double scalar
c$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:     rms – double scalar
V$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 s / ndf${\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 s / icount(5)${\mathbf{s}}/{\mathbf{icount}}\left(5\right)$, where s and icount(5)${\mathbf{icount}}\left(5\right)$ were output by nag_tsa_uni_arima_estim (g13ae).
Constraint: rms0.0${\mathbf{rms}}\ge 0.0$.
6:     nfv – int64int32nag_int scalar
L$L$, the required number of forecasts.
Constraint: nfv > 0${\mathbf{nfv}}>0$.

### Optional Input Parameters

1:     nst – int64int32nag_int scalar
Default: The dimension of the array st.
The number of values in the state set array st.
Constraint: nst = P × s + D × s + d + q + max (p,Q × s)${\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:     npar – int64int32nag_int scalar
Default: The dimension of the array par.
The number of φ$\varphi$, θ$\theta$, Φ$\Phi$ and Θ$\Theta$ parameters in the model.
Constraint: npar = p + q + P + Q${\mathbf{npar}}=p+q+P+Q$.

wa nwa

### Output Parameters

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

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

```function nag_tsa_uni_arima_forecast_state_example
st = [0.066;
-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.007;
0.0252;
0.002;
0.0353;
-0.046;
0.0374;
0.0151;
-0.0237;
0.0031;
0.0188;
0.0066;
0.0125];
mr = [int64(0);1;1;0;1;1;12];
par = [0.327;
0.6262];
c = 0;
rms = 0.0014;
nfv = int64(12);
[fva, fsd, ifail] = nag_tsa_uni_arima_forecast_state(st, mr, par, c, rms, nfv)
```
```

fva =

6.0381
5.9912
6.1469
6.1207
6.1574
6.3029
6.4288
6.4392
6.2657
6.1348
6.0059
6.1139

fsd =

0.0374
0.0451
0.0517
0.0575
0.0627
0.0676
0.0721
0.0764
0.0805
0.0843
0.0880
0.0915

ifail =

0

```
```function g13ah_example
st = [0.066;
-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.007;
0.0252;
0.002;
0.0353;
-0.046;
0.0374;
0.0151;
-0.0237;
0.0031;
0.0188;
0.0066;
0.0125];
mr = [int64(0);1;1;0;1;1;12];
par = [0.327;
0.6262];
c = 0;
rms = 0.0014;
nfv = int64(12);
[fva, fsd, ifail] = g13ah(st, mr, par, c, rms, nfv)
```
```

fva =

6.0381
5.9912
6.1469
6.1207
6.1574
6.3029
6.4288
6.4392
6.2657
6.1348
6.0059
6.1139

fsd =

0.0374
0.0451
0.0517
0.0575
0.0627
0.0676
0.0721
0.0764
0.0805
0.0843
0.0880
0.0915

ifail =

0

```