0
$\begingroup$

I have a series with N observation, I want to test the whole series for stationarity with KPSS. However I noticed that when run with all lags, the KPSS test always seems to return the 0.5 value, for example:

import numpy as np
from statsmodels.tsa.stattools import kpss
kpss(np.random.uniform(0,1,100), nlags=99)
(0.499999999999999,
 0.04166666666666689,
 99,
 {'10%': 0.347, '5%': 0.463, '2.5%': 0.574, '1%': 0.739})

I'm surely missing something, my business requirement is to test the series for stationarity in the long period (meaning: the whole series) and in the short period (meaning: i.e. the latest 10 values), so I assumed to run the KPSS test with nlags=N and nlags=10.

Could you help me understanding what I'm getting wrong?

$\endgroup$

1 Answer 1

1
$\begingroup$

nlags in kpss does not take a slice (window) of the time series. Instead, it specifies the autocorrelation structure for the estimation of the covariance matrix in the test. See this for details.

If you want to test for presence of a unit root in a slice (window) of the time series, do the slicing beforehand and then supply the result to the kpss function. Regarding nlags in kpss, keep it as nlags='auto' unless you have some additional information about the autocorrelation structure.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.