[issue42276] Bug in adfuller test and a suggested fix
Guo
report at bugs.python.org
Fri Nov 6 07:44:20 EST 2020
New submission from Guo <guoyanling_2000 at yahoo.de>:
from statsmodels.tsa.stattools import adfuller
adf = adfuller(x, regression=‘c’, autolag=‘t-stat’)
Sometimes comes error message:
UnboundLocalError: local variable ‘bestlag’ referenced before assignment
I found the reason: 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 this bug this way: open the file stattools.py and find the lines:
elif method == “t-stat”:
#stop = stats.norm.ppf(.95)
stop = 1.6448536269514722
Then add here following two lines:
bestlag = startlag
icbest = np.abs(results[startlag].tvalues[-1])
This way, the code won’t crash again and t-stat simply uses no lag when there is no significant value
----------
components: Library (Lib)
messages: 380446
nosy: gyllila
priority: normal
severity: normal
status: open
title: Bug in adfuller test and a suggested fix
type: enhancement
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42276>
_______________________________________
More information about the Python-bugs-list
mailing list