You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think there is a bug in scale handling in GLM Gaussian using PenalizedMixin.
related to #5296 (comment)
GLM fit sets temporarily scale=1, but then hessian and score_obs for the post-estimation results uses the actual scale from results or recomputed based on scale type.
However in the penalized case, we have
loglike(params, scale=?) + pen_weights * penalty
when results instance computes cov_params, either hessian or a sandwich, then it uses hessian and score_obs based on actual scale, which causes the relative weights of loglike and penalty to change.
There is currently a problem in the unit test comparing GLM-Gaussian to TheilRidge with a difference in bse for penalized params.
However, when I compute the HC sandwich directly using hessian and score_obs based on scale=1, and the use the scale to multiply this normalized_cov_params, then GLM-Gaussian and TheilRidge cov_params agree.
This would be fine for the Gaussian case where hessian and score are multiplicative in scale, but not for families where scale has an additional effect on score and hessian. (There are one or two of those, but I don't remember which families.)
TheilRidge uses the RegressionResult behavior of multiplying normalized_cov_params by the scale where normalized_cov_params is either the unscaled hessian or the unscaled HC0 sandwich.
possible fix:
multiple penalty by scale, if scale is given in kwds.
In that case we leave the relative weights unchanged for whatever scale is used to evaluate loglike and derivatives.
The possible fix doesn't work for GLM because it doesn't use the scale keyword. The scale is selected through the scaletype which has fixed scale or triggers computing the scale with estimate_scale inside the loglike and derivative methods.
Fixed by commit fae6de5, which introduced _handle_scale() in statsmodels/base/_penalized.py so the penalty term is consistently divided by the same scale used in loglike/score/hessian for PenalizedMixin GLM models. Closing as fixed.
Activity
josef-pkt commentedon Oct 9, 2018
The possible fix doesn't work for GLM because it doesn't use the scale keyword. The scale is selected through the
scaletypewhich has fixed scale or triggers computing the scale withestimate_scaleinside the loglike and derivative methods.josef-pkt commentedon Oct 9, 2018
It looks like there is a serious bug in GLM Gaussian scale/cov_params
i.e. normalized_cov_params is divided by scale even though scale is 1 in super.
This should be caught by some unit tests, so something is strange.
(I'm adjusting things during reviewing/figuring out GAM PR, and there is no guarantee that I didn't make a different mistake.)
bashtage commentedon Jul 30, 2026
Fixed by commit fae6de5, which introduced _handle_scale() in statsmodels/base/_penalized.py so the penalty term is consistently divided by the same scale used in loglike/score/hessian for PenalizedMixin GLM models. Closing as fixed.