NAG Library Function Document

nag_tsa_diff (g13aac)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_tsa_diff (g13aac) carries out non-seasonal and seasonal differencing on a time series. Information which allows the original series to be reconstituted from the differenced series is also produced. This information is required in time series forecasting.

2
Specification

#include <nag.h>
#include <nagg13.h>
void  nag_tsa_diff (const double x[], Integer nx, Integer d, Integer ds, Integer s, double xd[], Integer *nxd, NagError *fail)

3
Description

Let dsDxi be the ith value of a time series xi, for i=1,2,,n after non-seasonal differencing of order d and seasonal differencing of order D (with period or seasonality s). In general,
dsDxi = d-1sDxi+1-d-1sDxi d>0
dsDxi = dsD-1xi+s-dsD-1xi D>0
Non-seasonal differencing up to the required order d is obtained using
1xi = xi+1-xi for i=1,2,,n-1
2xi = 1xi+1-1xi for i=1,2,,n-2
     
dxi = d-1xi+1-d-1xi for i=1,2,,n-d
Seasonal differencing up to the required order D is then obtained using
ds1xi = dxi+s-dxi for i=1,2,,n-d-s
ds2xi = ds1xi+s-ds1xi for i=1,2,,n-d-2s
     
dsDxi = dsD-1xi+s-dsD-1xi for i=1,2,,n-d-D×s
Mathematically, the sequence in which the differencing operations are performed does not affect the final resulting series of m=n-d-D×s values.

4
References

None.

5
Arguments

1:     x[nx] const doubleInput
On entry: the undifferenced time series, xi, for i=1,2,,n.
2:     nx IntegerInput
On entry: n, the number of values in the undifferenced time series.
Constraint: nx>d+ds×s.
3:     d IntegerInput
On entry: d, the order of non-seasonal differencing.
Constraint: d0.
4:     ds IntegerInput
On entry: D, the order of seasonal differencing.
Constraint: ds0.
5:     s IntegerInput
On entry: s, the seasonality.
Constraints:
  • if ds>0, s>0;
  • if ds=0, s0.
6:     xd[nx] doubleOutput
On exit: the differenced values in elements 0 to nxd-1, and reconstitution data in the remainder of the array.
7:     nxd Integer *Output
On exit: the number of differenced values in the array xd.
8:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, d=value.
Constraint: d0.
On entry, ds=value.
Constraint: ds0.
On entry, s=value.
Constraint: s0.
NE_INT_2
On entry, ds=value.
Constraint: if s=0, ds0.
NE_INT_4
On entry, nx=value, d=value, ds=value and s=value.
Constraint: nx>d+ds×s.
NE_INTERNAL_ERROR
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.
NE_NO_LICENCE
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.

7
Accuracy

The computations are believed to be stable.

8
Parallelism and Performance

nag_tsa_diff (g13aac) is not threaded in any implementation.

9
Further Comments

The time taken by nag_tsa_diff (g13aac) is approximately proportional to d+ds×nx.

10
Example

This example reads in a set of data consisting of 20 observations from a time series. Non-seasonal differencing of order 2 and seasonal differencing of order 1 (with seasonality of 4) are applied to the input data, giving an output array holding 14 differenced values and 6 values which can be used to reconstitute the output array.

10.1
Program Text

Program Text (g13aace.c)

10.2
Program Data

Program Data (g13aace.d)

10.3
Program Results

Program Results (g13aace.r)

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