G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13DLF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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.

## 2  Specification

 SUBROUTINE G13DLF ( K, N, Z, KMAX, TR, ID, DELTA, W, ND, WORK, IFAIL)
 INTEGER K, N, KMAX, ID(K), ND, IFAIL REAL (KIND=nag_wp) Z(KMAX,N), DELTA(KMAX,*), W(KMAX,*), WORK(K*N) CHARACTER(1) TR(K)

## 3  Description

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$.

## 4  References

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

## 5  Parameters

1:     K – INTEGERInput
On entry: $k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{K}}\ge 1$.
2:     N – INTEGERInput
On entry: $n$, the number of observations in the series, prior to differencing.
Constraint: ${\mathbf{N}}\ge 1$.
3:     Z(KMAX,N) – 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:     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:     TR(K) – 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:     ID(K) – 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:     DELTA(KMAX,$*$) – 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$, then DELTA is not referenced.
8:     W(KMAX,$*$) – 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:     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:   WORK(${\mathbf{K}}×{\mathbf{N}}$) – REAL (KIND=nag_wp) arrayWorkspace
11:   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{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.

## 7  Accuracy

The computations are believed to be stable.

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 .$

## 9  Example

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.

### 9.1  Program Text

Program Text (g13dlfe.f90)

### 9.2  Program Data

Program Data (g13dlfe.d)

### 9.3  Program Results

Program Results (g13dlfe.r)