cultivars.diagnostics#

Diagnostics: what a series is before a model is fitted, and what a fit left behind.

A time-series model is a set of claims about the data, and the diagnostics are how those claims are checked. They are read in the order a specification is built. Whether a series carries a stochastic trend decides between a level model, a difference, and a cointegrating system (unit_roots); whether its seasonal pattern is fixed or wandering decides between dummies and a seasonal difference (seasonality); when several integrated series are in hand, how many stationary combinations they share decides the rank of the error-correction model (cointegration); whether a series has long memory refines the integer question of a unit root into a fractional one (long_memory); whether one regression held over the whole sample, or broke, and where (breaks); and whether a linear autoregression is wrong in the specific way a threshold or smooth-transition model would fix (nonlinearity). Underneath them all is one record type (hypothesis), so that a study which collects a dozen verdicts holds one kind of object with one reject and one summary, and the tests a fitted model runs on its own residuals, Granger causality, portmanteau, normality, ARCH, return the same records from the result rather than from here.

The package has one rule that every module keeps: the null distribution is the one the test needs. Where the literature supplies a response surface or a dense table the p-value is read from it; where a limit is a functional of Brownian motion with no table at the trimming, period, or dimension in hand, the limit is simulated at the values in hand; where only three asymptotic critical values exist the record carries them and no p-value, and refuses a level it does not have. A verdict never comes from a distribution that is merely nearby.

Each module is a leaf: names are imported from the module, not from this package, and every producer takes the series and the specification it needs, fitting any auxiliary regression inside, so the null is always exactly what the docstring says it is.

Layout. hypothesis names the records, HypothesisTest and its TabulatedTest, ChiSquaredTest, WaldTest, and LikelihoodRatioTest. unit_roots is the Dickey-Fuller line, KPSS, and Zivot-Andrews with the UnitRootTest record; seasonality is HEGY and Canova-Hansen; cointegration is the public home of the Johansen rank record the error-correction models produce; long_memory is GPH, local Whittle, and exact local Whittle; breaks is the Andrews, Bai-Perron, and CUSUM tests; and nonlinearity is Teräsvirta, Tsay, RESET, Hansen, and BDS. Convergence diagnostics for a sampler’s draws live with the Bayesian workflow in chains, and forecast-comparison tests with the forecast evaluation in comparison.

Example

Classify a series before modelling it: integrated at the zero frequency, with a stable seasonal pattern, and no break:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.cumsum(rng.standard_normal(200)) + np.tile([1.0, -0.5, 2.0, -2.5], 50)
>>> unit_roots.adf(y).reject(), unit_roots.kpss(y).reject()
(False, True)
>>> root = seasonality.hegy(y, period=4, replications=500, seed=0)
>>> root.reject(), all(c.reject() for c in root.companions)
(False, True)
>>> breaks.sup_wald(np.diff(y), seed=0).reject()
False

Modules#

breaks

Structural-break tests: whether one regression held over the whole sample.

cointegration

Cointegration rank: the Johansen trace and maximum-eigenvalue sequences.

hypothesis

Hypothesis-test records: one statistic, one p-value, one verdict, one table.

long_memory

Semiparametric long memory: the differencing parameter without a short-run model.

nonlinearity

Nonlinearity gateways: the tests that justify a regime model before it is fit.

seasonality

Seasonal unit roots: is the seasonal pattern deterministic, or does it wander?

unit_roots

Unit-root and stationarity tests: the question every model in the package asks first.