Skip to content

BUG: PenalizedMixin GLM, hessian scale handling #5315

Closed

Description

@josef-pkt

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.

Activity

  1. added this to the 0.10 milestone on Oct 9, 2018
  2. josef-pkt commented on Oct 9, 2018

    @josef-pkt
    MemberAuthor

    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.

  3. josef-pkt commented on Oct 9, 2018

    @josef-pkt
    MemberAuthor

    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.)

  4. bashtage commented on Jul 30, 2026

    @bashtage
    Member

    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.

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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions