Skip to content

ENH/REF: follow-up to merges for 0.14 #7815

Open

Description

@josef-pkt

I'm planning to merge some PRs that will need follow-up before the 0.14 release.
This is mainly because I have to bring different parts together and I want to postpone decisions on a final implementation and api. And for now I'm more focused on the overall structure than verifying every detail.

The two big areas will be more post-estimation to existing models, and new categories of models.

General task is API and docstring cleanup and review.

companion to roadmap #7720

post-estimation

new models

stats

Cleanup inconsistent API, deprecations, still to do:

  • discrete fittedvalues
  • get_prediction 1-dim or 2-dim
  • GLM predict which, get_prediction Results class

TODO: across the code of most PRs:

  • docstring will need review and fixes
  • additions to rst docs if not automatic, e.g. new XXXResults classes
  • unit test needs more coverage for extras, eg. offset. Maybe refactor and streamline some unit tests. We still get more automatic coverage for new infrastructure like score_test through internal code use like diagnostics, e.g. variable addition, reset tests.

Activity

  1. added this to the 0.14 milestone on Oct 21, 2021
  2. josef-pkt commented on Nov 3, 2021

    @josef-pkt
    MemberAuthor

    Bug that affects score_test. see #7840 GLM fit_constrained uses wrong df_resid for scale estimate

    I'm not sure if it is only the scale estimate in the restricted model. There could also be the wrong df_resid in score_test itself.
    I didn't go through the code yet for this.

    The following two versions agree for HC0, but not for nonrobust cov_type

    cov_type="HC0"
    st1 = res_constr.score_test(cov_type=cov_type)
    st2 = res.score_test(exog_extra=groups, cov_type=cov_type)
    

    the 3rd way of using score_test does not work with HC0

    We don't have a constraint matrix if only the params_constrained are given.
    Can we still compute sandwiches without knowing R?

    sthc = res_full.score_test(params_constrained=res_constr.params, k_constraints=1, cov_type="HC0")
    raises, final part of traceback:

    statsmodels\statsmodels\base\_parameter_inference.py in _lm_robust(score, constraint_matrix, score_deriv_inv, cov_score, cov_params)
         57 
         58     k_constraints = np.linalg.matrix_rank(R)
    ---> 59     tmp = R.dot(Ainv)
         60     wscore = tmp.dot(score)  # C Ainv score
         61 
    
    AttributeError: 'NoneType' object has no attribute 'dot'
    
  3. josef-pkt commented on Dec 16, 2021

    @josef-pkt
    MemberAuthor

    see also #3810 SUMM/REF: Review discrete_model for changes that might still be included.

    I didn't review get_prediction for OLS linear model again
    That still needs at least improved docs
    and wls_prediction_std is still used in several parts of statsmodels. We should deprecate it.

  4. josef-pkt commented on Oct 11, 2022

    @josef-pkt
    MemberAuthor

    most of the new modules are missing an __all__
    That would also be convenient for the notebooks that introduce a new module

  5. josef-pkt commented on Nov 3, 2022

    @josef-pkt
    MemberAuthor

    for get_prediction discrete, GLM

    question: Does Prediction Results have confint_method?
    (I will need an example to check)

    how are conf_int of predicted values computed as function of params and cov_params?
    e.g. "linear", "endpoint", "delta"
    corresponding to the 3 get_prediction methods

    related: based on the code in discrete, I don't see whether or where Poisson get_prediction uses endpoint transformation if which="mean".
    get_prediction is in CountResults and the same (?) between Poisson and negbin

    update
    dispatch for endpoint transformation is in base _prediction_inference get_prediction, but it uses a model attribute
    use_endpoint = getattr(self.model, "_use_endpoint", True)
    and
    elif (which == "mean")and (use_endpoint is True) and (average is False)

    where is the model attribute set?

    update
    use_endpoint above defaults to true
    So this is correct for all count models in discrete, mean is not a function of dispersion parameters even in NB, GP.
    zero-inflated models define their own get_prediction that only uses delta method
    BUG (likely): Truncated and Hurdle models do not define prediction, nor does code search find a _use_endpoint attribute.
    So by inheritance through CountResults, truncated and hurdle models would incorrectly use endpoint transformation for which="mean". ???

    aside: Poisson results has get_influence method, but it's the same as the one inherited from DiscreteResults.
    I guess we can remove it.

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