LinearityTest#
- class cultivars.diagnostics.nonlinearity.LinearityTest(*, statistic, pvalue, name, df, null, alternative, order, delay, nobs, threshold=None, critical_values=None, suggestion=None, companions=())[source]#
Verdict of a test of a linear autoregression against a nonlinear alternative.
The four members share a null, that the AR(\(p\)) is correctly specified, and differ in the alternative they aim at, which the record names. Three are \(F\) tests on an auxiliary regression of the linear model’s residuals \(\hat u_t\) on its regressors and a set of added terms,
\[F = \frac{(SSR_0 - SSR_1) / q}{SSR_1 / (n - k - q)} \;\sim\; F(q,\; n - k - q),\]with \(q\) added terms: cubic products of the lags and the transition variable for Teräsvirta, powers of the fitted values for RESET, and, for Tsay, the arranged autoregression’s predictive residuals regressed on the lags. Hansen’s test alone is a sup statistic, the largest \(F\) over candidate thresholds, whose law has no table because the threshold is unidentified under the null; its p-value and critical values are simulated, it locates the threshold it found, and its
dfisNone. A rejection by Tsay or Hansen says “threshold”; a rejection by Teräsvirta says “smooth transition” and, through the escalation sequence carried ascompanions, which kind; a rejection by RESET says only that something smooth was left in the residual.- Variables:
name – The test.
statistic – The test statistic,
Ffor the regression tests and sup-Ffor Hansen.pvalue – Its p-value.
df –
(numerator, denominator)degrees of freedom of anFreference;Nonefor a simulated law.null – The hypothesis under test.
alternative – What a rejection points to.
order – Autoregressive order of the linear null.
delay – Delay of the transition variable, or
Nonewhere the test has none.nobs – Observations in the auxiliary regression.
threshold – Hansen’s estimated threshold;
Noneotherwise.critical_values – Simulated
{"1%", "5%", "10%"}critical values for Hansen;Noneotherwise.suggestion – Teräsvirta’s model-selection reading,
"LSTAR"or"ESTAR";Noneotherwise.companions – The steps of Teräsvirta’s escalation sequence.
Note
The Teräsvirta record always carries a
suggestion, whether or not linearity is rejected: the rule compares the three escalation p-values and one of them is always smallest. Read it only afterreject()says there is a transition to choose between. The tests are for the conditional mean; neglected conditional heteroskedasticity inflates all four, so run an ARCH test on the linear residuals first and read a rejection here in its light.See also
terasvirta(),tsay(),reset(),hansen_threshold()– the four producers.BDSTest– the independence test that catches any dependence, linear or not.
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.
Example
A two-regime threshold autoregression is caught by all four, each naming its own alternative:
>>> 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() >>> for test in (terasvirta(y, order=1), tsay(y, order=1), ramsey_reset(y, order=1)): ... print(f"{test.name:<11} {test.alternative:<24} {test.df} {test.reject()}") Teräsvirta smooth transition (3, 394) True Tsay threshold (2, 336) True RESET smooth misspecification (2, 395) True >>> test = hansen_threshold(y, order=1, replications=500, seed=0) >>> test.df, test.reject(), bool(abs(test.threshold) < 0.5) (None, True, True)
Attributes#
|
|
|
|
The hypothesis under test, |
|
What a rejection points to. |
|
Autoregressive order \(p\) of the linear null. |
|
Delay \(d\) of the transition variable \(y_{t-d}\), or |
|
Observations in the auxiliary regression, |
|
Hansen's least-squares threshold estimate; |
|
Simulated |
|
Teräsvirta's reading of the escalation sequence; |
|
The escalation steps |
|
from the |
|