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

# Syntax

C#
```public static void g13dl(
int k,
int n,
double[,] z,
string[] tr,
int[] id,
double[,] delta,
double[,] w,
out int nd,
out int ifail
)```
Visual Basic
```Public Shared Sub g13dl ( _
k As Integer, _
n As Integer, _
z As Double(,), _
tr As String(), _
id As Integer(), _
delta As Double(,), _
w As Double(,), _
<OutAttribute> ByRef nd As Integer, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g13dl(
int k,
int n,
array<double,2>^ z,
array<String^>^ tr,
array<int>^ id,
array<double,2>^ delta,
array<double,2>^ w,
[OutAttribute] int% nd,
[OutAttribute] int% ifail
)```
F#
```static member g13dl :
k : int *
n : int *
z : float[,] *
tr : string[] *
id : int[] *
delta : float[,] *
w : float[,] *
nd : int byref *
ifail : int byref -> unit
```

#### Parameters

k
Type: System..::..Int32
On entry: $k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{k}}\ge 1$.
n
Type: System..::..Int32
On entry: $n$, the number of observations in the series, prior to differencing.
Constraint: ${\mathbf{n}}\ge 1$.
z
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathbf{_kmax}\ge {\mathbf{k}}$
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-1\right]=\text{"L"}$, ${\mathbf{z}}\left[i,t\right]>0.0$;
• if ${\mathbf{tr}}\left[i-1\right]=\text{"S"}$, ${\mathbf{z}}\left[\mathit{i},\mathit{t}\right]\ge 0.0$, for $\mathit{i}=0,1,\dots ,k-1$ and $\mathit{t}=0,1,\dots ,n-1$.
tr
Type: array<System..::..String>[]()[][]
An array of size [k]
On entry: ${\mathbf{tr}}\left[\mathit{i}-1\right]$ indicates whether the $\mathit{i}$th time series is to be transformed, for $\mathit{i}=1,2,\dots ,k$.
${\mathbf{tr}}\left[i-1\right]=\text{"N"}$
No transformation is used.
${\mathbf{tr}}\left[i-1\right]=\text{"L"}$
A log transformation is used.
${\mathbf{tr}}\left[i-1\right]=\text{"S"}$
A square root transformation is used.
Constraint: ${\mathbf{tr}}\left[\mathit{i}-1\right]=\text{"N"}$, $\text{"L"}$ or $\text{"S"}$, for $\mathit{i}=1,2,\dots ,k$.
id
Type: array<System..::..Int32>[]()[][]
An array of size [k]
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}=0,1,\dots ,{\mathbf{k}}-1$.
delta
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathbf{_kmax}\ge {\mathbf{k}}$
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-1\right]\right)$.
On entry: if ${\mathbf{id}}\left[i-1\right]>0$, then ${\mathbf{delta}}\left[\mathit{i}-1,\mathit{j}-1\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.
w
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathbf{_kmax}\ge {\mathbf{k}}$
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-1\right]\right)$.
On exit: ${\mathbf{w}}\left[\mathit{i}-1,\mathit{t}-1\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}$.
nd
Type: System..::..Int32%
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-1\right]\right)$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (KMAX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{k}}<1$, or ${\mathbf{n}}<1$,
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{id}}\left[i-1\right]<0$, for some $i=1,2,\dots ,k$, or ${\mathbf{id}}\left[i-1\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}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The computations are believed to be stable.

# Parallelism and Performance

None.

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-B2z1t=1-2B+B2z1t, andw2t=∇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-11.$

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

Example program (C#): g13dle.cs

Example program data: g13dle.d

Example program results: g13dle.r