NAG Library Routine Document

1Purpose

g13dlf differences and/or transforms a multivariate time series. It is intended to be used prior to g13ddf to fit a vector autoregressive moving average (VARMA) model to the differenced/transformed series.

2Specification

Fortran Interface
 Subroutine g13dlf ( k, n, z, kmax, tr, id, w, nd, work,
 Integer, Intent (In) :: k, n, kmax, id(k) Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: nd Real (Kind=nag_wp), Intent (In) :: z(kmax,n), delta(kmax,*) Real (Kind=nag_wp), Intent (Inout) :: w(kmax,*) Real (Kind=nag_wp), Intent (Out) :: work(k*n) Character (1), Intent (In) :: tr(k)
#include nagmk26.h
 void g13dlf_ (const Integer *k, const Integer *n, const double z[], const Integer *kmax, const char tr[], const Integer id[], const double delta[], double w[], Integer *nd, double work[], Integer *ifail, const Charlen length_tr)

3Description

For certain time series it may first be necessary to difference the original data to obtain a stationary series before calculating autocorrelations, etc. This routine also allows you to apply either a square root or a log transformation to the original time series to stabilize the variance if required.
If the order of differencing required for the $i$th series is ${\mathit{d}}_{i}$, then the differencing operator is defined by ${\delta }_{i}\left(B\right)=1-{\delta }_{i1}B-{\delta }_{i2}{B}^{2}-\cdots -{\delta }_{i{\mathit{d}}_{i}}{B}^{{\mathit{d}}_{i}}$, where $B$ is the backward shift operator; that is, $B{Z}_{t}={Z}_{t-1}$. Let $\mathit{d}$ denote the maximum of the orders of differencing, ${\mathit{d}}_{i}$, over the $k$ series. The routine computes values of the differenced/transformed series ${W}_{\mathit{t}}={\left({w}_{1\mathit{t}},{w}_{2\mathit{t}},\dots ,{w}_{\mathit{k}\mathit{t}}\right)}^{\mathrm{T}}$, for $\mathit{t}=\mathit{d}+1,\dots ,n$, as follows:
 $wit=δiBzit*, i=1,2,…,k$
where ${z}_{it}^{*}$ are the transformed values of the original $k$-dimensional time series ${Z}_{t}={\left({z}_{1t},{z}_{2t},\dots ,{z}_{kt}\right)}^{\mathrm{T}}$.
The differencing parameters ${\delta }_{ij}$, for $i=1,2,\dots ,k$ and $j=1,2,\dots ,{\mathit{d}}_{i}$, must be supplied by you. If the $i$th series does not require differencing, then ${\mathit{d}}_{i}=0$.

4References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley

5Arguments

1:     $\mathbf{k}$ – IntegerInput
On entry: $k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{k}}\ge 1$.
2:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of observations in the series, prior to differencing.
Constraint: ${\mathbf{n}}\ge 1$.
3:     $\mathbf{z}\left({\mathbf{kmax}},{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{z}}\left(\mathit{i},\mathit{t}\right)$ must contain, ${z}_{\mathit{i}\mathit{t}}$, the $\mathit{i}$th component of ${Z}_{\mathit{t}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n$.
Constraints:
• if ${\mathbf{tr}}\left(i\right)=\text{'L'}$, ${\mathbf{z}}\left(i,t\right)>0.0$;
• if ${\mathbf{tr}}\left(i\right)=\text{'S'}$, ${\mathbf{z}}\left(\mathit{i},\mathit{t}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n$.
4:     $\mathbf{kmax}$ – IntegerInput
On entry: the first dimension of the arrays z, delta and w as declared in the (sub)program from which g13dlf is called.
Constraint: ${\mathbf{kmax}}\ge {\mathbf{k}}$.
5:     $\mathbf{tr}\left({\mathbf{k}}\right)$ – Character(1) arrayInput
On entry: ${\mathbf{tr}}\left(\mathit{i}\right)$ indicates whether the $\mathit{i}$th time series is to be transformed, for $\mathit{i}=1,2,\dots ,k$.
${\mathbf{tr}}\left(i\right)=\text{'N'}$
No transformation is used.
${\mathbf{tr}}\left(i\right)=\text{'L'}$
A log transformation is used.
${\mathbf{tr}}\left(i\right)=\text{'S'}$
A square root transformation is used.
Constraint: ${\mathbf{tr}}\left(\mathit{i}\right)=\text{'N'}$, $\text{'L'}$ or $\text{'S'}$, for $\mathit{i}=1,2,\dots ,k$.
6:     $\mathbf{id}\left({\mathbf{k}}\right)$ – Integer arrayInput
On entry: the order of differencing for each series, ${\mathit{d}}_{1},{\mathit{d}}_{2},\dots ,{\mathit{d}}_{k}$.
Constraint: $0\le {\mathbf{id}}\left(\mathit{i}\right)<{\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{k}}$.
7:     $\mathbf{delta}\left({\mathbf{kmax}},*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array delta must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\mathit{d}\right)$, where $\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$.
On entry: if ${\mathbf{id}}\left(i\right)>0$, then ${\mathbf{delta}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to ${\delta }_{\mathit{i}\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathit{d}}_{i}$ and $\mathit{i}=1,2,\dots ,k$.
If $\mathit{d}=0$, delta is not referenced.
8:     $\mathbf{w}\left({\mathbf{kmax}},*\right)$ – Real (Kind=nag_wp) arrayOutput
Note: the second dimension of the array w must be at least ${\mathbf{n}}-\mathit{d}$, where $\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$.
On exit: ${\mathbf{w}}\left(\mathit{i},\mathit{t}\right)$ contains the value of ${w}_{\mathit{i},\mathit{t}+\mathit{d}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n-\mathit{d}$.
9:     $\mathbf{nd}$ – IntegerOutput
On exit: the number of differenced values, $n-\mathit{d}$, in the series, where $\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{id}}\left(i\right)\right)$.
10:   $\mathbf{work}\left({\mathbf{k}}×{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
11:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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{n}}<1$, or ${\mathbf{kmax}}<{\mathbf{k}}$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{id}}\left(i\right)<0$, for some $i=1,2,\dots ,k$, or ${\mathbf{id}}\left(i\right)\ge {\mathbf{n}}$, for some $i=1,2,\dots ,k$.
${\mathbf{ifail}}=3$
 On entry, at least one of the first $k$ elements of tr is not equal to 'N', 'L' or 'S'.
${\mathbf{ifail}}=4$
On entry, one or more of the elements of z is invalid, for the transformation requested; that is, you may be trying to log or square root a series, some of whose values are negative.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7Accuracy

The computations are believed to be stable.

8Parallelism and Performance

g13dlf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The same differencing operator does not have to be applied to all the series. For example, suppose we have $k=2$, and wish to apply the second-order differencing operator ${\nabla }^{2}$ to the first series and the first-order differencing operator $\nabla$ to the second series:
 $w1t =∇2z1t= 1-B 2z1t=1-2B+B2z1t, and w2t =∇z2t=1-Bz2t.$
Then ${\mathit{d}}_{1}=2,{\mathit{d}}_{2}=1$, $\mathit{d}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathit{d}}_{1},{\mathit{d}}_{2}\right)=2$, and
 $delta = δ11 δ12 δ21 = 2 -1 1 .$

10Example

A program to difference (non-seasonally) each of two time series of length $48$. No transformation is to be applied to either of the series.

10.1Program Text

Program Text (g13dlfe.f90)

10.2Program Data

Program Data (g13dlfe.d)

10.3Program Results

Program Results (g13dlfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017