NAG Library Function Document

nag_tsa_multi_diff (g13dlc)


    1  Purpose
    7  Accuracy


nag_tsa_multi_diff (g13dlc) differences and/or transforms a multivariate time series.


#include <nag.h>
#include <nagg13.h>
void  nag_tsa_multi_diff (Integer k, Integer n, const double z[], const Integer tr[], const Integer id[], const double delta[], double w[], Integer *nd, NagError *fail)


For certain time series it may first be necessary to difference the original data to obtain a stationary series before calculating autocorrelations, etc. This function 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 ith series is di, then the differencing operator is defined by δiB=1-δi1B-δi2B2--δidiBdi, where B is the backward shift operator; that is, BZt=Zt-1. Let d denote the maximum of the orders of differencing, di, over the k series. The function computes values of the differenced/transformed series Wt = w1t,w2t,,wktT , for t=d+1,,n, as follows:
wit=δiBzit*,  i=1,2,,k  
where zit* are the transformed values of the original k-dimensional time series Zt = z1t,z2t,,zktT .
The differencing parameters δij, for i=1,2,,k and j=1,2,,di, must be supplied by you. If the ith series does not require differencing, then di=0.


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


1:     k IntegerInput
On entry: k, the dimension of the multivariate time series.
Constraint: k1.
2:     n IntegerInput
On entry: n, the number of observations in the series, prior to differencing.
Constraint: n1.
3:     z[k×n] const doubleInput
On entry: z[t-1k+i-1] must contain the ith series at time t, for t=1,2,,n and i=1,2,,k.
4:     tr[k] const IntegerInput
On entry: tr[i-1] indicates whether the ith series is to be transformed, for i=1,2,,k.
A square root transformation is used.
No transformation is used.
A log transformation is used.
Constraint: tr[i-1]=-1, 0 or 1, for i=1,2,,k.
5:     id[k] const IntegerInput
On entry: the order of differencing for each series, d1,d2,,dk.
Constraint: 0id[i]<n, for i=0,1,,k-1.
6:     delta[dim] const doubleInput
Note: the dimension, dim, of the array delta must be at least k×max1,d, where d=maxid[i-1].
On entry: if id[i-1]>0 then delta[j-1k+i-1] must be set to δij, for j=1,2,,dl and i=1,2,,k.
7:     w[dim] doubleOutput
Note: the dimension, dim, of the array w must be at least k×n-d, where d=maxid[i-1].
On exit: w[t-1k+i-1] contains the value of wi,t+d, for i=1,2,,k and t=1,2,,n-d.
8:     nd Integer *Output
On exit: the number of differenced values, n-d, in the series, where d=maxid[i-1].
9:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, k=value.
Constraint: k1.
On entry, n=value.
Constraint: n1.
On entry, element value of id is greater than or equal to n.
On entry, element value of id is less than zero.
On entry, tr[value]=value.
Constraint: tr[i]=-1, 0 or 1.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
On entry, one (or more) of the transformations requested is invalid.


The computations are believed to be stable.

Parallelism and Performance

nag_tsa_multi_diff (g13dlc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

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 2 to the first series and the first-order differencing operator  to the second series:
w1t =2z1t= 1-B 2z1t=1-2B+B2z1t,   and w2t =z2t=1-Bz2t.  
Then d1=2,d2=1, d=maxd1,d2=2, and
delta = δ11 δ12 δ21 = 2 -1 1 .  


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.

Program Text

Program Text (g13dlce.c)

Program Data

Program Data (g13dlce.d)

Program Results

Program Results (g13dlce.r)

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