Try out NAG Library functions

Explore NAG maths and stats routines with interactive demos
Function ID
G13AAF
Name
nagf_tsa_uni_diff
Description
Univariate time series, seasonal and non-seasonal differencing
Keywords
differencing, time series | non-seasonal differencing | seasonal differencing | time series | univariate time series
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.
The example data reflects that shown in the "Example" section of the routine documentation. You can change this here to try alternative inputs. The formatting will need to be kept as it is here, otherwise the program is likely to fail to run correctly.

Please note that incompatible data will however cause the example output to display an error message. These error messages are fully explained in the Routine document
    Program g13aafe

!     G13AAF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: g13aaf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: ifail, nd, nds, ns, nx, nxd
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: x(:), xd(:)
!     .. Executable Statements ..
      Write (nout,*) 'G13AAF Example Program Results'
      Write (nout,*)

!     Skip heading in data file
      Read (nin,*)

!     Read in the problem size
      Read (nin,*) nx, nd, nds, ns

      Allocate (x(nx),xd(nx))

!     Read in data
      Read (nin,*) x(1:nx)

!     Perform differencing
      ifail = 0
      Call g13aaf(x,nx,nd,nds,ns,xd,nxd,ifail)

!     Display results
      Write (nout,99999) 'Non-seasonal differencing of order ', nd,            &
        ' and seasonal differencing'
      Write (nout,99999) 'of order ', nds, ' with seasonality ', ns,           &
        ' are applied'
      Write (nout,*)
      Write (nout,99998) 'The output array holds ', nx,                        &
        ' values, of which the first ', nxd, ' are differenced values'
      Write (nout,*)
      Write (nout,99997) xd(1:nx)

99999 Format (1X,A,I1,A,I1,A)
99998 Format (1X,A,I2,A,I2,A)
99997 Format (1X,5F9.1)
    End Program g13aafe
The NAG Library
The world’s largest collection of robust, documented, tested and maintained numerical algorithms.
Learn more here or contact us for purchasing information