-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
statsmodels.tsa.stattools.coint: UnboundLocalError: local variable 'bestlag' referenced before assignment #7014
Comments
I cannot reproduce on 0.12. What version are you using? |
Seems impossible to raise in 0.12. I'm going to close, but please post if you are experiencing this on 0.12. |
It was 0.11.1 I still get the error with 0.12:
ENV:
With random data, coint is fine:
|
Still can't reproduce
|
Ohh, got it
|
Ensure that it is always defined even when all t-stats are small closes statsmodels#7014
Ensure that it is always defined even when all t-stats are small closes statsmodels#7014
Ensure that it is always defined even when all t-stats are small closes statsmodels#7014
Ensure that it is always defined even when all t-stats are small closes statsmodels#7014
I got the same error message for t-stat, however for adfuller, not coint (I did not use coint). Maybe my fix can help you: Open the file stattools.py and find the lines (you can first search for which file contains coint): elif method == “t-stat”: Then add here following two lines: This way, the code won’t crash again and t-stat simply uses no lag when there is no significant value. What caused this issue? The reason is when using t-stat, bestlag is only assigned, when the last lag becomes significant the first time, so if no lag has a significant t-value, then bestlag is never assigned. I fixed it by first assigning no lag as default to bestlag, then the remaining code would update the values whenever a significant t-value is found. Hope it helps. |
@gyllila
The idea being that if np.abs(icbest) is never >= stop it at least has the init value. |
Exactly. Though, this is just a suggestion, you don’t have to do it the same way. In some earlier replies someone mentioned to change autolag, which sounds also to be a good solution, maybe better than mine. Anyway: does coint now work after adding the two lines? |
Ensure that it is always defined even when all t-stats are small closes statsmodels#7014
Describe the bug
If bestlag=0 and autolag='t-stat' an UnboundLocalError results.
If bestlag is >0 and autolag='t-stat' results are normal.
An assert or Warning might be nice.
Code Sample, a copy-pastable example if possible
Oddly, this:
does not throw an error, but the same args with real accelerometer time series data does.
Expected Output
I'd expect a Warning or AssertionError
Output of
import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.8.2.final.0
statsmodels
Installed: 0.11.1 (C:\Python38\lib\site-packages\statsmodels)
Required Dependencies
cython: Not installed
numpy: 1.19.0 (C:\Python38\lib\site-packages\numpy)
scipy: 1.4.1 (C:\Python38\lib\site-packages\scipy)
pandas: 1.0.3 (C:\Python38\lib\site-packages\pandas)
dateutil: 2.8.1 (C:\Python38\lib\site-packages\dateutil)
patsy: 0.5.1 (C:\Python38\lib\site-packages\patsy)
Optional Dependencies
matplotlib: 3.2.0 (C:\Python38\lib\site-packages\matplotlib)
backend: TkAgg
cvxopt: Not installed
joblib: 0.14.1 (C:\Python38\lib\site-packages\joblib)
Developer Tools
IPython: 7.15.0 (C:\Python38\lib\site-packages\IPython)
jinja2: 2.11.2 (C:\Python38\lib\site-packages\jinja2)
sphinx: Not installed
pygments: 2.6.1 (C:\Python38\lib\site-packages\pygments)
pytest: Not installed
virtualenv: Not installed
The text was updated successfully, but these errors were encountered: