Repository navigation
Added kpss test - #2749
Added kpss test#2749N-Wouda wants to merge 44 commits into
Conversation
Added a KPSS test for level/trend stationarity. Largely based on the R implementation in tseries.
Turned the critical values to a dict, like in `adfuller()`
Just `l` was an unclear variable name.
|
I think KPSS would be a nice addition to Statsmodels. Unless I'm missing something, though, I think this couldn't be included because the tseries library is GPL licensed (see https://cran.r-project.org/web/packages/tseries/index.html) which is incompatible with the Statsmodels license. |
|
@ChadFulton I could do the dirty work of going back to the original paper by Kwiatkowski et al. and refactor everything. There's not much to a KPSS test: the final result of such a refactoring will not deviate substantially from this format (although it will be rewritten completely independently of the R code, so it can be under any license we like). If you want me to, I'm not opposed to just doing so. It will not be that hard, at most a couple of hours worth of work :). |
|
Unfortunately, I think that rewriting would be necessary - I appreciate the work you've already put into this. @josef-pkt is rewriting sufficient to satisfy licensing problems? |
|
@ChadFulton already pulled the paper via my university. I'll get to it this weekend, depending on @josef-pkt's reply! |
See comment in #2749.
|
@ChadFulton @josef-pkt I have completely reworked the test, so this should be fine. I am still somewhat unhappy with two things: (1) the flag parameter, indicating whether the p-value is within the range of critical values (as the kpss statistic is interpolated to obtain a p-value), and (2) the lag selection. About the flag parameter: should I raise a warning if the statistic is more extreme than the critical values? Or just leave it at this? About the lag selection: I could probably hijack |
|
Thanks, I'll take a closer look at the code soon. In the meantime, it would be good to add some unit tests against known results. To get the known results, it is acceptable to use the output of the R routines (even though we couldn't port their code). |
Been a while since I lost wrote a few of these. May not work; will rewrite if not.
Made an incredibly stupid typo when pushing to brach. Fixed now.
|
@ChadFulton done! Results should be coming in after the Travis build. Tests run fine on my machine, but the first few builds are going to fail: I accidentally pushed a typo into my local branch.. Latest commit should address these issues and build/test just fine. |
There was a problem hiding this comment.
Is this the same as if nobs != x.size:?
There was a problem hiding this comment.
You are absolutely correct. No idea why I took this approach. Will push a revision!
There was a problem hiding this comment.
This needs a note in the current version that pvalues are truncated, i.e. report boundary points if pvalue < 0.01 or > 0.1, and interpolates.
|
@josef-pkt That just leaves us with the argument-consistency. Would you rather have me call it Other than that, thank you for checking my work! I already updated it, and the Travis results should be coming in in a short while. |
|
about I will be offline for some time today, the main thing is to work towards consistent argument names, instead of introducing another name. I remembered |
|
@josef-pkt would you be ok with using the |
|
consistency with adfuller looks good If autolag will be used, then lags should also be made consistent with adfuller. I haven't looked at any recommendations for KPSS. Can you squash the commits? |
Added a KPSS test for level/trend stationarity. Largely based on the R implementation in tseries. Added kpss test to docs Small update to __all__ Update stattools.py Update stattools.py Added authors Update stattools.py Update stattools.py Update stattools.py Update stattools.py Update stattools.py Turned the critical values to a dict, like in `adfuller()` Minor update to kpss() Renamed parameter `l` to `lags` Just `l` was an unclear variable name. Reworked the entire test as discussed See comment in #2749. Update stattools.py
Been a while since I lost wrote a few of these. May not work; will rewrite if not. Update test_stattools.py Updated unit test Made an incredibly stupid typo when pushing to brach. Fixed now. Update test_stattools.py Update test_stattools.py Added R-code to docstring x.size rather than involved approach Update tsa.rst Raise warning for out of bounds interpolation of test statistic Removed `flag` from tests Test for warning Update test_stattools.py Update test_stattools.py Rewrote some of the docstring Updated based on Josef's comments Updated to take into account resstore Update test_stattools.py Changed null_hypo argument to regression Updated regression argument in tests Statsmodels style ** Found another `**` padded by spaces. Update test_stattools.py Update test_stattools.py Update stattools.py
|
@josef-pkt I absolutely suck at git; it is really not my cup of tea (and I do think I screwed up a bit just yet). I could just open a new PR with the final result of this one, reference this and keep it simple? Sorry for making such a mess of things in this PR, I do feel bad about that! |
Yes, you could do that, at least it's standard.
That's no reason to feel bad. We all have been there, and it takes quite a bit of time to go beyond simple commits in git. (I'm using git gui for most of my regular work, I know a few git commands on the command line, for the rest I have to reread the manual each time.) |
|
@josef-pkt I will just open a new PR then.
I actually tried this, but I probably did something wrong. Not sure what though, I will read up on the manual a bit more. |
Added an implementation of the Kwiatkowski–Phillips–Schmidt–Shin (KPSS) test to
tsa.stattools.