arch.unitroot.KPSS¶
-
class arch.unitroot.KPSS(y: ndarray | DataFrame | Series, lags: int | None =
None, trend: 'c' | 'ct' ='c')[source]¶ Kwiatkowski, Phillips, Schmidt and Shin (KPSS) stationarity test.
- Parameters:¶
- y: ndarray | DataFrame | Series¶
The data to test for stationarity.
- lags: int | None =
None¶ The number of lags to use in the Newey-West estimator of the long-run covariance. If omitted or None, the number of lags is calculated with the data-dependent method of Hobijn et al. (1998). See also Andrews (1991), Newey & West (1994), and Schwert (1989). Set lags=-1 to use the old method that only depends on the sample size, 12 * (nobs/100) ** (1/4).
- trend: 'c' | 'ct' =
'c'¶ The trend component to include in the test. Not case sensitive.
”c” - Include a constant
”ct” - Include a constant and linear time trend
- Raises:¶
TypeError – If y cannot be converted to numbers, lags is not an integer or None, or trend is not a str.
ValueError – If y is not 1-d or contains NaN or inf, lags is less than -1, or trend is not one of the options.
InfeasibleTestException – If y has too few observations for trend, or lags (the number from the rule 12 * (nobs/100) ** (1/4) if it is -1) is larger than the number of observations in y. This is also a
ValueError.
Notes
The null hypothesis of the KPSS test is that the series is weakly stationary and the alternative is that it is non-stationary. If the p-value is above a critical size, then the null cannot be rejected and the series appears stationary.
The p-values and critical values were computed using an extensive simulation based on 100,000,000 replications using series with 2,000 observations. See [3] for the initial description of the KPSS test. Further details are available in [2] and [5]. Details about the long-run covariance estimation can be found in [1] and [4].
References
Examples
>>> from arch.unitroot import KPSS >>> import numpy as np >>> import statsmodels.api as sm >>> data = sm.datasets.macrodata.load().data >>> inflation = np.diff(np.log(data["cpi"])) >>> kpss = KPSS(inflation) >>> print(f"{kpss.stat:0.4f}") 0.3916 >>> print(f"{kpss.pvalue:0.4f}") 0.0761 >>> kpss = KPSS(inflation, trend="ct") >>> print(f"{kpss.stat:0.4f}") 0.2802 >>> print(f"{kpss.pvalue:0.4f}") 0.0026Methods
summary()Summary of test, containing statistic, p-value and critical values.
Properties
The alternative hypothesis.
The critical values of the test.
The number of lags used in the model.
The number of observations used when computing the test statistic.
The null hypothesis.
The p-value for the test statistic.
The test statistic for a unit root.
The deterministic trend term used in the test.
List of valid trend terms.
The data used in the test statistic.