TimeSeriesSRC.sdiff

TimeSeriesSRC.sdiff(y, d, p=1)

Apply seasonal (or regular) differencing to a time series.

Computes the d-th order difference at period p:

\[\nabla_p^d\, y(t) = \nabla_p^{d-1}\, y(t) - \nabla_p^{d-1}\, y(t-p)\]

For p = 1 this reduces to ordinary differencing (numpy.diff).

Parameters:
  • y (array-like) – 1-D or row-vector input series.

  • d (int) – Number of differences to apply. d = 0 returns y unchanged.

  • p (int, optional) – Seasonal period. Default 1 (ordinary differencing).

Returns:

yd – Differenced series. Each application of the operator reduces the length by p.

Return type:

ndarray, shape (1, N - d*p)

Raises:

Exception – If d * p is larger than or equal to the length of y.

Examples

>>> import numpy as np
>>> from TimeSeriesSRC.basefunctions.sdiff import func_sdiff
>>> y = np.arange(1.0, 21.0)
>>> yd = func_sdiff(y, d=1, p=4)   # seasonal difference at lag 4
>>> yd.shape
(1, 16)

See also

uniAnal

Passes diff / per arguments directly to this function.