Skip to content

ENH: sandwich cov_type code without symmetry of hessian #8789

Open

Description

@josef-pkt

I never checked whether the generic sandwich code (based on score_obs/momcond and hessian/momcond_deriv is correct for asymmetric hessians.
Do we use the correct transposition of the (inverse) hessian?

I guess there are no unit test for that.

We get asymmetric "hessian" in GMM, conditional moment tests, GEE, RLM , ..., if those are based on moment conditions that do not come from a single objective function (like loglike).
e.g. M-estimator that start with moment conditions and not we a single objective function. (nonlinear robust model with separately specified moment condition for variance)
Also two-stage models have asymmetric derivatives of score_obs, Murphy/Topel and general versions of it (*)

Current GMM does not yet reuse the generic cov_type code.
Current conditional moment tests (CMT) also don't use generic cov_type code.
score_test uses cov_params and symmetric hessian based on the unrestricted loglikelihood but the cov of the null hypothesis restrictions is based on the CMT code.

(*)
Zero-inflated models are not two-stage model, there is one loglikelihood function for both components.
Hurdle model is currently implemented with two separate models, but parameters are independent across submodels, hessian and cov(score) are block-diagonal.

Activity

  1. added this to the 0.15 milestone on Apr 12, 2023
  2. josef-pkt commented on Apr 12, 2023

    @josef-pkt
    MemberAuthor

    code looks correct, just needs checking that there are unit tests
    statsmodels\stats\tests\test_sandwich.py (which does not have many unit test) does not fail when I remove the transpose. All (or almost all) applications including their unit tests will be for symmetric hessian.

    all sandwiches are computed using _HCCM2 which has the correct transpose

    def _HCCM2(hessian_inv, scale):
    
        if scale.ndim == 1:
            scale = scale[:,None]
    
        xxi = hessian_inv
        H = np.dot(np.dot(xxi, scale), xxi.T)
        return H
    
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