Skip to content

Fix GLMInfluence.hat_matrix_diag method name - #9830

Merged
bashtage merged 3 commits into
statsmodels:mainfrom
EdenRochmanSharabi:fix/glminfluence-hat-matrix-diag-9415
Jul 20, 2026
Merged

bashtage merged 3 commits into
statsmodels:mainfrom
EdenRochmanSharabi:fix/glminfluence-hat-matrix-diag-9415

Conversation

@EdenRochmanSharabi

Copy link
Copy Markdown
Contributor

Fix typo in GLMInfluence.hat_matrix_diag: calls get_hat_matrix() (which does not exist on GLMResults) instead of get_hat_matrix_diag().

The bug is triggered when constructing GLMInfluence directly rather than via GLMResults.get_influence(), since the latter passes hat_matrix_diag to the constructor.

One-line change at outliers_influence.py:1427.

Closes #9415

@bashtage

bashtage commented Jun 8, 2026

Copy link
Copy Markdown
Member

Could you write a test that will hit this line?

# Regression test for GH#9415: GLMInfluence constructed directly
# (without hat_matrix_diag) called get_hat_matrix instead of
# get_hat_matrix_diag, raising AttributeError.
from statsmodels.stats.outliers_influence import GLMInfluence

@Aniketsy Aniketsy Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move import at top level, you can keep this with --L18

from statsmodels.stats.outliers_influence import MLEInfluence

Comment on lines +53 to +55
# Regression test for GH#9415: GLMInfluence constructed directly
# (without hat_matrix_diag) called get_hat_matrix instead of
# get_hat_matrix_diag, raising AttributeError.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about keeping like this ...

# GH#9415: GLMInfluence constructed directly raised AttributeError on cooks_distance

i'll leave this upto you, earlier version is also fine.

@EdenRochmanSharabi

Copy link
Copy Markdown
Contributor Author

Done both, thanks.

@Aniketsy Aniketsy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine 👍 , i think you need to resolve conflicts

Call get_hat_matrix_diag() instead of get_hat_matrix() which does not
exist on GLMResults, raising AttributeError.

Closes statsmodels#9415
Test that GLMInfluence(res) without passing hat_matrix_diag computes
cooks_distance correctly via get_hat_matrix_diag.
@EdenRochmanSharabi
EdenRochmanSharabi force-pushed the fix/glminfluence-hat-matrix-diag-9415 branch from f1c644d to ac7055c Compare June 18, 2026 07:19
from statsmodels.genmod.generalized_linear_model import GLM
from statsmodels.regression.linear_model import OLS
from statsmodels.stats.outliers_influence import MLEInfluence, variance_inflation_factor
from statsmodels.stats.outliers_influence import GLMInfluence, MLEInfluence, variance_inflation_factor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to run isort on this file. CI shows incorrect sorting in linting.

@bashtage
bashtage self-requested a review July 20, 2026 16:01
@bashtage

Copy link
Copy Markdown
Member

Thanks. Will merge and fix anything that crops up on the formatting side.

@bashtage
bashtage merged commit c0bdf61 into statsmodels:main Jul 20, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants