Skip to content

Should scale and normalized_cov_params be removed from LikelihoodModelResults? #1594

Open

Description

@bashtage

Most likelihood models do not naturally have scale or normalized_cov_params concepts, and these are only applicable to a subset of additive error models.

Some of the applications of these simply fake the result and set normalized_cov_params to the actual covariance of the parameters and scale=1 - it seems to have these as attributes is then misleading.

It would be more natural for the model inheriting from LikelihoodModelResults to provide a covariance estimator if required.

These are only actually used in the following lines,

 if cov_p is None:
            if scale is None:
                scale = self.scale
            if hasattr(self, 'cov_params_default'):
                cov_p = self.cov_params_default
            else:
                cov_p = self.normalized_cov_params * scale

but then derived classes have the attributes scale and normalized_cov_params.

This also appears to have the side effect that cov_params has to be a function rather than just an attribute property, so that the somewhat awkward situation arises where the unfortunate mixed syntax is required

>>> res.params
>>> res.bse
>>> res.tvalues
>>> res.cov_params()

I think the correct behavior is to have the subclass explicitly pass the parameter covariance so that

def __init__(self, model, params, normalized_cov_params=None, scale=1.):

would become

def __init__(self, model, params, cov_params=None):

and then the magic currently in cov_params() will not be required.

The other use of cov_params can be moved to a either a private function or a function that is more appropriately named such as cov_linear_restriction which is what the computational side of cov_params appears to compute.

Activity

  1. changed the title [-]Should 'scale` and `normalized_cov_params` be removed from `LikelihoodModelResults`?[/-] [+]Should `scale` and `normalized_cov_params` be removed from `LikelihoodModelResults`?[/+] on Apr 16, 2014
  2. josef-pkt commented on Apr 16, 2014

    @josef-pkt
    Member

    I'm not sure yet how this should go. This would be a high impact refactoring because it's used across models.

    That cov_params is a method that requires call (), has been bothering me for a long time, but it's a multi-purpose method. My latest thought was to get cov_params_default to store just the covariance_matrix as attribute.

    It's not obvious if merging scale into normalized_cov_params is a good idea:

    In the linear models, scale is actually estimated in the results instance, the __init__ argument is ignored. For GLM, and discrete_models we have models with scale=1 by definition. However, GLM also has families, e.g. Gaussian, where scale is estimated separately. For pseudo- or quasi-MLE we also have scale different from 1.

    for example for my experiments with overdispersed Poisson, I was just adjusting the scale != 1 separately.

    Essentially, plain MLE includes the scale in the Hessian (or equivalent), all other estimators estimate the scale separately.

  3. bashtage commented on Apr 16, 2014

    @bashtage
    MemberAuthor

    In terms of general names, I'm also unsure about bse. The name of the estimated parameters is params which is very generic and doesn't use any domain-specific naming conventions. I would think that either se, std_err or param_se would be preferred. se is probably too short to be clean. If param_se is used then param_cov would be the natural name for these.

    Of it cov_params was kept, then se_params would be a better name.

    I have also been experimenting with making f_test a mixin since it isn't appropriate for almost all non-regression-based models.

  4. bashtage commented on Apr 16, 2014

    @bashtage
    MemberAuthor

    It's not obvious if merging scale into normalized_cov_params is a good idea:

    In the linear models, scale is actually estimated in the results instance, the init argument is ignored. For GLM, and discrete_models we have models with scale=1 by definition. However, GLM also has families, e.g. Gaussian, where scale is estimated separately. For pseudo- or quasi-MLE we also have scale different from 1.

    for example for my experiments with overdispersed Poisson, I was just adjusting the scale != 1 separately.

    Essentially, plain MLE includes the scale in the Hessian (or equivalent), all other estimators estimate the scale separately.

    What I don't see what value having LikelihoodResults aware of this provides, other than a lot of complex code that is really handling things that have nothing to do with LikelihoodResults. This seems to violate the separation of concerns (http://en.wikipedia.org/wiki/Separation_of_concerns) since this routine really contains very specific code that ties into a specific class.

    for example for my experiments with overdispersed Poisson, I was just adjusting the scale != 1 separately.

    Couldn't this be done simply by multiplying the covariance by some number !=1 using an existing results (assuming that was refactored to be ignorant of scale)?

    res = some_model()
    res.cov_params *= 2
    res.t_test....
  5. josef-pkt commented on Apr 16, 2014

    @josef-pkt
    Member

    I have also been experimenting with making f_test a mixin since it isn't appropriate for almost all non-regression-based models.

    Since it's now just delegating to wald_test, we could deprecate it in LikelihoodModelResults and add it only to RegressionResults (and any others that we might get that have use_t=True as default)

    I'm against removing the use_t options for all or generic models. Skipper deleted it once, I added it back in. I have seen too many papers that recommend t and F for better small sample properties, than the asymptotic normal, chisquare based statistics.

  6. josef-pkt commented on Apr 16, 2014

    @josef-pkt
    Member

    technical answer:
    normalized_cov_params is part of the parameter estimate in fit, i.e. model,
    scale is used for inference (possibly ignored nuisance parameter in fit), it's the role of the results instance to combine them.
    (at least, that's the way it is for linear models)

    What I don't see what value having LikelihoodResults aware of this provides

    LikelihoodResults is really a misnomer or a two-in-one class because it covers both MLE and non-MLE (general extremum, M-estimators) models.

    I would like to split the likelihood part from the extremum estimator part.


    When we add cov_type and a choice of covariance estimator to fit, then the cov_params_default would combine scale and normalized_cov_params.
    However, we still should avoid extra calculations in fit, because in some cases we are only interested in the parameter estimates (for example iterative WLS used in GLM and RLM, or cross-validation).

  7. josef-pkt commented on Apr 16, 2014

    @josef-pkt
    Member

    Couldn't this be done simply by multiplying the covariance by some number !=1 using an existing results (assuming that was refactored to be ignorant of scale)?

    The relevant part is in parenthesis, currently normalized_cov_params is ignorant of scale, or better it is for a fixed scale=1. Internally, we need to combine cov_params_without_scale and scale somewhere, where this is is open for refactoring.

  8. josef-pkt commented on Apr 16, 2014

    @josef-pkt
    Member

    I fully agree with renaming bse, we just need to agree on a new name and deprecate bse.
    it's an early inherited name that was never changed.

    I would also be fine with replacing cov_params() by an attribute, but I expect that it will break a lot of code, and I don't see how to do this with a deprecation.

  9. bashtage commented on Apr 16, 2014

    @bashtage
    MemberAuthor

    The relevant part is in parenthesis, currently normalized_cov_params is ignorant of scale, or better it is for a fixed scale=1. Internally, we need to combine cov_params_without_scale and scale somewhere, where this is is open for refactoring.

    Looking through the calls to this code I don't really see why having the ability to set scale is used inside a results instance. Put another way, the (scaled) covariance can be directly provided. In the case of a LS model, this would just be sigma^2 * (X.T*X)^(-1), or could be HCX. In the case of a MLE model, this could be the covariance of the scores, or the Hessian, or a sandwich form to allow for QMLE.

    This refactor is definitely big, and it probably makes sense to start a new results class (mostly copied) with an alternative structure and then deliberately migrate, rather than trying to change the existing.

  10. josef-pkt commented on Nov 23, 2015

    @josef-pkt
    Member

    an update here: cov_params_default is now the main attribute to hold the covariance if cov_type is not nonrobust. normalized_cov_params corresponds to the Hessian, but is not yet unified.
    Even for the nonrobust case we might start to use it, maybe during the next cov_type refactoring. cov_params_default is not yet guaranteed to be available. cov_params is still the main interface that uses cov_params_default if that is available.

    usage of scale is still has several open issues, with the main problem that we need to fix it in some usages (LR tests) or make it optional (overdispersion)

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