statsmodels.tsa.stattools.kpss#

statsmodels.tsa.stattools.kpss(x, regression='c', nlags='auto', store=False, *, result_object=None)[source]#

Kwiatkowski-Phillips-Schmidt-Shin test for stationarity

Computes the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test for the null hypothesis that x is level or trend stationary.

Parameters:
xarray_like, 1d

The data series to test.

regression{“c”, “ct”}

The null hypothesis for the KPSS test.

  • “c” : The data is stationary around a constant (default).

  • “ct” : The data is stationary around a trend.

nlags{str, int}, optional

Indicates the number of lags to be used. If “auto” (default), lags is calculated using the data-dependent method of Hobijn et al. (1998). See also Andrews (1991), Newey & West (1994), and Schwert (1989). If set to “legacy”, uses int(12 * (n / 100)**(1 / 4)), as outlined in Schwert (1989).

storebool

If True, then a result instance is returned additionally to the KPSS statistic (default is False).

result_objectbool, optional

Flag indicating whether to return the results as a KPSSResult instead of a plain tuple. If None (the default), the current tuple-returning behavior is used and a FutureWarning is issued.

Deprecated since version 0.15.0: In release 0.16.0 or after July 2027, whichever is later, the default will change to always return a KPSSResult. Set result_object=True to opt in now, or result_object=False to silence the warning and keep the current return type.

Returns:
KPSSResult

If result_object=True, a result object with fields statistic, pvalue, lags, crit, and resstore (resstore is None when not computed). See KPSSResult.

Otherwise (the deprecated default), a plain tuple made up of:
statisticfloat

The KPSS test statistic.

pvaluefloat

The p-value of the test. The p-value is interpolated from Table 1 in Kwiatkowski et al. (1992), and a boundary point is returned if the test statistic is outside the table of critical values, that is, if the p-value is outside the interval (0.01, 0.1).

lagsint

The truncation lag parameter. Only returned when store=False; when store=True the lag is instead available as resstore.lags.

critdict

The critical values at 10%, 5%, 2.5% and 1%. Based on Kwiatkowski et al. (1992).

resstoreinstance of ResultsStore

Only returned when store=True (and, in that case, in place of lags). An instance of a dummy class with results attached as attributes.

Notes

To estimate sigma^2 the Newey-West estimator is used. If lags is “legacy”, the truncation lag parameter is set to int(12 * (n / 100) ** (1 / 4)), as outlined in Schwert (1989). The p-values are interpolated from Table 1 of Kwiatkowski et al. (1992). If the computed statistic is outside the table of critical values, then a warning message is generated.

Missing values are not handled.

See the notebook Stationarity and detrending (ADF/KPSS) for an overview.

References

[1]

Andrews, D.W.K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59: 817-858.

[2]

Hobijn, B., Frances, B.H., & Ooms, M. (2004). Generalizations of the KPSS-test for stationarity. Statistica Neerlandica, 52: 483-502.

[3]

Kwiatkowski, D., Phillips, P.C.B., Schmidt, P., & Shin, Y. (1992). Testing the null hypothesis of stationarity against the alternative of a unit root. Journal of Econometrics, 54: 159-178.

[4]

Newey, W.K., & West, K.D. (1994). Automatic lag selection in covariance matrix estimation. Review of Economic Studies, 61: 631-653.

[5]

Schwert, G. W. (1989). Tests for unit roots: A Monte Carlo investigation. Journal of Business and Economic Statistics, 7 (2): 147-159.