# naginterfaces.library.tsa.uni_​diff¶

naginterfaces.library.tsa.uni_diff(x, nd, nds, ns)[source]

uni_diff 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.

For full information please refer to the NAG Library document for g13aa

https://www.nag.com/numeric/nl/nagdoc_27.1/flhtml/g13/g13aaf.html

Parameters
xfloat, array-like, shape

The undifferenced time series, , for .

ndint

, the order of non-seasonal differencing.

ndsint

, the order of seasonal differencing.

nsint

, the seasonality.

Returns
xdfloat, ndarray, shape

The differenced values in elements to , and reconstitution data in the remainder of the array.

nxdint

The number of differenced values in the array .

Raises
NagValueError
(errno )

On entry, .

Constraint: if , .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, , , and .

Constraint: .

Notes

Let be the th value of a time series , for after non-seasonal differencing of order and seasonal differencing of order (with period or seasonality ). In general,

 ∇d∇Dsxi=∇d−1∇Dsxi+1−∇d−1∇Dsxi d>0 ∇d∇Dsxi=∇d∇D−1sxi+s−∇d∇D−1sxi D>0

Non-seasonal differencing up to the required order 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 is then obtained using

 ∇d∇1sxi=∇dxi+s−∇dxi for i=1,2,…,(n−d−s) ∇d∇2sxi=∇d∇1sxi+s−∇d∇1sxi for i=1,2,…,(n−d−2s) ⋮ ∇d∇Dsxi=∇d∇D−1sxi+s−∇d∇D−1sxi 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 values.