Skip to content

Bug when calling GLMInfluence(mdl).cooks_distance with V0.14.4 #9415

Closed

Description

@mango-unchained

Describe the bug

When calculating Cook's distance on GLMs, statsmodels throws an error with this message

'GLMResults' object has no attribute 'get_hat_matrix'

The problem is in line 1358 of \statsmodels\stats\outliers_influence.py. The line reads

return self.results.get_hat_matrix()

But it should read

return self.results.get_hat_matrix_diag()

I updated that line, and everything now works smoothly.

Expected Output

The Cook's distance instead of an error message.

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

Details

INSTALLED VERSIONS

Python: 3.11.7.final.0

statsmodels

Installed: 0.14.4

Required Dependencies

cython: Not installed
numpy: 2.1.2
scipy: 1.14.1
pandas: 2.2.3
dateutil: 2.9.0.post0
patsy: 0.5.6

Optional Dependencies

matplotlib: 3.9.2
backend: module://matplotlib_inline.backend_inline
cvxopt: Not installed
joblib: Not installed

Developer Tools

IPython: 8.28.0
jinja2: 3.1.4
sphinx: Not installed
pygments: 2.18.0
pytest: Not installed
virtualenv: Not installed

Activity

  1. josef-pkt commented on Oct 30, 2024

    @josef-pkt
    Member

    Thanks for reporting,
    strange that this didn't get caught by unit tests.

    Are you creating a GLMInfluence instance directly?

    AFAICS. GLMResults.get_influence() is using the correct get_hat_matrix_diag method.
    The main unit tests are in stats/tests/test_influence
    The test classes use get_influence() results method.

    So, it looks like that code path has no test coverage, i.e. GLMInfluence currently needs hatmatrix diag in __init__.
    Aside: GLMInfluence inherits __init__ from MLEInfluence

  2. added this to the 0.15 milestone on Oct 30, 2024
  3. mango-unchained commented on Oct 30, 2024

    @mango-unchained
    Author

    No worries.

    Yeah, I am creating GLMInfluence instances directly.

  4. added a commit that references this issue on Jun 18, 2026
    c65a98d
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