Skip to content

timeseries

Time-series statistics: stationarity, seasonality, gaps and autocorrelation.

These need the whole series in order, so they run on a materialised column (numpy arrays). They replace the statsmodels functions the pandas backend used (adfuller, acf, pacf), which would pull in pandas.

Classes

Functions:

mackinnon_pvalue(stat)

Approximate p-value of an ADF statistic (regression with a constant).

adfuller(x, maxlag=None, autolag='AIC')

Augmented Dickey-Fuller unit-root test with a constant.

Matches statsmodels.tsa.stattools.adfuller(x, regression="c") for the statistic and the MacKinnon p-value.

Returns: The test statistic, its p-value and the number of lags used.

get_fft(values)

Positive frequencies and their power (dB).

seasonality_test(values, mad_threshold=6.0)

Detect seasonality from the outlying peaks of the power spectrum.

Source: https://github.com/facebookresearch/Kats/blob/main/kats/detectors/seasonality.py

compute_gap_stats(data, gap_tolerance=2)

Intervals between observations that are much longer than usual.

Args: data: index and value columns, non-null values only.

acf(x, nlags, alpha=0.05)

Autocorrelation with Bartlett confidence intervals (as statsmodels).

pacf(x, nlags, alpha=0.05)

Partial autocorrelation by Levinson-Durbin on the biased autocovariance (statsmodels' method="ywm"), with normal confidence intervals.

timeseries_summary(config, data)

Seasonality, stationarity and gaps of a series.

Args: data: index and value columns, in time order.