UnitRootTest#

class cultivars.diagnostics.unit_roots.UnitRootTest(*, statistic, pvalue, name, critical_values, null, nobs, lower_tail=False, companions=(), trend, lags, method, break_index=None)[source]

Bases: _TabulatedTest

Verdict of a unit-root or stationarity test.

The family is not one hypothesis but two. The Dickey-Fuller line, ADF, Phillips-Perron, DF-GLS, Ng-Perron, Zivot-Andrews, puts the unit root under the null and rejects in the lower tail: under \(\rho = 1\) in \(\Delta y_t = (\rho - 1) y_{t-1} + \cdots\) the \(t\) ratio converges not to a normal but to the Dickey-Fuller functional

\[\frac{\int_0^1 W(r)\, dW(r)}{\bigl(\int_0^1 W(r)^2\, dr\bigr)^{1/2}},\]

whose quantiles depend on the deterministic terms and sit well to the left of the normal’s. KPSS puts stationarity under the null and rejects in the upper tail, its statistic a scaled integral of a squared Brownian bridge. The record carries which, so that reject() reads correctly for both and a table of several tests can be read side by side: a series the ADF cannot reject a unit root for and the KPSS cannot reject stationarity for is one the sample does not decide, and that is a finding.

P-values are exact where the literature supplies a response surface (MacKinnon for the Dickey-Fuller law) or a table dense enough to interpolate (KPSS, whose p-value is then clipped to the table’s range); the tests known only through asymptotic critical values at three levels report pvalue=None and reject() reads the table, refusing a level it does not carry.

Variables:
  • trend – Deterministic specification the test was run under.

  • lags – Augmentation lags or kernel bandwidth, as the test uses.

  • method – How lags was chosen or the kernel used.

  • break_index – For a break-allowing test, the first observation of the new regime; None otherwise.

Note

lags means two different things across the family, and method disambiguates: an augmentation count for ADF, DF-GLS, Ng-Perron, and Zivot-Andrews, where method names the selection rule and its ceiling; a kernel bandwidth for Phillips-Perron and KPSS, where method names the kernel. Ng-Perron’s four statistics travel as companions of the \(MZ_t\) record, since they are one test on one sample.

See also

References

Dickey, D. A., & Fuller, W. A. (1979). Distribution of the estimators for autoregressive time series with a unit root. Journal of the American Statistical Association, 74(366), 427-431.

MacKinnon, J. G. (1996). Numerical distribution functions for unit root and cointegration tests. Journal of Applied Econometrics, 11(6), 601-618.

Kwiatkowski, D., Phillips, P. C. B., Schmidt, P., & Shin, Y. (1992). Testing the null hypothesis of stationarity against the alternative of a unit root. Journal of Econometrics, 54(1-3), 159-178.

Example

A random walk keeps the ADF null and rejects the KPSS null; white noise does the reverse. The two records reject in opposite tails and agree on both series:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> walk = np.cumsum(rng.standard_normal(300))
>>> noise = rng.standard_normal(300)
>>> adf(walk).reject(), kpss(walk).reject()
(False, True)
>>> adf(noise).reject(), kpss(noise).reject()
(True, False)
>>> test = adf(walk)
>>> test.lower_tail, test.trend, test.method, test.break_index
(True, 'c', 'aic (max 15)', None)

A test known only through its table has no p-value and reads the level it is asked for from the table:

>>> test = dfgls(walk)
>>> test.pvalue, test.reject(alpha=0.05)
(None, False)

Private methods#

_metadata()

Header lines: null, trend, lags, method, observations, and the break when there is one.

_repr_fields()

The extra pieces of the one-line repr: null, trend, lags.