Skip to content

ENH: sign convention for hessian_factor #4714

Open

Description

@josef-pkt

I'm getting confused about the sign of hessian_factor.

I was adding hessian factor to discrete so that hessian = sum_i(hessian_factor_i * outer(exog_i)), in an upcoming PR

However, GLM hessian_factor has the opposite sign
hessian =

factor = self.hessian_factor(params, scale=scale, observed=observed)
hess = -np.dot(self.exog.T * factor, self.exog)

I don't remember why GLM has that sign. The only reason that I can think of is so that hessian_factor is positive. My guess this came from SPSS.

The recently merged score_test assumes that the GLM definition prevails and raises with a opposite sign Poisson.

Activity

  1. added this to the 0.10 milestone on Jun 5, 2018
  2. thequackdaddy commented on Jun 5, 2018

    @thequackdaddy
    Member

    This may be related, but we have differing signs for hessian and score when you are using newton vs other optimizers

    if method == 'newton':

  3. josef-pkt commented on Jun 5, 2018

    @josef-pkt
    MemberAuthor

    I guess it's (generalized) linear model versus generic MLE. In the first case the tradition is to use (h x'x)^{-1} for cov_params which is the negative hessian and the negative got absorbed in hessian_factor, we add it back for computing hessian, and reverse it again for minimizing negative loglikelihood.

    I prefer to have a consistent generic MLE definition but then we need to change every use of current GLM hessian.

  4. josef-pkt commented on Jun 5, 2018

    @josef-pkt
    MemberAuthor

    This may be related, but we have differing signs for hessian and score when you are using newton vs other optimizers

    I guess that might be more related to the definition of the optimizer, i.e. the sign convention used in our home-made "newton" in contrast to the scipy minimizers.
    Our "newton" iteration might have been written for a maximization problem.

  5. jbrockmendel commented on May 13, 2019

    @jbrockmendel
    Contributor

    Is resolving this inconsistency an option? It's affect on the code-base is expanding (#5711)

  6. josef-pkt commented on May 13, 2019

    @josef-pkt
    MemberAuthor

    It cannot be changed in a backwards compatible way, and I'm not sure what the consequences are.
    So reverting the sign is not a quickfix. My guess is that we have the same problem in OLS and similar.

    In GAM I ran also into problems with a factor of 2, e.g. OLS versus MLE objective function, or min sum of squares versus min 0.5 * sum of squares. OLS/WLS moment conditions do not include the 2 for the former.

    The main underlying problem is that estimators based on optimization problems differ from estimators that use first order conditions (moment conditions or estimating equations). The latter are not required to have a fixed sign. e.g. #5674

    bottom line: We need to figure out what the generic patterns should be before fixing existing algorithms.

    For the definition of llf and loglike, we decided to use only the full version and not to drop any terms that are irrelevant in the optimization problem.
    By the same argument we could fix the sign and terms in the score and hessian to be consistent with the optimization problem when there are overlapping cases between optimization and estimating/moment equations.

  7. josef-pkt commented on Oct 31, 2021

    @josef-pkt
    MemberAuthor

    For moment tests and score_test all we need is consistent sign between score and hessian.
    That is sign convention for moment estimators, estimating equations, GMM should be irrelevant for it, as long as those signs are consistent.

    OLS/WLS/GLS has hessian_factor but no score_factor
    hessian_factor was added as part of distributed PR 44e1c72#diff-8cb6b075cf3ba145f963655324052ee2647c3554d9bb80e920ac520c8efe17bc

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