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_varma_update (g13dk)

## Purpose

nag_tsa_multi_varma_update (g13dk) 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 nag_tsa_multi_varma_forecast (g13dj) must be made prior to calling this function 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 nag_tsa_multi_varma_update (g13dk) the reference vector is updated so that should future series values become available these forecasts may be updated by recalling nag_tsa_multi_varma_update (g13dk).

## Syntax

[mlast, ref, v, predz, sefz, ifail] = g13dk(k, mlast, z, ref, predz, sefz, 'lmax', lmax, 'm', m, 'lref', lref)
[mlast, ref, v, predz, sefz, ifail] = nag_tsa_multi_varma_update(k, mlast, z, ref, predz, sefz, 'lmax', lmax, 'm', m, 'lref', lref)

## Description

Let Zt = (z1t,z2t,,zkt)T ${Z}_{\mathit{t}}={\left({z}_{1\mathit{t}},{z}_{2\mathit{t}},\dots ,{z}_{k\mathit{t}}\right)}^{\mathrm{T}}$, for t = 1,2,,n$\mathit{t}=1,2,\dots ,n$, denote a k$k$-dimensional time series for which forecasts of n + 1,n + 2,, n + lmax${\stackrel{^}{Z}}_{n+1},{\stackrel{^}{Z}}_{n+2},\dots ,{\stackrel{^}{Z}}_{n+{l}_{\mathrm{max}}}$ have been computed using nag_tsa_multi_varma_forecast (g13dj). Given m$m$ further observations Zn + 1,Zn + 2,,Zn + m${Z}_{n+1},{Z}_{n+2},\dots ,{Z}_{n+m}$, where m < lmax$m<{l}_{\mathrm{max}}$, nag_tsa_multi_varma_update (g13dk) updates the forecasts of Zn + m + 1,Zn + m + 2,,Zn + lmax${Z}_{n+m+1},{Z}_{n+m+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ and their corresponding standard errors.
nag_tsa_multi_varma_update (g13dk) uses a multivariate version of the procedure described in Box and Jenkins (1976). The forecasts are updated using the ψ$\psi$ weights, computed in nag_tsa_multi_varma_forecast (g13dj). If Zt * ${Z}_{t}^{*}$ denotes the transformed value of Zt${Z}_{t}$ and t * (l)${\stackrel{^}{Z}}_{t}^{*}\left(l\right)$ denotes the forecast of Zt + l * ${Z}_{t+l}^{*}$ from time t$t$ with a lead of l$l$ (that is the forecast of Zt + l * ${Z}_{t+l}^{*}$ given observations Zt * ,Zt1 * ,${Z}_{t}^{*},{Z}_{t-1}^{*},\dots \text{}$), then
 Ẑt + 1 * (l) = τ + ψlεt + 1 + ψl + 1εt + ψl + 2εt − 1 + ⋯ $Z^t+1*(l)=τ+ψlεt+1+ψl+1εt+ψl+2εt-1+⋯$
and
 Ẑt * (l + 1) = τ + ψl + 1εt + ψl + 2εt − 1 + ⋯ $Z^t*(l+ 1)=τ+ψl+ 1εt+ψl+ 2εt- 1+⋯$
where τ$\tau$ is a constant vector of length k$k$ involving the differencing parameters and the mean vector μ$\mu$. By subtraction we obtain
 Ẑt + 1 * (l) = Ẑt * (l + 1) + ψlεt + 1. $Z^t+1*(l)=Z^t*(l+1)+ψlεt+1.$
Estimates of the residuals corresponding to the new observations are also computed as εn + l = Zn + l * n * (l)${\epsilon }_{n+\mathit{l}}={Z}_{n+\mathit{l}}^{*}-{\stackrel{^}{Z}}_{n}^{*}\left(\mathit{l}\right)$, for l = 1,2,,m$\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 nag_tsa_multi_varma_update (g13dk) may be called again should future series values become available, see Section [Further Comments].
When a transformation has been used the forecasts and their standard errors are suitably modified to give results in terms of the original series Zt${Z}_{t}$; see Granger and Newbold (1976).

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

## Parameters

The quantities k, lmax, kmax, ref and lref from nag_tsa_multi_varma_forecast (g13dj) are suitable for input to nag_tsa_multi_varma_update (g13dk).

### Compulsory Input Parameters

1:     k – int64int32nag_int scalar
k$k$, the dimension of the multivariate time series.
Constraint: k1${\mathbf{k}}\ge 1$.
2:     mlast – int64int32nag_int scalar
On the first call to nag_tsa_multi_varma_update (g13dk), since calling nag_tsa_multi_varma_forecast (g13dj), mlast must be set to 0$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 nag_tsa_multi_varma_update (g13dk).
Constraint: 0mlast < lmaxm$0\le {\mathbf{mlast}}<{\mathbf{lmax}}-{\mathbf{m}}$.
3:     z(kmax,m) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
z(i,j)${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)$ must contain the value of zi,n + mlast + j${z}_{\mathit{i},n+{\mathbf{mlast}}+\mathit{j}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and j = 1,2,,m$\mathit{j}=1,2,\dots ,m$, and where n$n$ is the number of observations in the time series in the last call made to nag_tsa_multi_varma_forecast (g13dj).
Constraint: if the transformation defined in tr in nag_tsa_multi_varma_forecast (g13dj) for the i$\mathit{i}$th series is the log transformation, then z(i,j) > 0.0${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)>0.0$, and if it is the square-root transformation, then z(i,j)0.0${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)\ge 0.0$, for j = 1,2,,m$\mathit{j}=1,2,\dots ,m$ and i = 1,2,,k$\mathit{i}=1,2,\dots ,k$.
4:     ref(lref) – double array
lref, the dimension of the array, must satisfy the constraint lref(lmax1) × k × k + 2 × k × lmax + k${\mathbf{lref}}\ge \left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$.
Must contain the first (lmax1) × k × k + 2 × k × lmax + k$\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$ elements of the reference vector as returned on a successful exit from nag_tsa_multi_varma_forecast (g13dj) (or a previous call to nag_tsa_multi_varma_update (g13dk)).
5:     predz(kmax,lmax) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
Nonupdated values are kept intact.
6:     sefz(kmax,lmax) – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
Nonupdated values are kept intact.

### Optional Input Parameters

1:     lmax – int64int32nag_int scalar
Default: The second dimension of the arrays predz, sefz. (An error is raised if these dimensions are not equal.)
The number, lmax${l}_{\mathrm{max}}$, of forecasts requested in the call to nag_tsa_multi_varma_forecast (g13dj).
Constraint: lmax2${\mathbf{lmax}}\ge 2$.
2:     m – int64int32nag_int scalar
Default: The second dimension of the array z.
m$m$, the number of new observations available since the last call to either nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk). The number of new observations since the last call to nag_tsa_multi_varma_forecast (g13dj) is then ${\mathbf{m}}+{\mathbf{mlast}}$.
Constraint: 0 < m < lmaxmlast$0<{\mathbf{m}}<{\mathbf{lmax}}-{\mathbf{mlast}}$.
3:     lref – int64int32nag_int scalar
Default: The dimension of the array ref.
The dimension of the array ref as declared in the (sub)program from which nag_tsa_multi_varma_update (g13dk) is called.
Constraint: lref(lmax1) × k × k + 2 × k × lmax + k${\mathbf{lref}}\ge \left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$.

kmax work

### Output Parameters

1:     mlast – int64int32nag_int scalar
Is incremented by m$m$ to indicate that ${\mathbf{mlast}}+{\mathbf{m}}$ observations have now been used to update the forecasts since the last call to nag_tsa_multi_varma_forecast (g13dj).
mlast must not be changed between calls to nag_tsa_multi_varma_update (g13dk), unless a call to nag_tsa_multi_varma_forecast (g13dj) has been made between the calls in which case mlast should be reset to 0$0$.
2:     ref(lref) – double array
The elements of ref are updated. The first (lmax1) × k × k$\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}$ elements store the ψ$\psi$ weights ψ1,ψ2,,ψlmax1${\psi }_{1},{\psi }_{2},\dots ,{\psi }_{{l}_{\mathrm{max}}-1}$. The next ${\mathbf{k}}×{\mathbf{lmax}}$ elements contain the forecasts of the transformed series and the next ${\mathbf{k}}×{\mathbf{lmax}}$ elements contain the variances of the forecasts of the transformed variables; see nag_tsa_multi_varma_forecast (g13dj). The last k elements are not updated.
3:     v(kmax,m) – double array
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
v(i,j)${\mathbf{v}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the i$\mathit{i}$th component of εn + mlast + j${\epsilon }_{n+{\mathbf{mlast}}+\mathit{j}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and j = 1,2,,m$\mathit{j}=1,2,\dots ,m$.
4:     predz(kmax,lmax) – double array
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
predz(i,j)${\mathbf{predz}}\left(\mathit{i},\mathit{j}\right)$ contains the updated forecast of zi,n + j${z}_{\mathit{i},n+\mathit{j}}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and j = mlast + m + 1,,lmax$\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 nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk) are set equal to the corresponding columns of z.
5:     sefz(kmax,lmax) – double array
kmaxk$\mathit{kmax}\ge {\mathbf{k}}$.
sefz(i,j)${\mathbf{sefz}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the standard error of the corresponding element of predz, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$ and j = mlast + m + 1,,lmax$\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 nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk) are set equal to zero.
6:     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, k < 1${\mathbf{k}}<1$, or lmax < 2${\mathbf{lmax}}<2$, or m ≤ 0${\mathbf{m}}\le 0$, or ${\mathbf{mlast}}+{\mathbf{m}}\ge {\mathbf{lmax}}$, or mlast < 0${\mathbf{mlast}}<0$, or kmax < k$\mathit{kmax}<{\mathbf{k}}$, or lref < (lmax − 1) × k × k + 2 × k × lmax + k${\mathbf{lref}}<\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$.
ifail = 2${\mathbf{ifail}}=2$
On entry, some of the elements of the reference vector, ref, have been corrupted since the most recent call to nag_tsa_multi_varma_forecast (g13dj) (or nag_tsa_multi_varma_update (g13dk)).
ifail = 3${\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.
ifail = 4${\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.

## Accuracy

The matrix computations are believed to be stable.

If a further m*${m}^{*}$ observations, Zn + mlast + 1,Zn + mlast + 2,, Zn + mlast + m*${Z}_{n+{\mathbf{mlast}}+1},{Z}_{n+{\mathbf{mlast}}+2},\dots ,{Z}_{n+{\mathbf{mlast}}+{m}^{*}}$, become available, then forecasts of Zn + mlast + m* + 1,Zn + mlast + m* + 2,, Zn + lmax${Z}_{n+{\mathbf{mlast}}+{m}^{*}+1},{Z}_{n+{\mathbf{mlast}}+{m}^{*}+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ may be updated by recalling nag_tsa_multi_varma_update (g13dk) with m = m*${\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 εn + mlast + 1,εn + mlast + 2,, εn + mlast + m*${\epsilon }_{n+{\mathbf{mlast}}+1},{\epsilon }_{n+{\mathbf{mlast}}+2},\dots ,{\epsilon }_{n+{\mathbf{mlast}}+{m}^{*}}$; columns mlast + 1,mlast + 2,,mlast + m*${\mathbf{mlast}}+1,{\mathbf{mlast}}+2,\dots ,{\mathbf{mlast}}+{m}^{*}$ of predz contain the new observed values Zn + mlast + 1,Zn + mlast + 2,, Zn + mlast + m*${Z}_{n+{\mathbf{mlast}}+1},{Z}_{n+{\mathbf{mlast}}+2},\dots ,{Z}_{n+{\mathbf{mlast}}+{m}^{*}}$ and columns mlast + 1,mlast + 2,,mlast + m*${\mathbf{mlast}}+1,{\mathbf{mlast}}+2,\dots ,{\mathbf{mlast}}+{m}^{*}$ of sefz are set to zero.

## Example

```function nag_tsa_multi_varma_update_example
k = int64(2);
mlast = int64(0);
z = [8.1;
10.2];
ref = [0.8016071892386086;
0;
0.0648134906597352;
0.575015951133362;
0.6425740858390225;
0;
0.08922375105047406;
0.330643344057805;
0.5150920068269873;
0;
0.09295254958469001;
0.1901251969693142;
0.4129014557918555;
0;
0.08683410968309672;
0.109325020969728;
7.82042808779155;
10.30633951031062;
7.277073498724811;
9.251955479776221;
6.773178244308308;
8.645667843598654;
6.329956567700314;
8.297042781821611;
5.952071278119719;
8.096577810334958;
2.964154253391392;
5.379903126133676;
4.957660260306922;
7.158732286465553;
6.297464315601706;
7.746890308545223;
7.191419098742513;
7.941360843800069;
7.783032455102286;
8.005661231897443;
100;
100;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0];
predz = [7.82042808779155, 7.277073498724811, 6.773178244308308, 6.329956567700314, 5.952071278119719;
10.30633951031062, 9.251955479776221, 8.645667843598654, 8.297042781821611, 8.096577810334958];
sefz = [1.721671935471852, 2.226580396102266, 2.509474908342721, 2.681682139766477, 2.789808677150153;
2.319461818209922, 2.675580738169856, 2.783323608304507, 2.81804202307206, 2.829427721624541];
[mlastOut, refOut, v, predzOut, sefzOut, ifail] = ...
nag_tsa_multi_varma_update(k, mlast, z, ref, predz, sefz)
```
```

mlastOut =

1

refOut =

0.8016
0
0.0648
0.5750
0.6426
0
0.0892
0.3306
0.5151
0
0.0930
0.1901
0.4129
0
0.0868
0.1093
7.8204
10.3063
7.4943
9.1908
6.9433
8.6105
6.4641
8.2768
6.0583
8.0850
2.9642
5.3799
4.9577
7.1587
6.2975
7.7469
7.1914
7.9414
7.7830
8.0057
100.0000
100.0000
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

v =

0.2796
-0.1063

predzOut =

8.1000    7.4943    6.9433    6.4641    6.0583
10.2000    9.1908    8.6105    8.2768    8.0850

sefzOut =

0    1.7217    2.2266    2.5095    2.6817
0    2.3195    2.6756    2.7833    2.8180

ifail =

0

```
```function g13dk_example
k = int64(2);
mlast = int64(0);
z = [8.1;
10.2];
ref = [0.8016071892386086;
0;
0.0648134906597352;
0.575015951133362;
0.6425740858390225;
0;
0.08922375105047406;
0.330643344057805;
0.5150920068269873;
0;
0.09295254958469001;
0.1901251969693142;
0.4129014557918555;
0;
0.08683410968309672;
0.109325020969728;
7.82042808779155;
10.30633951031062;
7.277073498724811;
9.251955479776221;
6.773178244308308;
8.645667843598654;
6.329956567700314;
8.297042781821611;
5.952071278119719;
8.096577810334958;
2.964154253391392;
5.379903126133676;
4.957660260306922;
7.158732286465553;
6.297464315601706;
7.746890308545223;
7.191419098742513;
7.941360843800069;
7.783032455102286;
8.005661231897443;
100;
100;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0;
0];
predz = [7.82042808779155, 7.277073498724811, 6.773178244308308, 6.329956567700314, 5.952071278119719;
10.30633951031062, 9.251955479776221, 8.645667843598654, 8.297042781821611, 8.096577810334958];
sefz = [1.721671935471852, 2.226580396102266, 2.509474908342721, 2.681682139766477, 2.789808677150153;
2.319461818209922, 2.675580738169856, 2.783323608304507, 2.81804202307206, 2.829427721624541];
[mlastOut, refOut, v, predzOut, sefzOut, ifail] = g13dk(k, mlast, z, ref, predz, sefz)
```
```

mlastOut =

1

refOut =

0.8016
0
0.0648
0.5750
0.6426
0
0.0892
0.3306
0.5151
0
0.0930
0.1901
0.4129
0
0.0868
0.1093
7.8204
10.3063
7.4943
9.1908
6.9433
8.6105
6.4641
8.2768
6.0583
8.0850
2.9642
5.3799
4.9577
7.1587
6.2975
7.7469
7.1914
7.9414
7.7830
8.0057
100.0000
100.0000
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

v =

0.2796
-0.1063

predzOut =

8.1000    7.4943    6.9433    6.4641    6.0583
10.2000    9.1908    8.6105    8.2768    8.0850

sefzOut =

0    1.7217    2.2266    2.5095    2.6817
0    2.3195    2.6756    2.7833    2.8180

ifail =

0

```