Repository navigation
ENH/REF: discrete add get_distribution, add which="var" for NBP, GPP - #7929
Conversation
|
Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-12-13 18:13:53 UTC |
|
currently only smoketests to check that methods and inherited methods work |
|
This pull request introduces 4 alerts and fixes 1 when merging 9d6f81e into 6b4aa33 - view on LGTM.com new alerts:
fixed alerts:
|
9d6f81e to
12f13dc
Compare
|
amended and force pushed Should be correct now. unit tests for get_distribution check the implied mean. Aside: standard geometric distribution parameter as in scipy is |
|
we can add predict get_distribution for |
|
This pull request introduces 1 alert and fixes 1 when merging 12f13dc into 6b4aa33 - view on LGTM.com new alerts:
fixed alerts:
|
|
all green This PR also includes a new NegativeBinomialPResults class, but it doesn't have extra methods yet. |
|
checking patterns in count models NegativeBinomialP.predict: NegativeBinomial does not have predict, uses inherited from CountModel. Poisson.predict calls super for mean and linear, and recursive call for "prob" (and "var" that I'm just adding) CountModel.predict : the conditions for offset, exposure handling look correct but messy. GenericZeroInflated. predict: looks like a rearranged version others: I also just found #7624 ZI models are still missing get_distribution |
|
I never looked at geometric special case in NegBin wikipedia has two versions,
Problem is that in the starting at 1 version, the mean mu has to be >= 1, If mu < 1 than variance using formula would be negative. but we use exp mean function (log link) that imposes mu > 0. I need to figure out how the parameterization works. https://en.wikipedia.org/wiki/Geometric_distribution update |
12f13dc to
1b644b3
Compare
|
This pull request introduces 1 alert and fixes 1 when merging 1b644b3 into ab51acc - view on LGTM.com new alerts:
fixed alerts:
|
|
I don't remember if I ever checked the generic rvs for discrete distributions in scipy. Using scalar params works, i.e. this is fine: The problem was that GeneralizedPoisson.fit didn't converge and had large negative dispersion parameter. The diagnostic plots look good in the following example, especially with nobs=5000 NegativeBinomial does not have predict which="probs" yet. |
|
we still have an inconsistency in the shape of the frozen distribution. |
1b644b3 to
38b5076
Compare
|
amended with fix for geometric distribution. now with loc=-1, and appropriate mean, var aside: I saw somewhere the comment that geometric distribution is NB2 with alpha=1. should be correct now. get_diagnostic with plot function is nice and convenient current models in my notebook with consistent options (except 1-dim versus 2-dim get_distribution) not yet:
|
|
This pull request introduces 1 alert and fixes 1 when merging 38b5076 into ab51acc - view on LGTM.com new alerts:
fixed alerts:
|
|
inconsistent default of p in GeneralizedPoisson and ZeroInflatedGeneralizedPoisson
I got some surprising results when I assumed the default p are the same. my additional cases that I'm checking for get_distribution and get_diagnostic plot: GeneralizedPoisson loglike is not very stable. I easily get invalid value in log and convergence warnings for simple random samples. |
|
it looks like I have zi get_distribution working correctly now. One bug in old, existing code: I have not yet checked My current example case for checking is a constants only model. So, no checks for different exog. |
|
I pushed the zi get_distribution part Not sure yet. I have not added yet an assert on the frequencies, which should be stably predicted even if individual parameters are noisy. Also I'm still running occasionally into convergence problems when I change the DGP numbers, nobs or params. |
|
This pull request introduces 1 alert and fixes 1 when merging 36fd5b9 into 1b75604 - view on LGTM.com new alerts:
fixed alerts:
|
36fd5b9 to
30deeb4
Compare
|
This pull request introduces 1 alert and fixes 1 when merging 30deeb4 into 506b9f3 - view on LGTM.com new alerts:
fixed alerts:
|
|
still to do: zinegbin.rvs looks correct aside when mu=1, then negbin is independent of p |
|
ZI predict: generic or individual methods? Currently, only the generic ZI model class defines predict. The specific subclasses to not define a predict method. which = "var" also needs to be model specific, i.e. either another helper function or adding a predict method that partially delegates to super. Or, we could generically go through Everything related to mean function, works generically because all models are parameterized in terms of mean_main mu and prob of inflation (i.e. mean of inflation model). Do we add other "which" in future that need more model specific computation and methods? aside: we need to explain in docs what the existing which are (I had made a mistake earlier and though prob-zero is the inflation probability. but it's Prob(y=0)) also: generic ZI predict still has the ugly pattern of temporarily changing the model data, model.endog. model.exog, ... another possible change in future: Do we add All 3 ZI models have model specific |
|
another option #7923 add needs distribution specific return, mu and alpha and Once everything is working and has settled, then we need a review and refactor of redundant and duplicated computation. decision for now: new model specific update |
|
results The individual ZI results classes define |
|
This pull request introduces 1 alert and fixes 1 when merging 7d9505e into 3600f3f - view on LGTM.com new alerts:
fixed alerts:
|
|
post-estimation results for discrete looks more filled in now (after this PR) #7707 main undecided is get_influence, I guess I will default to using resid_pearson which is a safer bet than sf/sqrt(-hf) as default residual. I haven't checked margeff yet for GPP, NBP, I don't know the status. |
|
This pull request introduces 1 alert and fixes 1 when merging 370c357 into 3600f3f - view on LGTM.com new alerts:
fixed alerts:
|
2a881be to
3b9042f
Compare
|
This pull request introduces 1 alert and fixes 1 when merging 3b9042f into 3600f3f - view on LGTM.com new alerts:
fixed alerts:
|
|
now I added generic resid_pearson. That's all the features that I wanted to add in this PR. I should fix some docstrings, then it's ready to merge Next PR, I guess, get_diagnostic |
|
This pull request introduces 1 alert and fixes 1 when merging e7753c0 into 4458e43 - view on LGTM.com new alerts:
fixed alerts:
|
|
followup
|


more work on post-estimation for discrete
This also outsources the predict transform exog from base.model.Results.predict to a new private method
_transform_predict_exogThis helper method is reused in
get_distributionto avoid code duplication.get_distributiondoes not use the pandas index because return is a scipy frozen distribution instance.see also #7928 class diagram of unit tests
no get_distribution for MNLogit. I never tried out the scipy multinomial distribution, and don't know if it will work for our case.
This PR has now
get_distributionfor all discrete models except MNLogit. Currently only in model classes not in results classes.which="var"for count models, not yet zi