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_multi_inputmod_forecast_state (g13bh)

## Purpose

nag_tsa_multi_inputmod_forecast_state (g13bh) produces forecasts of a time series (the output series) which depends on one or more other (input) series via a multi-input model which will usually have been fitted using nag_tsa_multi_inputmod_estim (g13be). The future values of the input series must be supplied. The original observations are not required. nag_tsa_multi_inputmod_forecast_state (g13bh) uses as input either the original state set obtained from nag_tsa_multi_inputmod_estim (g13be), or the state set updated by a series of new observations from nag_tsa_multi_inputmod_update (g13bg). Standard errors of the forecasts are produced. If future values of some of the input series have been obtained as forecasts using ARIMA models for those series, this may be allowed for in the calculation of the standard errors.

## Syntax

[xxyn, mrx, fva, fsd, ifail] = g13bh(sttf, mr, mt, para, xxyn, mrx, parx, rmsxy, kzef, 'nsttf', nsttf, 'nser', nser, 'npara', npara, 'nfv', nfv)
[xxyn, mrx, fva, fsd, ifail] = nag_tsa_multi_inputmod_forecast_state(sttf, mr, mt, para, xxyn, mrx, parx, rmsxy, kzef, 'nsttf', nsttf, 'nser', nser, 'npara', npara, 'nfv', nfv)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: nfv has been made optional
.

## Description

The forecasts of the output series yt${y}_{\mathit{t}}$ are calculated, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$, where n$n$ is the latest time point of the observations used to produce the state set and L$L$ is the maximum lead time of the forecasts.
First the new input series values xt${x}_{t}$ are used to form the input components zt${z}_{\mathit{t}}$, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$, using the transfer function models:
 (a) zt = δ1zt − 1 + δ2zt − 2 + ⋯ + δpzt − p + ω0xt − b − ω1xt − b − 1 − ⋯ − ωqxt − b − q${z}_{t}={\delta }_{1}{z}_{t-1}+{\delta }_{2}{z}_{t-2}+\cdots +{\delta }_{p}{z}_{t-p}+{\omega }_{0}{x}_{t-b}-{\omega }_{1}{x}_{t-b-1}-\cdots -{\omega }_{q}{x}_{t-b-q}$.
The output noise component nt${n}_{\mathit{t}}$ is then forecast by setting at = 0${a}_{\mathit{t}}=0$, for t = n + 1,,n + L$\mathit{t}=n+1,\dots ,n+L$, and using the ARIMA model equations:
 (b) et = φ1et − 1 + φ2et − 2 + ⋯ + φpet − p + at − θ1at − 1 − θ2at − 2 − ⋯ − θ1at − 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 }_{1}{a}_{t-q}$ (c) 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}$ (d) nt = (∇d∇sD) − 1(wt + c)${n}_{t}={\left({\nabla }^{d}{\nabla }_{s}^{D}\right)}^{-1}\left({w}_{t}+c\right)$.
This last step of ‘integration’ reverses the process of differencing. Finally the output forecasts are calculated as
 yt = z1,t + z2,t + ⋯ + zm,t + nt. $yt=z1,t+z2,t+⋯+zm,t+nt.$
The forecast error variance of yt + l${y}_{t+l}$ (i.e., at lead time l$l$) is Sl2${S}_{l}^{2}$, which is the sum of parts which arise from the various input series, and the output noise component. That part due to the output noise is
 snl2 = Vn × (ψ02 + ψ12 + ⋯ + ψl − 12), $snl2=Vn×(ψ02+ψ12+⋯+ψl-12),$
where Vn${V}_{n}$ is the estimated residual variance of the output noise ARIMA model, and ψ0,ψ1,${\psi }_{0},{\psi }_{1},\dots \text{}$ are the ‘psi-weights’ of this model as defined in Box and Jenkins (1976). They are calculated by applying the equations (b), (c) and (d) above, for t = 0,1,,L$t=0,1,\dots ,L$, but with artificial values for the various series and with the constant c$c$ set to 0$0$. Thus all values of at${a}_{t}$, et${e}_{t}$, wt${w}_{t}$ and nt${n}_{t}$ are taken as zero, for t < 0$t<0$; at${a}_{t}$ is taken to be 1$1$, for t = 0$t=0$ and 0$0$, for t > 0$t>0$. The resulting values of nt${n}_{\mathit{t}}$, for t = 0,1,,L$\mathit{t}=0,1,\dots ,L$, are precisely ψ0,ψ1,,ψL${\psi }_{0},{\psi }_{1},\dots ,{\psi }_{L}$ as required.
Further contributions to Sl2${S}_{l}^{2}$ come only from those input series, for which future values are forecasts which have been obtained by applying input series ARIMA models. For such a series the contribution is
 szl2 = Vx × (ν02 + ν12 + ⋯ + νl − 12), $szl2=Vx×(ν02+ν12+⋯+νl-12),$
where Vx${V}_{x}$ is the estimated residual variance of the input series ARIMA model. The coefficients ν0,ν1,${\nu }_{0},{\nu }_{1},\dots \text{}$ are calculated by applying the transfer function model equation (a) above, for t = 0,1,,L$t=0,1,\dots ,L$, but again with artificial values of the series. Thus all values of zt${z}_{t}$ and xt${x}_{t}$, for t < 0$t<0$, are taken to be zero, and x0,x1,${x}_{0},{x}_{1},\dots \text{}$ are taken to be the psi-weight sequence ψ0,ψ1,${\psi }_{0},{\psi }_{1},\dots \text{}$ for the input series ARIMA model. The resulting values of zt${z}_{\mathit{t}}$, for t = 0,1,,L$\mathit{t}=0,1,\dots ,L$, are precisely ν0,ν1,,νL${\nu }_{0},{\nu }_{1},\dots ,{\nu }_{L}$ as required.
In adding such contributions szl2$s{z}_{l}^{2}$ to snl2$s{n}_{l}^{2}$ to make up the total forecast error variance Sl2${S}_{l}^{2}$, it is assumed that the various input series with which these contributions are associated are statistically independent of each other.
When using the function in practice an ARIMA model is required for all the input series. In the case of those inputs for which no such ARIMA model is available (or its effects are to be excluded), the corresponding orders and parameters and the estimated residual variance should be set to zero.

## 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:     sttf(nsttf) – double array
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 for the output noise component.
p$p$, q$q$, P$P$ and Q$Q$ give respectively the number of autoregressive (φ)$\left(\varphi \right)$, moving average (θ)$\left(\theta \right)$, seasonal autoregressive (Φ)$\left(\Phi \right)$ and seasonal moving average (Θ)$\left(\Theta \right)$ 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$.
3:     mt(4$4$,nser) – int64int32nag_int array
The transfer function orders b$b$, p$p$ and q$q$ of each of the input series. The data for input series i$i$ are held in column i$i$. Row 1 holds the value bi${b}_{i}$, row 2 holds the value qi${q}_{i}$ and row 3 holds the value pi${p}_{i}$. For a simple input, bi = qi = pi = 0${b}_{i}={q}_{i}={p}_{i}=0$.
Row 4 holds the value ri${r}_{i}$, where ri = 1${r}_{i}=1$ for a simple input, ri = 2​ or ​3${r}_{i}=2\text{​ or ​}3$ for a transfer function input. When ri = 1${r}_{i}=1$, any nonzero contents of rows 1, 2 and 3 of column i$i$ are ignored. The choice of ri = 2${r}_{i}=2$ or ri = 3${r}_{i}=3$ is an option for use in model estimation and does not affect the operation of nag_tsa_multi_inputmod_forecast_state (g13bh).
Constraint: mt(4,i) = 1${\mathbf{mt}}\left(4,\mathit{i}\right)=1$, 2$2$ or 3$3$, for i = 1,2,,nser1$\mathit{i}=1,2,\dots ,{\mathbf{nser}}-1$.
4:     para(npara) – double array
Estimates of the multi-input model parameters as returned by nag_tsa_multi_inputmod_estim (g13be). These are in order, firstly the ARIMA model parameters: p$p$ values of φ$\varphi$ parameters, q$q$ values of θ$\theta$ parameters, P$P$ values of Φ$\Phi$ parameters and Q$Q$ values of Θ$\Theta$ parameters. These are followed by the transfer function model parameter values ω0,ω1,,ωq1${\omega }_{0},{\omega }_{1},\dots ,{\omega }_{{q}_{1}}$, δ1,δ2,,δp1${\delta }_{1},{\delta }_{2},\dots ,{\delta }_{{p}_{1}}$ for the first of any input series and similar sets of values for any subsequent input series. The final component of para is the constant c$c$.
5:     xxyn(ldxxyn,nser) – double array
ldxxyn, the first dimension of the array, must satisfy the constraint ldxxynnfv$\mathit{ldxxyn}\ge {\mathbf{nfv}}$.
The supplied nfv values for each of the input series required to produce the nfv output series forecasts. Column i$i$ contains the values for input series i$i$. Column nser need not be supplied.
6:     mrx(7$7$,nser) – int64int32nag_int array
The orders array for each of the input series ARIMA models. Thus, column i$i$ contains values of p$p$, d$d$, q$q$, P$P$, D$D$, Q$Q$, s$s$ for input series i$i$. In the case of those inputs for which no ARIMA model is available, the corresponding orders should be set to 0$0$. (The model for any input series only affects the standard errors of the forecast values.)
7:     parx(ldparx,nser) – double array
ldparx, the first dimension of the array, must satisfy the constraint ldparxncd$\mathit{ldparx}\ge \mathit{ncd}$, where ncd$\mathit{ncd}$ is the maximum number of parameters in any of the input series ARIMA models. If there are no input series, ldparx1$\mathit{ldparx}\ge 1$.
Values of the parameters (φ$\varphi$, θ$\theta$, Φ$\Phi$ and Θ$\Theta$) for each of the input series ARIMA models. Thus column i$i$ contains mrx(1,i)${\mathbf{mrx}}\left(1,i\right)$ values of φ$\varphi$ parameters, mrx(3,i)${\mathbf{mrx}}\left(3,i\right)$ values of θ$\theta$ parameters, mrx(4,i)${\mathbf{mrx}}\left(4,i\right)$ values of Φ$\Phi$ parameters and mrx(6,i)${\mathbf{mrx}}\left(6,i\right)$ values of Θ$\Theta$ parameters – in that order.
Values in the columns relating to those input series for which no ARIMA model is available are ignored. (The model for any input series only affects the standard errors of the forecast values.)
8:     rmsxy(nser) – double array
The estimated residual variances for each input series ARIMA model followed by that for the output noise ARIMA model. In the case of those inputs for which no ARIMA model is available, or when its effects are to be excluded in the calculation of forecast standard errors, the corresponding entry of rmsxy should be set to 0$0$.
9:     kzef – int64int32nag_int scalar
Must not be set to 0$0$, if the values of the input component series zt${z}_{t}$ and the values of the output noise component nt${n}_{t}$ are to overwrite the contents of xxyn on exit, and must be set to 0$0$ if xxyn is to remain unchanged on exit, apart from the appearance of the forecast values in column nser.

### Optional Input Parameters

1:     nsttf – int64int32nag_int scalar
Default: The dimension of the array sttf.
The exact number of values in the state set array sttf as returned by nag_tsa_multi_inputmod_estim (g13be) or nag_tsa_multi_inputmod_update (g13bg).
2:     nser – int64int32nag_int scalar
Default: The dimension of the arrays mt, rmsxy and the second dimension of the arrays xxyn, parx. (An error is raised if these dimensions are not equal.)
The total number of input and output series. There may be any number of input series (including none), but only one output series.
3:     npara – int64int32nag_int scalar
Default: The dimension of the array para.
The exact number of φ$\varphi$, θ$\theta$, Φ$\Phi$, Θ$\Theta$, ω$\omega$, δ$\delta$ and c$c$ parameters. (c$c$ must be included, whether its value was previously estimated or was set fixed).
4:     nfv – int64int32nag_int scalar
Default: The first dimension of the array xxyn.
The number of forecast values required.

### Input Parameters Omitted from the MATLAB Interface

ldxxyn ldparx wa iwa

### Output Parameters

1:     xxyn(ldxxyn,nser) – double array
ldxxynnfv$\mathit{ldxxyn}\ge {\mathbf{nfv}}$.
If kzef = 0${\mathbf{kzef}}=0$, then column nser of xxyn contains the output series forecast values (as does fva), but xxyn is otherwise unchanged.
If kzef0${\mathbf{kzef}}\ne 0$, then the columns of xxyn hold the corresponding values of the forecast components zt${z}_{t}$ for each of the input series and the values of the output noise component nt${n}_{t}$ in that order.
2:     mrx(7$7$,nser) – int64int32nag_int array
Unchanged, apart from column nser which is used for workspace.
3:     fva(nfv) – double array
The required forecast values for the output series.
4:     fsd(nfv) – double array
The standard errors for each of the forecast values.
5:     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, nsttf is not consistent with the orders in arrays mr and mt.
ifail = 2${\mathbf{ifail}}=2$
 On entry, npara is not consistent with the orders in arrays mr and mt.
ifail = 3${\mathbf{ifail}}=3$
 On entry, ldxxyn is too small.
ifail = 4${\mathbf{ifail}}=4$
 On entry, iwa is too small.
ifail = 5${\mathbf{ifail}}=5$
 On entry, ldparx is too small.
ifail = 6${\mathbf{ifail}}=6$
On entry, one of the ri${r}_{i}$, stored in mt(4,i)${\mathbf{mt}}\left(4,\mathit{i}\right)$, for i = 1,2,,nser1$\mathit{i}=1,2,\dots ,{\mathbf{nser}}-1$, does not equal 1$1$, 2$2$ or 3$3$.

## Accuracy

The computations are believed to be stable.

The time taken by nag_tsa_multi_inputmod_forecast_state (g13bh) is approximately proportional to ${\mathbf{nfv}}×{\mathbf{npara}}$.

## Example

```function nag_tsa_multi_inputmod_forecast_state_example
sttf = [6.716; 158.3022; -80.3352; -74.8937; -80.7694; -70.3022; 0.8476; -2.0234; -5.808; 10.2943];
mr = [int64(1);0;0;0;1;1;4];
mt = [int64(1),0; ...
0,0; ...
1,0; ...
3,0];
para = [0.5158; 0.9994; 8.6343; 0.6726; -0.3172];
xxyn = [6.923, 0; 6.939, 0; 6.705, 0; 6.914, 0];
mrx = [int64(2),0; ...
0,0; ...
2,0; ...
0,0; ...
1,0; ...
1,0; ...
4,0];
parx = [1.6743, 0; -0.9505, 0; 1.4605, 0; -0.4862, 0; 0.8993, 0];
rmsxy = [0.172; 22.9256];
kzef = int64(1);
[xxynOut, mrxOut, fva, fsd, ifail] = ...
nag_tsa_multi_inputmod_forecast_state(sttf, mr, mt, para, xxyn, mrx, parx, rmsxy, kzef)
```
```

xxynOut =

164.4620  -76.1897
170.3924  -70.4499
174.5193  -73.8694
175.2747  -80.1789

mrxOut =

2                    1
0                    0
2                    0
0                    0
1                    1
1                    1
4                    4

fva =

88.2723
99.9425
100.6499
95.0958

fsd =

4.7881
6.4690
7.3175
7.5534

ifail =

0

```
```function g13bh_example
sttf = [6.716; 158.3022; -80.3352; -74.8937; -80.7694; -70.3022; 0.8476; -2.0234; -5.808; 10.2943];
mr = [int64(1);0;0;0;1;1;4];
mt = [int64(1),0; ...
0,0; ...
1,0; ...
3,0];
para = [0.5158; 0.9994; 8.6343; 0.6726; -0.3172];
xxyn = [6.923, 0; 6.939, 0; 6.705, 0; 6.914, 0];
mrx = [int64(2),0; ...
0,0; ...
2,0; ...
0,0; ...
1,0; ...
1,0; ...
4,0];
parx = [1.6743, 0; -0.9505, 0; 1.4605, 0; -0.4862, 0; 0.8993, 0];
rmsxy = [0.172; 22.9256];
kzef = int64(1);
[xxynOut, mrxOut, fva, fsd, ifail] = ...
g13bh(sttf, mr, mt, para, xxyn, mrx, parx, rmsxy, kzef)
```
```

xxynOut =

164.4620  -76.1897
170.3924  -70.4499
174.5193  -73.8694
175.2747  -80.1789

mrxOut =

2                    1
0                    0
2                    0
0                    0
1                    1
1                    1
4                    4

fva =

88.2723
99.9425
100.6499
95.0958

fsd =

4.7881
6.4690
7.3175
7.5534

ifail =

0

```