Skip to content

Adding a wild cluster bootstrap cov_type to models #8437

Open

Description

@amichuda

Hi! @s3alfisc and I are working on implementing wild cluster bootstrapping into python and we wanted to add it as a pull request to statsmodels. It's still a work in progress, but is there a straightforward way of adding a new cov_type?

Would you be able to tell me which files to look at and which classes to inherit to implement?

I can see that there's a cov_type file in base but not sure if adding to that is enough

Thank you!

Activity

  1. changed the title [-]Adding a new `cov_type` to models[/-] [+]Adding a wild cluster bootstrap `cov_type` to models[/+] on Oct 12, 2022
  2. bashtage commented on Oct 12, 2022

    @bashtage
    Member

    Look in the linear regression code to see how the covariance estimators are defined. It isn't that clean IIRC.

  3. josef-pkt commented on Oct 12, 2022

    @josef-pkt
    Member

    That would be great
    For which model do you want to add the new cov_type?

    some details:
    If you use bootstrapping, then it will not go through the sandwich code.

    The selection and dispatch of robust cov_type methods is in get_robustcov_results
    Those are not fully standardized and there is still some code duplication that never got cleaned up

    For OLS and other linear model, the methods is in class statsmodels.regression.linear_model.RegressionResults

    Most other models (at least outside tsa), like discrete, GLM, use the generic implementation from base,
    base.model.LikelihoodModelResults.__init__ calls function statsmodels.base.covtype.get_robustcov_results

    I just see that GLMResults.__init__ also explicitly calls that function.
    (I guess GLMResults does this because super is called at the beginning, but there is some processing before being able to create the final robust cov_params.)

    If there are model specific cov_types, then they may be included in the fit method,
    for example GLM has adjustments for OIM versus EIM and for excess dispersion, scale different from one in e.g. quasi-Poisson.

  4. amichuda commented on Oct 12, 2022

    @amichuda
    Author

    Great! We're planning on adding it to linearmodels as well ;)

    A cursory glance tells me that if we just add to get_robustcov_results in base that should propagate?

    def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):

    The aim is to apply it to linear models, so OLS and the like. I'm not actually sure about the properties in adding it to likelihood models or non-linear estimators.

    For OLS and other linear model, the methods is in class statsmodels.regression.linear_model.RegressionResults

    I think I can add it here and provisionally to base.get_robustcov_results and see what happens 💥

  5. josef-pkt commented on Oct 12, 2022

    @josef-pkt
    Member

    Write most code outside the classes as in base.covtype so it can be generalized or reused later, and then just add it to
    statsmodels.regression.linear_model.RegressionResults.get_robustcov_results

    For example if cov_type in ['fixed scale', 'fixed_scale']:
    was added specifically and only to the linear Regression models.

    Implementing it only for the linear models will be easier than generically or for other models.
    Recreating a model with different options or data is more fragile in other models because of many different extra keywords used in the XXXModel __init__ across models

  6. josef-pkt commented on Oct 12, 2022

    @josef-pkt
    Member

    quick question

    The wild clusterbootstrap is a residual bootstrap with fixed exog, or do you also randomize over which clusters are included?

  7. s3alfisc commented on Oct 13, 2022

    @s3alfisc
    Contributor

    Hi @josef-pkt and @bashtage , thanks so much for your feedback!

    Indeed, the exogenous variables are fixed in the wild bootstrap. We decided to implement the wild bootstrap instead of a block bootstrap because a) it seems to perform really well in a range of edge cases (e.g. few clusters, wildly different cluster sizes, few treated clusters etc) and b) because it can be implemented in really performant ways.

    The simulation evidence that it works well is (to the best of my knowledge) so far restricted to linear models estimated by OLS - some of the main researchers in the literature do not consider it a good idea to wild (cluster) bootstrap nonlinear models (see e.g. this reply by @droodman here or these slides by MacKinnon, which form a very good introduction to the wild bootstrap.

    We plan to implement a range of new versions of the wild bootstrap, as discussed in the paper by MacKinnon, Nielsen & Webb (2022), which seem to perform even better than the "classical" wild cluster bootstrap as introduced in Cameron et al. As a side product, we might also implement a very fast jackknifed based estimator for CRV3 covariance matrices as described in in yet another paper by MacKinnon, Nielsen and Webb =)

  8. josef-pkt commented on Oct 13, 2022

    @josef-pkt
    Member

    Great,, I'm looking forward to the PR.

    Thanks for the references.
    I will try to catch up with those after the upcoming release. I have not looked at this literature since I implemented the cluster robust sandwiches.

    AFAIR, I have seen only bootstrap with resampling clusters for nonlinear, nongaussian or asymmetric models, GLM, Poisson,...

    Aside to the model under null constraints:
    GLM has fit_constrained by reparameterizing the design matrix. However that is not implemented for OLS, WLS. At the time I implemented fit_constrained, I skipped OLS mainly because of the missing offset option in the linear regression models.

  9. josef-pkt commented on Oct 13, 2022

    @josef-pkt
    Member

    mainly as reference for myself: #2054 seems to be the last time I looked at this

    We should have cluster robust score or lagrange multiplier test which would be the asymptotic competitor to the bootstrap version.
    However, I never tried it out for cluster robust (AFAIR)

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions