Johansen test wrongly implemented
Describe the bug
The implementation in the function coint_johansen is simply incorrect when comparing to Johansen's approach. The usage of critical values from his work is therefore incorrect. For a correct implementation, see for example the package called "Johansen".
- One of the first lines in the function code is
endog = detrend(endog, det_order)
This procedure is incorrect and yields wrong test statistic. If one assumes a deterministic (polynomial) trend in the levels, one appends corresponding deterministic terms to the z-array. See the package Johansen for reference. The mapping of "p" in coint_johansen to "model" in Johansen is {-1:0, 0:1,1:3}
- Usage of the variable f. What's the point is de-meaning the variables dx, lx, z?! If one leaves out the lines
z = detrend(z, f) dx = detrend(dx, f) dx = detrend(lx, f)
the resulting variables r0t and rkt will remain unchanged.
Code Sample, a copy-pastable example if possible
# Your code here that produces the bug
# This example should be self-contained, and so not rely on external data.
# It should run in a fresh ipython session, and so include all relevant imports.Note: As you can see, there are many issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates.
Note: Please be sure you are using the latest released version of statsmodels, or a recent build of master. If your problem has been fixed in an unreleased version, you might be able to use master until a new release occurs.
Note: If you are using a released version, have you verified that the bug exists in the master branch of this repository? It helps the limited resources if we know problems exist in the current master so that they do not need to check whether the code sample produces a bug in the next release.
If the issue has not been resolved, please file it in the issue tracker.
Expected Output
A clear and concise description of what you expected to happen.
Output of import statsmodels.api as sm; sm.show_versions()
[paste the output of import statsmodels.api as sm; sm.show_versions() here below this line]
Source: statsmodels/statsmodels