adf#
- cultivars.diagnostics.unit_roots.adf(endog, *, trend='c', lags=None, max_lags=None, method='aic')[source]#
Augmented Dickey-Fuller test of a unit root.
The regression
\[\Delta y_t = d_t + \gamma\, y_{t-1} + \sum_{j = 1}^{p} \phi_j\, \Delta y_{t-j} + e_t\]tests \(\gamma = 0\) by the \(t\) ratio on \(y_{t-1}\), read against the Dickey-Fuller law rather than the normal. The augmentation \(p\) absorbs serial correlation in the differences, so that under an ARMA short run the limit still holds (Said & Dickey 1984). When
lagsis not given it is chosen on the common sample that the largest candidate leaves, so the criteria compare like with like; the test itself is then run on the longest sample the chosen augmentation allows. The p-value is MacKinnon’s (1996) response surface, and the critical values its finite-sample ones at the effective sample size.- Parameters:
endog (
ArrayLike) – The series,(T,).trend (
str) –"n","c"or"ct"; the law depends on it.lags (
int|None) – Augmentation lags, at least 0, orNoneto select.max_lags (
int|None) – Largest augmentation under selection; default Schwert’s \(\lfloor 12 (T / 100)^{1/4} \rfloor\).method (
str) –"aic","bic","t-stat"(general-to-specific at 10%) or"maic"(Ng-Perron modified AIC).
- Return type:
- Returns:
The
UnitRootTestnamed"ADF"with MacKinnon’s response-surface p-value and finite-sample critical values;lagsis the augmentation andmethodhow it was chosen.- Raises:
SpecificationError – If the trend, method, or counts are unusable or the sample is too short.
DimensionError – If the series is not one-dimensional.
NumericalError – If the series is not finite or the design is singular.
Note
BIC under-augments against moving-average errors and the test then over-rejects, which is why AIC is the default; the modified AIC is built for the neighbourhood of the null and pays for that with long augmentations on a plainly stationary series. The trend must include every deterministic term the alternative would need: a trending series tested with
trend="c"has no power.See also
kpss()– the complementary test with stationarity under the null.phillips_perron()– the same law with a nonparametric correction in place of the augmentation.dfgls()– the more powerful GLS-detrended version.zivot_andrews()– when the alternative allows a break.
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.
Said, S. E., & Dickey, D. A. (1984). Testing for unit roots in autoregressive-moving average models of unknown order. Biometrika, 71(3), 599-607.
MacKinnon, J. G. (1996). Numerical distribution functions for unit root and cointegration tests. Journal of Applied Econometrics, 11(6), 601-618.
Schwert, G. W. (1989). Tests for unit roots: A Monte Carlo investigation. Journal of Business & Economic Statistics, 7(2), 147-159.
Example
A random walk keeps the null; a stationary AR(1) with a root of 0.9 rejects it at 300 observations:
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> walk = np.cumsum(rng.standard_normal(300)) >>> test = adf(walk) >>> test.reject(), round(test.pvalue, 3), test.trend, test.lags (False, 0.841, 'c', 0) >>> y = np.zeros(300) >>> for t in range(1, 300): ... y[t] = 0.9 * y[t - 1] + rng.standard_normal() >>> test = adf(y) >>> test.reject(), test.method (True, 'aic (max 15)')