hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_uni_diff (g13aa)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_tsa_uni_diff (g13aa) 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.

Syntax

[xd, nxd, ifail] = g13aa(x, nd, nds, ns, 'nx', nx)
[xd, nxd, ifail] = nag_tsa_uni_diff(x, nd, nds, ns, 'nx', nx)

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.

References

None.

Parameters

Compulsory Input Parameters

1:     xnx – double array
The undifferenced time series, xi, for i=1,2,,n.
2:     nd int64int32nag_int scalar
d, the order of non-seasonal differencing.
Constraint: nd0.
3:     nds int64int32nag_int scalar
D, the order of seasonal differencing.
Constraint: nds0.
4:     ns int64int32nag_int scalar
s, the seasonality.
Constraints:
  • if nds>0, ns>0;
  • if nds=0, ns0.

Optional Input Parameters

1:     nx int64int32nag_int scalar
Default: the dimension of the array x.
n, the number of values in the undifferenced time series.
Constraint: nx>nd+nds×ns.

Output Parameters

1:     xdnx – double array
The differenced values in elements 1 to nxd, and reconstitution data in the remainder of the array.
2:     nxd int64int32nag_int scalar
The number of differenced values in the array xd.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,nd<0,
ornds<0,
orns<0,
orns=0 when nds>0.
   ifail=2
On entry,nxnd+nds×ns.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The computations are believed to be stable.

Further Comments

The time taken by nag_tsa_uni_diff (g13aa) is approximately proportional to nd+nds×nx.

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.
function g13aa_example


fprintf('g13aa example results\n\n');

x = [120;     108;      98;     118;     135;
     131;     118;     125;     121;     100;
      82;      82;      89;      88;      86;
      96;     108;     110;      99;     105];
nd  = int64(2);
nds = int64(1);
ns  = int64(4);

[xd, nxd, ifail] = g13aa( ...
                          x, nd, nds, ns);

% Display results
nx = numel(xd);
fprintf(' Non-seasonal differencing of order %4d\n', nd);
fprintf(' and seasonal differencing of order %4d\n', nds);
fprintf('       are applied with seasonality %4d\n\n',ns);
fprintf('The output array holds %4d values,\n',nx); 
fprintf('    of which the first %4d are differenced values\n\n',nxd);
for j = 1:7:nxd
  fprintf('%7.0f',xd(j:min(j+6,nxd)));
  fprintf('\n');
end
fprintf('\n');
for j = nxd+1:7:nx
  fprintf('%7.0f',xd(j:min(j+6,nx)));
  fprintf('\n');
end


g13aa example results

 Non-seasonal differencing of order    2
 and seasonal differencing of order    1
       are applied with seasonality    4

The output array holds   20 values,
    of which the first   14 are differenced values

    -11    -10     -8      4     12     -2     18
      9     -4     -6     -5     -2    -12      5

      2    -10    -13     17      6    105

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015