Skip to content

clone method, information to reconstruct model, results #1093

Open

Description

@josef-pkt

see #1841 for duplicate issue with notes/comments by Kerby

just an idea for some use cases

  • llnull currently used in some models in summary for likelihood ratio test
    for example Poisson
  • bootstrap attached as a method: conditional on exog: we would like to get a new instance of the model that we can reuse internally for running bootstrap replication.
    We need to be able to clone, recreate a new instance of the model and then refit with new endog. Simple in OLS when we just have endog and exog. but we might need more information about what the user used in the signature in some models (if we want to write generic code).
  • results with robust cov_params: (my latest thought on design)
    make it possible for users to specify which cov_params to use and all statistics in the results instance are based on this cov_params. Instead of changing cov_params in the given result instance, we create and return a new result instance.
  • diagnostic tests example link-test see diagnostic: link test - nonlinearity test for many model  #1479 (with comments)

data meta information about original model

If we want to get the original names and possibly row names or row indices, then we also need access to that information. I don't know how that works.
The use cases above are for internal use of a cloned model.
A case for getting the original names of the DataFrame see https://github.com/statsmodels/statsmodels/pull/1529/files#diff-b7b680f28b6de7c43a2dc7afb511f1c4R99

Activity

  1. josef-pkt commented on Apr 18, 2014

    @josef-pkt
    MemberAuthor

    Does llnull work with NegativeBinomial? - check

    A not supported example:

    I set a dynamic attribute in a subclass of Poisson that should go either as keyword in model.__init__ or model.fit. Currently summary breaks on trying to calculate llnul using a new model instance that doesn't have the attribute.

  2. josef-pkt commented on Apr 19, 2014

    @josef-pkt
    MemberAuthor

    see #1221 llnull call doesn't take anything extra into account

        @cache_readonly
        def llnull(self):
            model = self.model
            #TODO: what parameters to pass to fit?
            null = model.__class__(model.endog, np.ones(self.nobs)).fit(disp=0)
            return null.llf
    
  3. josef-pkt commented on Apr 19, 2014

    @josef-pkt
    MemberAuthor

    proposal to get started with generic solution

    add initkeys attribute, with just a list of keys not full dictionary (to avoid extra references to full length data for remove_data)

  4. josef-pkt commented on Apr 24, 2014

    @josef-pkt
    MemberAuthor

    I had already use a different solution for bootstrap

    setting registered attributes directly (setattr) instead of going through the __init__ kwds
    https://github.com/statsmodels/statsmodels/blob/master/statsmodels/base/model.py#L1591
    This is more flexible in attaching additional attributes but might incorrectly skip some initialization code. (for example it would set the transformed exposure instead of the solution in #1609)

  5. josef-pkt commented on Jun 1, 2014

    @josef-pkt
    MemberAuthor

    GLM doesn't work yet because it doesn't have family in _init_keys

    appending works from me (from the outside in an example)

            formula = 'deaths ~ smokes + C(agecat)'
            mod = GLM.from_formula(formula, data=data,
                                        family=families.Poisson(),
                                        offset=np.log(data['pyears'].values))
            mod._init_keys.append('family')
    

    I don't remember how offset and exposure are correctly added, but they are returned in _get_init_kwds

    @kshedden still some changes to do to get all keywords for recreating a class.

    I'm recreating the class for GLM.fit_constrained.

  6. josef-pkt commented on May 12, 2015

    @josef-pkt
    MemberAuthor

    This is largely implemented for recreating models with _init_kwds.

    TODO: check test coverage, models where this doesn't work (or is not needed yet)?

    I'm opening a new issue specifically for (re)creating results instances, #2393

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