cultivars.diagnostics.nonlinearity#

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

A threshold or smooth-transition model is a claim that a linear autoregression is wrong in a specific way, and the claim should be tested on the linear model’s own terms before the nonlinear one is estimated. The difficulty every such test meets is that the parameters of the alternative, the threshold or the transition’s location and speed, are not identified under the null, so a likelihood ratio has no chi-squared limit and each test finds its own way around that. Four do so from different directions. Teräsvirta’s LM test replaces the transition function by its Taylor expansion, so the alternative becomes the cubic auxiliary regression

\[\hat u_t = \beta_0^\top w_t + \sum_{i = 1}^{p} \sum_{j = 1}^{3} \beta_{ji}\, y_{t-i}\, y_{t-d}^{\,j} + e_t,\]

whose exclusion restriction is an ordinary \(F\) test, and it carries a device for choosing between logistic and exponential transitions. Tsay’s arranged autoregression sorts the sample by the threshold variable and asks whether the recursive predictive residuals drift as the recursion crosses a threshold; it names no functional form. Hansen’s sup-F is the likelihood-ratio test of a SETAR against its linear restriction, the sup taken over candidate thresholds, whose p-value is simulated from fixed-regressor draws because the sup has no tabulated law. Ramsey’s RESET is the general-purpose check that the linear fit has left a smooth function of itself in the residual. The BDS statistic is the odd one out: applied to residuals, it tests independence against any dependence at all, linear or not, and rejects for neglected conditional heteroskedasticity as readily as for a threshold, which is why it is read after an ARCH test and not instead of one.

Two commitments shape the surface. First, a rejection says what it rejects toward. Every LinearityTest names its alternative, the Teräsvirta record carries the escalation sequence that chooses the transition, and the Hansen record carries the threshold it found, so a reader who gets four verdicts on one series can tell a threshold from a smooth transition from a misspecification with no regime in it. Second, the reference distribution is the one the test needs and not a convenient stand-in: the \(F\) form where the chi-squared over- rejects at the sample sizes these tests meet, a simulated sup where no table exists, and, for BDS, a size warning on the record itself below the sample length at which the normal reference holds.

All five take a series, not residuals from a fit the caller has already made: the linear autoregression of the stated order is fitted inside each test, so the null is always the AR(\(p\)) and the degrees of freedom are always right. The BDS test is the exception and takes whatever it is given, usually standardized residuals.

Layout. LinearityTest is the record for the four model-aimed tests and BDSTest for the independence test, both HypothesisTest records with reject and a summary. terasvirta(), tsay(), ramsey_reset(), hansen_threshold(), and bds() are the producers, sharing _validate_specification for the sample-length check. The numerics live in _core: _terasvirta_lm runs the cubic auxiliary regression and the escalation steps, _tsay_arranged the sorted recursion, _reset_test the augmented regression, _hansen_threshold the grid search and fixed-regressor simulation, _bds the correlation integrals, and _simulated_critical_values turns Hansen’s draws into critical values; the trimming, grid, replication, and radius defaults are the module’s named constants.

References

Teräsvirta, T. (1994). Specification, estimation, and evaluation of smooth transition autoregressive models. Journal of the American Statistical Association, 89(425), 208-218.

Tsay, R. S. (1989). Testing and modeling threshold autoregressive processes. Journal of the American Statistical Association, 84(405), 231-240.

Hansen, B. E. (1996). Inference when a nuisance parameter is not identified under the null hypothesis. Econometrica, 64(2), 413-430.

Ramsey, J. B. (1969). Tests for specification errors in classical linear least-squares regression analysis. Journal of the Royal Statistical Society B, 31(2), 350-371.

Brock, W. A., Dechert, W. D., Scheinkman, J. A., & LeBaron, B. (1996). A test for independence based on the correlation dimension. Econometric Reviews, 15(3), 197-235.

Davies, R. B. (1987). Hypothesis testing when a nuisance parameter is present only under the alternative. Biometrika, 74(1), 33-43.

Teräsvirta, T., Tjøstheim, D., & Granger, C. W. J. (2010). Modelling Nonlinear Economic Time Series. Oxford University Press.

Example

A two-regime threshold autoregression: the model-aimed tests reject linearity and Hansen locates the threshold. An ARCH series, which has no regime in its mean, is invisible to Tsay and caught by BDS, the division of labour the module is built around:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros(400)
>>> for t in range(1, 400):
...     slope = 0.8 if y[t - 1] < 0.0 else -0.5
...     y[t] = slope * y[t - 1] + rng.standard_normal()
>>> tsay(y, order=1).reject(), terasvirta(y, order=1).reject()
(True, True)
>>> verdict = hansen_threshold(y, order=1, replications=500, seed=0)
>>> verdict.reject(), bool(abs(verdict.threshold) < 0.5)
(True, True)
>>> e = np.zeros(400)
>>> for t in range(1, 400):
...     e[t] = np.sqrt(0.2 + 0.7 * e[t - 1] ** 2) * rng.standard_normal()
>>> tsay(e, order=1).reject(), bds(e).reject()
(False, True)

Classes#

BDSTest

Verdict of the BDS test of independence at one embedding dimension.

LinearityTest

Verdict of a test of a linear autoregression against a nonlinear alternative.

Functions#

bds(endog, *[, dimension, epsilon])

The BDS test of independence, usually on residuals.

hansen_threshold(endog, *, order[, delay, ...])

Hansen's (1996) sup-F test of a SETAR against its linear restriction.

ramsey_reset(endog, *, order[, powers])

Ramsey's RESET on an autoregression: do powers of the fitted value explain the residual?

terasvirta(endog, *, order[, delay])

Teräsvirta's (1994) LM-type test of linearity against smooth transition.

tsay(endog, *, order[, delay])

Tsay's (1989) arranged-autoregression test of linearity against a threshold.