Repository navigation
Description
Describe the bug
The coint_johansen module specifies:
k_ar_diff (int, nonnegative) – Number of lagged differences in the model.
So k_ar_diff = 0 is a possible value and means that the VECM model looks like
Delta y_t = \Pi * y_t + noise.
However coint_johansen seems it doesn't work if k_ar_diff = 0. For example, the following code gives an error:
import pandas as pd
import numpy as np
from statsmodels.tsa.vector_ar.vecm import coint_johansen
Xreturns = np.random.normal(0, 1, 1000)
X = pd.Series(np.cumsum( Xreturns))
noise1 = np.random.normal(0, 1, 1000)
noise2 = np.random.normal(0, 1, 1000)
Y = X + 5 + noise1
data=pd.concat([X, Y], axis=1)
result = coint_johansen(data, det_order = -1, k_ar_diff = 0)
ValueError: shapes (2,0) and (999,2) not aligned: 0 (dim 1) != 999 (dim 0)
It also gives error if det_order = 0 or det_order = 1.
Output of import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.6.7.final.0
OS: Linux 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64
byteorder: little
LC_ALL: None
LANG: es_AR.UTF-8
Statsmodels
Installed: 0.9.0 (/home/patricia/anaconda3/lib/python3.6/site-packages/statsmodels)
Required Dependencies
cython: 0.27.3 (/home/patricia/anaconda3/lib/python3.6/site-packages/Cython)
numpy: 1.14.3 (/home/patricia/anaconda3/lib/python3.6/site-packages/numpy)
scipy: 0.19.1 (/home/patricia/anaconda3/lib/python3.6/site-packages/scipy)
pandas: 0.23.4 (/home/patricia/anaconda3/lib/python3.6/site-packages/pandas)
dateutil: 2.6.1 (/home/patricia/anaconda3/lib/python3.6/site-packages/dateutil)
patsy: 0.5.0 (/home/patricia/anaconda3/lib/python3.6/site-packages/patsy)
Optional Dependencies
matplotlib: 2.1.2 (/home/patricia/anaconda3/lib/python3.6/site-packages/matplotlib)
backend: module://ipykernel.pylab.backend_inline
cvxopt: Not installed
joblib: Not installed
Developer Tools
IPython: 6.2.1 (/home/patricia/anaconda3/lib/python3.6/site-packages/IPython)
jinja2: 2.10 (/home/patricia/anaconda3/lib/python3.6/site-packages/jinja2)
sphinx: 1.6.6 (/home/patricia/anaconda3/lib/python3.6/site-packages/sphinx)
pygments: 2.3.1 (/home/patricia/anaconda3/lib/python3.6/site-packages/pygments)
nose: 1.3.7 (/home/patricia/anaconda3/lib/python3.6/site-packages/nose)
pytest: 3.3.2 (/home/patricia/anaconda3/lib/python3.6/site-packages)
virtualenv: Not installed
Activity
kisbye commentedon May 24, 2019
Hi:
Lines 644 and forward in vecm module are:
lx = endog[:-k_ar_diff]
lx = lx[1:]
dx = detrend(lx, f)
rkt = resid(dx, z) # level on lagged diffs
So, if k_ar_diff is iqual to zero, then lx is an empty vector and it raises an error.
BUG: Ensure coint_johansen runs with 0 lags
BUG: Ensure coint_johansen runs with 0 lags
bashtage commentedon May 24, 2019
Fix is in #5783
BUG: Ensure coint_johansen runs with 0 lags