Repository navigation
ENH: Diagnostic class rebased - #7597
Conversation
| """ | ||
| y = self.endog | ||
| X = self.exog | ||
| L = self.cdf(np.dot(X, params)) |
There was a problem hiding this comment.
this does not include offset
|
fails across the board recent change in main, #7596, breaks extra fit keywords |
|
This pull request introduces 1 alert when merging fa3d3fc into d2f6634 - view on LGTM.com new alerts:
|
|
Why not fix the issue? There were loads of incorrect keywords in tests, eg tol rather than gtol. |
|
I will fix the issue, but it is an indicator that the check breaks code, and checking extra kwargs is not worth it. exception is fine for now to fix our problems but needs to be converted to warning before the release, to avoid breaking user code, subclasses, ... |
|
Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-10-28 15:27:34 UTC |
|
This pull request introduces 1 alert when merging e3a7688 into d2f6634 - view on LGTM.com new alerts:
|
|
green, except for one flake unused import test coverage is pretty low |
e3a7688 to
1388fad
Compare
|
rebased again |
| return -2*self.llf + np.log(self.nobs)*(self.df_model+1) | ||
|
|
||
| @cache_readonly | ||
| def im_ratio(self): |
There was a problem hiding this comment.
now we use a method info_criteria in GLM, regression and tsa
| to the parameter vector. | ||
| """ | ||
| from statsmodels.genmod.families import links | ||
| link = links.Log() |
There was a problem hiding this comment.
which should have a family or link attribute for this
|
changes in test_glm_weights.py looks mostly pep-8 cleaning genmod test_glm CheckComparisonMixin includes test for stats/tests/test_influence.py compares Azur failures are only style check for unused import |
|
This pull request introduces 1 alert when merging 1388fad into b5baa4d - view on LGTM.com new alerts:
|
|
Poisson.get_prediction implements offset and exposure like GLM, but no unit test case with either offset or exposure, AFAICS |
| score_obs = res.model.score_obs(res.params) | ||
| cov_score = score_obs.T @ score_obs | ||
| hessneg_inv = np.linalg.inv(-hess) | ||
| im_ratio = hessneg_inv @ cov_score |
There was a problem hiding this comment.
use lstsqu to avoid direct matrix inversion
There was a problem hiding this comment.
If these are both always square and hess is full-rank, than solve would be the best solution I think.
| def tic(results): | ||
| """Takeuchi information criterion for misspecified models | ||
|
|
||
| """ |
|
It looks like PoissonDiagnostic was still in draft status when I stopped working on it. Currently, I'm trying to figure out how The problem is that many of these functions don't exist in other packages. (Maybe in some web appendices to articles. I haven't looked for it again.) Needs work before we can merge this even with an experimental API. update test_chisquare_prob cannot be used to test 1- or k-inflation, because it drops the last bin, but not bins in front (low y). Bins for the test always includes y=0, maybe pooled with other low y. test_chisquare_prob currently does not truncate almost empty bins for high endog values. rerunning Monte Carlo zi inflation tests, last row is for test_chisquare_prob for zero. |
|
maybe I should change the name of For individual probabilities like zero inflation, we could use one-sided tests. The OPG version would apply to any model. For better CMT, we would need derivatives d_probs / d_params (as in explicit zeroinflation tests) Still, I think we need an upper bound as default to avoid empty or almost empty bins. Most of these functions or methods should return now a |
a6421a2 to
a2733ba
Compare
|
This pull request introduces 1 alert when merging a2733ba into 63a32e9 - view on LGTM.com new alerts:
|
|
#7131 has a long list of references for score_test the test in the notebook looks also the best in smaller sample nobs=100 (still two sample regression) brock and constant only zi test looks strange, pvalues are far from uniform all dispersion tests also look mostly well sized in small samples (I haven't done any power simulations) |
|
Hosmer lemeshow type test for Poisson needs to have a limit on y-cells, i.e. we need to bin low count cells. code comment in
Note, currently anything with "prob" is not designed for large counts, because we compute full arrays with shape |
|
It looks like test_poisson_zeroinflation_brock, and the equivalent constant inflation test is numerically not stable because of the division by prob0 which can be very small if mu is large. again 2-sample case, nobs=1000, nrepl=5000 scoretest by Broek is parameterized in terms of prob ration If the score test is in terms of diff = observed0 - count0 (in other articles) then we don't have division by prob0 in the test statistic, and it's computationally more robust even if mu is larger. rewriting Broek test doesn't help equ 4 instead of similar to equ 3 in Broek article Boek article: in the simulation uses mu= 0.5 and mu=1 Ok, leave it as is but add a note in docstring that it only works well for small mu Jansakul and Hinde naming problem: I misspelled Broek in several different ways. Needs fixing. |
|
No reference for test_chisquare_prob Related: I think I also worked with added variable score tests adding dummies for specific cases, e.g. indicator variables for endog in a bin. general theory by Andrews Econometrica #3904 |
|
poisson diagnostics need one round of cleanup Then I can go back to general design. Basic idea PoissonDiagnostic should be the prototype We don't have Binomial and Beta-Binomial in discrete. Structure: This PR also adds derivatives for MLEInfluence in Logit and Poisson Tools needed in individual models, e.g.
|
|
I found the reference for the zi test in the notebook, #7131 (comment) implementation follows Tang and Tang 2019 which have the explicit formulas for the Poisson case, based on theory in He et al 2019 Given that it does the best in the monte carlos overall, it should be the default. design question: |
55ab55e to
518fa2e
Compare
|
another refactoring: I need d_pdf / d_dargs as part of e.g. zero-inflation testing, moment or conditional moment test for probabilities/frequencies. |
|
This pull request introduces 1 alert when merging 518fa2e into d990e32 - view on LGTM.com new alerts:
|
518fa2e to
8365fbb
Compare
|
This pull request introduces 1 alert when merging 8365fbb into d990e32 - view on LGTM.com new alerts:
|
|
I will make the Hosmer-lemeshow type test PoissonDiagnostic.chisquare_binned private for now. Adrews' theory applies to both partitioning of endog and of exog space, so we might be better off building on that. Aside: I recently downloaded However, it looks to me that they are comparing the mean, i.e.. residual in groups of observations. They are not partitioning the y space and use predictive probabilities as I do. aside to the aside: Surjanovic et al point out that distribution of the test statistic in HL is a sum of chisquare, and that HL use a 1-term approximation with chisquare using a df correction based mostly on simulations. |
|
I will merge this when it comes back green. main related parts missing: offset in binary models and score_test (Poisson and Logit to start with) and get_distribution to make simulations easier |
|
This pull request introduces 2 alerts when merging 5d6aa59 into d990e32 - view on LGTM.com new alerts:
|
5d6aa59 to
0158af1
Compare
…_chisquare_binned
closes #7166
rebased version of #7166
see previous PR for comments and details
update What's included in this PR
im_ratio,tic,gbicPoissonDiagnosticclass_deriv_mean_dparamsin BinaryModel and CountModelget_predictionin LogitResults and PoissonResults_deriv_score_obs_dendogin Logit and Poisson, used for ?score_factor,hessian_factorin Logitim_ratio,info_criteriain DiscreteResultsget_influencein Logit and Poisson returning MLEInfluence, tests against GLM.get_influenceget_diagnostic