Time Series

statinf.stats.timeseries.adf_test(x, lag='auto', trend='c', metric='aic', return_tuple=False)[source]

Augmented Dickey-Fuller test.

The test is primarily used for unit root testing for univariate time series in order to check for stationnarity. The null hypothesis \(H_0\) is that the root is 1 and series is not stationary.

The methodology checks the T-statistic of the variable in the linear regression and compares with critical value from MacKinnon. The default behavior will determine the lag minimizing the information criteria (AIC or BIC). User can also choose the lag.

Parameters
  • x (pandas.DataFrame or numpy.ndarray) – Time series to be tested.

  • lag (int, optional) – Lag to be considered in the series, defaults to ‘auto’.

  • trend (str, optional) –

    Trend to be included in the regression, defaults to ‘c’. Values can be:

    • ’none’: only consider the lag.

    • ’c’: only include a constant.

    • ’t’: only include the trend component.

    • ’ct’: include both constant and trend components.

  • metric (str, optional) – Type of metric to use in the linear regression for selecting the optimal lag, defaults to ‘aic’. Can either be ‘aic’ or ‘bic’.

  • return_tuple (bool) – Return a tuple with test statistic, p-value, lag. Defaults to False.

Example

>>> from statinf import stats
>>> stats.adf_test(series,  trend='ct')
... +------------------------------------------------------------+
... |                     Dickey-Fuller test                     |
... +------------+----------------+------------+---------+-------+
... |     df     | Critical value | Stat value | p-value |   H0  |
... +------------+----------------+------------+---------+-------+
... |        107 |       -3.41049 |  -1.298438 | 0.88831 | True  |
... +------------+----------------+------------+---------+-------+
... * We cannot reject H0: the series is not stationarity
... * Used 12 lags
Returns

Summary for the test or tuple statistic, critical value, p-value.

Return type

str or tuple

References
  • Hamilton, J. D. (1994). Time series analysis. Princeton university press, Princeton, NJ.

  • Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data. MIT press.

  • Cameron, A. C., & Trivedi, P. K. (2009). Microeconometrics using stata (Vol. 5, p. 706). College Station, TX: Stata press.

  • MacKinnon, J. G. (2010). Critical values for cointegration tests (No. 1227). Queen’s Economics Department Working Paper.

statinf.stats.timeseries.coint_test(x1, x2, lag='auto', trend='c', metric='aic', return_tuple=False)[source]

Cointegration test.

Checks the relation between two time series. The null hypothesis \(H_0\) is that there is no cointegration between both series. The methodology consists in regressing one variable on the other and checks the stationarity of the residuals.

Parameters
  • x1 (pandas.DataFrame or numpy.ndarray) – First series to be compared.

  • x2 (pandas.DataFrame or numpy.ndarray) – Second series to be compared.

  • lag (int, optional) – Lag to be considered in the series, defaults to ‘auto’.

  • trend (str, optional) – Trend to be included in the regression, defaults to ‘c’. See details in statinf.stats.timeseries.adf_test().

  • metric (str, optional) – Type of metric to use in the linear regression for selecting the optimal lag, defaults to ‘aic’. Can either be ‘aic’ or ‘bic’.

  • return_tuple (bool) – [description], defaults to False

  • return_tuple – Return a tuple with test statistic, p-value, and relation. Defaults to False.

Example

>>> from statinf import stats
>>> stats.coint_test(series, series2,  trend='ct')
... +------------------------------------------------------------+
... |                     Cointegration test                     |
... +------------+----------------+------------+---------+-------+
... |     df     | Critical value | Stat value | p-value |   H0  |
... +------------+----------------+------------+---------+-------+
... |        120 |       -3.41049 |  -2.213066 |  0.4825 | True  |
... +------------+----------------+------------+---------+-------+
... * We cannot reject H0: the series are not cointegrated
Returns

Summary for the test or tuple statistic, critical value, p-value.

Return type

str or tuple

References
  • Hamilton, J. D. (1994). Time series analysis. Princeton university press, Princeton, NJ.

  • Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data. MIT press.

  • MacKinnon, J. G. (1991). Critical values for cointegration tests. In Eds., Long-Run Economic Relationship: Readings in Cointegration.