Skip to content
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

Bug in adfuller test and a suggested fix #86442

Closed
gyllila mannequin opened this issue Nov 6, 2020 · 2 comments
Closed

Bug in adfuller test and a suggested fix #86442

gyllila mannequin opened this issue Nov 6, 2020 · 2 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@gyllila
Copy link
Mannequin

gyllila mannequin commented Nov 6, 2020

BPO 42276
Nosy @ronaldoussoren

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-11-06.12:54:02.207>
created_at = <Date 2020-11-06.12:44:20.321>
labels = ['3.8', 'type-bug', 'library']
title = 'Bug in adfuller test and a suggested fix'
updated_at = <Date 2020-11-06.12:54:02.204>
user = 'https://bugs.python.org/gyllila'

bugs.python.org fields:

activity = <Date 2020-11-06.12:54:02.204>
actor = 'ronaldoussoren'
assignee = 'none'
closed = True
closed_date = <Date 2020-11-06.12:54:02.207>
closer = 'ronaldoussoren'
components = ['Library (Lib)']
creation = <Date 2020-11-06.12:44:20.321>
creator = 'gyllila'
dependencies = []
files = []
hgrepos = []
issue_num = 42276
keywords = []
message_count = 2.0
messages = ['380446', '380447']
nosy_count = 2.0
nosy_names = ['ronaldoussoren', 'gyllila']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42276'
versions = ['Python 3.8']

@gyllila
Copy link
Mannequin Author

gyllila mannequin commented Nov 6, 2020

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

@gyllila gyllila mannequin added type-feature A feature request or enhancement 3.8 only security fixes stdlib Python modules in the Lib dir labels Nov 6, 2020
@ronaldoussoren
Copy link
Contributor

Statsmodel is not part of the Python standard library.

The issue tracker for this packages seems to be at: https://github.com/statsmodels/statsmodels/issues

@ronaldoussoren ronaldoussoren added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Nov 6, 2020
@ronaldoussoren ronaldoussoren added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Nov 6, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant