Skip to content

ENH: add GLM Margins and supporting helper functions #4751

Closed

Description

@josef-pkt

GEE has margins, although incomplete, see #3704
GLM has nothing related yet.

To compute hatmatrix or, more precisely, generalized leverage for generic MLE that have predict, I need one method d mu / d params, which is in discrete_models used for the margin computations.

GEE has _derivative_exog which is almost the same as _derivative_predict which is needed for margins but not yet in GEE.
GEE has model specific methods that compute with different argument, eg, mean_deriv, which should extend to GLM also.

I need _derivative_predict and similar derivatives in a generic interface, so I don't have to access the link directly.
To go the other way as a generic cross-model pattern see #3915
(e.g. I added the family to Poisson so I have access to the inverse link deriv)

naming: I think we need more explicit names to refere to the function and wrt which variable we take the derivative, e.g.
deriv_predict_params or deriv_mean_params
deriv_mean_exog
deriv_mean_linpred
deriv_score_endog (that's what I also need for generalized leverage)
or maybe another d in there
deriv_mean_dlinpred

(The new count models have many "which" in predict and we need derivatives to be able to get standard errors. It will be similar for other two part models like BetaRegression)

To get the equivalent of DFFITS, I also need deriv_mean_params or derivative_predict
e.g. currently I have it specific to the availability of model.family.link, i.e. GLM, and Poisson for now

    def d_fittedvalues(self):
        # in discrete we cannot reuse results.fittedvalues
        fittedvalues = self.results.predict()
        deriv = self.results.model.family.link.inverse_deriv(fittedvalues)
        return deriv * self.d_linpred

Activity

  1. added this to the 0.10 milestone on Jun 19, 2018
  2. modified the milestones: 0.10, 0.15 on Apr 24, 2023
  3. josef-pkt commented on Apr 24, 2023

    @josef-pkt
    MemberAuthor

    I just realized (again) that GLMResults still does not have get_margeff
    We need it to e.g. compare logit and probit, Binomial with different link functions, params have different scaling and cannot be directly compared.
    see also #8802 for another reason to look at margins in binomial

    If we don't want to support weights in the first version #7341, then we could raise NotImplementedError for non-default weights.

  4. modified the milestones: 0.15, 0.14 on Oct 27, 2023
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