Skip to content

DIckey Fuller test breaks on constant values #8471

Closed

Description

@Fleyderer

Describe the bug

Dickey-Fuller test gives error when testing with constant values.

Code Sample, a copy-pastable example if possible

adfuller(np.full(8, 5.0))

RuntimeWarning: divide by zero encountered in log llf = -nobs2*np.log(2*np.pi) - nobs2*np.log(ssr / nobs) - nobs2

Expected Output

I have expected that this series is stationary

Output of import statsmodels.api as sm; sm.show_versions()

Details

INSTALLED VERSIONS

Python: 3.10.6.final.0
OS: Linux 5.15.0-50-generic #56-Ubuntu SMP Tue Sep 20 13:23:26 UTC 2022 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

statsmodels

Installed: 0.13.2 (/home/michael/.local/lib/python3.10/site-packages/statsmodels)

Required Dependencies

cython: Not installed
numpy: 1.23.3 (/home/michael/.local/lib/python3.10/site-packages/numpy)
scipy: 1.9.2 (/home/michael/.local/lib/python3.10/site-packages/scipy)
pandas: 1.5.0 (/home/michael/.local/lib/python3.10/site-packages/pandas)
dateutil: 2.8.2 (/home/michael/.local/lib/python3.10/site-packages/dateutil)
patsy: 0.5.3 (/home/michael/.local/lib/python3.10/site-packages/patsy)

Optional Dependencies

matplotlib: 3.6.1 (/home/michael/.local/lib/python3.10/site-packages/matplotlib)
backend: module://matplotlib_inline.backend_inline
cvxopt: Not installed
joblib: Not installed

Developer Tools

IPython: 8.5.0 (/home/michael/.local/lib/python3.10/site-packages/IPython)
jinja2: 3.1.2 (/home/michael/.local/lib/python3.10/site-packages/jinja2)
sphinx: Not installed
pygments: 2.13.0 (/home/michael/.local/lib/python3.10/site-packages/pygments)
pytest: Not installed
virtualenv: 20.16.5 (/home/michael/.local/lib/python3.10/site-packages/virtualenv)

Activity

  1. bashtage commented on Oct 27, 2022

    @bashtage
    Member

    The test isn't well defined if the residual variance is 0. Ideally this would be caught and a meaningful exception raised.

  2. athompson1991 commented on Nov 23, 2022

    @athompson1991
    Contributor

    Hi @bashtage and @Fleyderer , I took a swing at this. Full transparency - this is essentially my first time trying to make a contribution to an open source project. I did the TDD process (new failing test, minimal code change to pass test) and pushed the change here:

    https://github.com/athompson1991/statsmodels/tree/issue-8471-dickey-fuller-fix

    It fixes this super specific issue of adfuller(np.full(8, 5.0)) but I'm happy to keep working on the code to generalize it. Let me know what you think about this and if I can/should open a PR or make further code changes.

  3. athompson1991 commented on Nov 24, 2022

    @athompson1991
    Contributor

    Update: Created a pull request: #8537

  4. added a commit that references this issue on Dec 7, 2022
  5. added this to the 0.14 milestone on Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions