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:
_TabulatedTestVerdict 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=Noneandreject()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
lagswas chosen or the kernel used.break_index – For a break-allowing test, the first observation of the new regime;
Noneotherwise.
Note
lagsmeans two different things across the family, andmethoddisambiguates: an augmentation count for ADF, DF-GLS, Ng-Perron, and Zivot-Andrews, wheremethodnames the selection rule and its ceiling; a kernel bandwidth for Phillips-Perron and KPSS, wheremethodnames the kernel. Ng-Perron’s four statistics travel ascompanionsof the \(MZ_t\) record, since they are one test on one sample.See also
adf(),phillips_perron(),dfgls(),ng_perron(),zivot_andrews()– the unit-root-null producers.kpss()– the stationarity-null producer.SeasonalUnitRootTest– the same record at the seasonal frequencies.TabulatedTest– the base that reads a statistic against critical values.
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#
Header lines: null, trend, lags, method, observations, and the break when there is one. |
|
The extra pieces of the one-line repr: null, trend, lags. |