NAG Library Routine Document
G13DKF
1 Purpose
G13DKF accepts a sequence of new observations in a multivariate time series and updates both the forecasts and the standard deviations of the forecast errors. A call to
G13DJF must be made prior to calling this routine in order to calculate the elements of a reference vector together with a set of forecasts and their standard errors. On a successful exit from G13DKF the reference vector is updated so that should future series values become available these forecasts may be updated by recalling G13DKF.
2 Specification
SUBROUTINE G13DKF ( 
K, LMAX, M, MLAST, Z, KMAX, REF, LREF, V, PREDZ, SEFZ, WORK, IFAIL) 
INTEGER 
K, LMAX, M, MLAST, KMAX, LREF, IFAIL 
REAL (KIND=nag_wp) 
Z(KMAX,M), REF(LREF), V(KMAX,M), PREDZ(KMAX,LMAX), SEFZ(KMAX,LMAX), WORK(K*M) 

3 Description
Let
${Z}_{\mathit{t}}={\left({z}_{1\mathit{t}},{z}_{2\mathit{t}},\dots ,{z}_{k\mathit{t}}\right)}^{\mathrm{T}}$, for
$\mathit{t}=1,2,\dots ,n$, denote a
$k$dimensional time series for which forecasts of
${\hat{Z}}_{n+1},{\hat{Z}}_{n+2},\dots ,{\hat{Z}}_{n+{l}_{\mathrm{max}}}$ have been computed using
G13DJF. Given
$m$ further observations
${Z}_{n+1},{Z}_{n+2},\dots ,{Z}_{n+m}$, where
$m<{l}_{\mathrm{max}}$, G13DKF updates the forecasts of
${Z}_{n+m+1},{Z}_{n+m+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ and their corresponding standard errors.
G13DKF uses a multivariate version of the procedure described in
Box and Jenkins (1976). The forecasts are updated using the
$\psi $ weights, computed in
G13DJF. If
${Z}_{t}^{*}$ denotes the transformed value of
${Z}_{t}$ and
${\hat{Z}}_{t}^{*}\left(l\right)$ denotes the forecast of
${Z}_{t+l}^{*}$ from time
$t$ with a lead of
$l$ (that is the forecast of
${Z}_{t+l}^{*}$ given observations
${Z}_{t}^{*},{Z}_{t1}^{*},\dots \text{}$), then
and
where
$\tau $ is a constant vector of length
$k$ involving the differencing parameters and the mean vector
$\mu $. By subtraction we obtain
Estimates of the residuals corresponding to the new observations are also computed as
${\epsilon}_{n+\mathit{l}}={Z}_{n+\mathit{l}}^{*}{\hat{Z}}_{n}^{*}\left(\mathit{l}\right)$, for
$\mathit{l}=1,2,\dots ,m$. These may be of use in checking that the new observations conform to the previously fitted model.
On a successful exit, the reference array is updated so that G13DKF may be called again should future series values become available, see
Section 8.
When a transformation has been used the forecasts and their standard errors are suitably modified to give results in terms of the original series
${Z}_{t}$; see
Granger and Newbold (1976).
4 References
Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Granger C W J and Newbold P (1976) Forecasting transformed series J. Roy. Statist. Soc. Ser. B 38 189–203
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley
5 Parameters
The quantities
K,
LMAX,
KMAX,
REF and
LREF from
G13DJF
are suitable for input to G13DKF.
 1: K – INTEGERInput
On entry: $k$, the dimension of the multivariate time series.
Constraint:
${\mathbf{K}}\ge 1$.
 2: LMAX – INTEGERInput
On entry: the number,
${l}_{\mathrm{max}}$, of forecasts requested in the call to
G13DJF.
Constraint:
${\mathbf{LMAX}}\ge 2$.
 3: M – INTEGERInput
On entry:
$m$, the number of new observations available since the last call to either
G13DJF or G13DKF. The number of new observations since the last call to
G13DJF is then
${\mathbf{M}}+{\mathbf{MLAST}}$.
Constraint:
$0<{\mathbf{M}}<{\mathbf{LMAX}}{\mathbf{MLAST}}$.
 4: MLAST – INTEGERInput/Output
On entry: on the first call to G13DKF, since calling
G13DJF,
MLAST must be set to
$0$ to indicate that no new observations have yet been used to update the forecasts; on subsequent calls
MLAST must contain the value of
MLAST as output on the previous call to G13DKF.
On exit: is incremented by
$m$ to indicate that
${\mathbf{MLAST}}+{\mathbf{M}}$ observations have now been used to update the forecasts since the last call to
G13DJF.
MLAST must not be changed between calls to G13DKF, unless a call to
G13DJF has been made between the calls in which case
MLAST should be reset to
$0$.
Constraint:
$0\le {\mathbf{MLAST}}<{\mathbf{LMAX}}{\mathbf{M}}$.
 5: Z(KMAX,M) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{Z}}\left(\mathit{i},\mathit{j}\right)$ must contain the value of
${z}_{\mathit{i},n+{\mathbf{MLAST}}+\mathit{j}}$, for
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{j}=1,2,\dots ,m$, and where
$n$ is the number of observations in the time series in the last call made to
G13DJF.
Constraint:
if the transformation defined in
TR in
G13DJF for the
$\mathit{i}$th series is the log transformation, then
${\mathbf{Z}}\left(\mathit{i},\mathit{j}\right)>0.0$, and if it is the squareroot transformation, then
${\mathbf{Z}}\left(\mathit{i},\mathit{j}\right)\ge 0.0$, for
$\mathit{j}=1,2,\dots ,m$ and
$\mathit{i}=1,2,\dots ,k$.
 6: KMAX – INTEGERInput
On entry: the first dimension of the arrays
Z,
PREDZ,
SEFZ and
V as declared in the (sub)program from which G13DKF is called.
Constraint:
${\mathbf{KMAX}}\ge {\mathbf{K}}$.
 7: REF(LREF) – REAL (KIND=nag_wp) arrayInput/Output
On entry: must contain the first
$\left({\mathbf{LMAX}}1\right)\times {\mathbf{K}}\times {\mathbf{K}}+2\times {\mathbf{K}}\times {\mathbf{LMAX}}+{\mathbf{K}}$ elements of the reference vector as returned on a successful exit from
G13DJF (or a previous call to G13DKF).
On exit: the elements of
REF are updated. The first
$\left({\mathbf{LMAX}}1\right)\times {\mathbf{K}}\times {\mathbf{K}}$ elements store the
$\psi $ weights
${\psi}_{1},{\psi}_{2},\dots ,{\psi}_{{l}_{\mathrm{max}}1}$. The next
${\mathbf{K}}\times {\mathbf{LMAX}}$ elements contain the forecasts of the transformed series and the next
${\mathbf{K}}\times {\mathbf{LMAX}}$ elements contain the variances of the forecasts of the transformed variables; see
G13DJF. The last
K elements are not updated.
 8: LREF – INTEGERInput
On entry: the dimension of the array
REF as declared in the (sub)program from which G13DKF is called.
Constraint:
${\mathbf{LREF}}\ge \left({\mathbf{LMAX}}1\right)\times {\mathbf{K}}\times {\mathbf{K}}+2\times {\mathbf{K}}\times {\mathbf{LMAX}}+{\mathbf{K}}$.
 9: V(KMAX,M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{V}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the $\mathit{i}$th component of ${\epsilon}_{n+{\mathbf{MLAST}}+\mathit{j}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,m$.
 10: PREDZ(KMAX,LMAX) – REAL (KIND=nag_wp) arrayInput/Output
On entry: nonupdated values are kept intact.
On exit:
${\mathbf{PREDZ}}\left(\mathit{i},\mathit{j}\right)$ contains the updated forecast of
${z}_{\mathit{i},n+\mathit{j}}$, for
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{j}={\mathbf{MLAST}}+{\mathbf{M}}+1,\dots ,{l}_{\mathrm{max}}$.
The columns of
PREDZ corresponding to the new observations since the last call to either
G13DJF or G13DKF are set equal to the corresponding columns of
Z.
 11: SEFZ(KMAX,LMAX) – REAL (KIND=nag_wp) arrayInput/Output
On entry: nonupdated values are kept intact.
On exit:
${\mathbf{SEFZ}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the standard error of the corresponding element of
PREDZ, for
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{j}={\mathbf{MLAST}}+{\mathbf{M}}+1,\dots ,{l}_{\mathrm{max}}$.
The columns of
SEFZ corresponding to the new observations since the last call to either
G13DJF or G13DKF are set equal to zero.
 12: WORK(${\mathbf{K}}\times {\mathbf{M}}$) – REAL (KIND=nag_wp) arrayWorkspace
 13: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$
On entry,  ${\mathbf{K}}<1$, 
or  ${\mathbf{LMAX}}<2$, 
or  ${\mathbf{M}}\le 0$, 
or  ${\mathbf{MLAST}}+{\mathbf{M}}\ge {\mathbf{LMAX}}$, 
or  ${\mathbf{MLAST}}<0$, 
or  ${\mathbf{KMAX}}<{\mathbf{K}}$, 
or  ${\mathbf{LREF}}<\left({\mathbf{LMAX}}1\right)\times {\mathbf{K}}\times {\mathbf{K}}+2\times {\mathbf{K}}\times {\mathbf{LMAX}}+{\mathbf{K}}$. 
 ${\mathbf{IFAIL}}=2$
On entry, some of the elements of the reference vector,
REF, have been corrupted since the most recent call to
G13DJF (or G13DKF).
 ${\mathbf{IFAIL}}=3$
On entry, one or more of the elements of
Z is invalid, for the transformation being used; that is you may be trying to log or square root a series, some of whose values are negative.
 ${\mathbf{IFAIL}}=4$
This is an unlikely exit. For one of the series, overflow will occur if the forecasts are updated. You should check whether the elements of
REF have been corrupted.
7 Accuracy
The matrix computations are believed to be stable.
If a further
${m}^{*}$ observations,
${Z}_{n+{\mathbf{MLAST}}+1},{Z}_{n+{\mathbf{MLAST}}+2},\dots ,{Z}_{n+{\mathbf{MLAST}}+{m}^{*}}$, become available, then forecasts of
${Z}_{n+{\mathbf{MLAST}}+{m}^{*}+1},{Z}_{n+{\mathbf{MLAST}}+{m}^{*}+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ may be updated by recalling G13DKF with
${\mathbf{M}}={m}^{*}$. Note that
M and the contents of the array
Z are the only quantities which need updating;
MLAST is updated on exit from the previous call. On a successful exit,
V contains estimates of
${\epsilon}_{n+{\mathbf{MLAST}}+1},{\epsilon}_{n+{\mathbf{MLAST}}+2},\dots ,{\epsilon}_{n+{\mathbf{MLAST}}+{m}^{*}}$; columns
${\mathbf{MLAST}}+1,{\mathbf{MLAST}}+2,\dots ,{\mathbf{MLAST}}+{m}^{*}$ of
PREDZ contain the new observed values
${Z}_{n+{\mathbf{MLAST}}+1},{Z}_{n+{\mathbf{MLAST}}+2},\dots ,{Z}_{n+{\mathbf{MLAST}}+{m}^{*}}$ and columns
${\mathbf{MLAST}}+1,{\mathbf{MLAST}}+2,\dots ,{\mathbf{MLAST}}+{m}^{*}$ of
SEFZ are set to zero.
9 Example
This example shows how to update the forecasts of two series each of length
$48$. No transformation has been used and no differencing applied to either of the series.
G13DDF
is first called to fit an AR(1) model to the series.
$\mu $ is to be estimated and
${\varphi}_{1}\left(2,1\right)$ constrained to be zero. A call to
G13DJF is then made in order to compute forecasts of the next five series values. After one new observation becomes available the four forecasts are updated. A further observation becomes available and the three forecasts are updated.
9.1 Program Text
Program Text (g13dkfe.f90)
9.2 Program Data
Program Data (g13dkfe.d)
9.3 Program Results
Program Results (g13dkfe.r)