Repository navigation
ENH: add GLMInfluence - #4732
Conversation
|
aside: It would be faster to write GLMInfluence by just translating formulas to code, but I'd like to figure out the generic pattern, so it will be easier to extend. |
|
This pull request introduces 1 alert when merging 9f20b51 into 9913b6a - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
The idea for keeping and fixing a LOOO loop is that we want to check the computation for selected observations, e.g. if we have influential or outlier candidates from the one-step approximation. |
|
all red, I forget to revert a change mse_resid -> scale, that I ha d tried out for consistency between OLS and GLM, but it didn't work (at least in my simple tries) see #4733 test errors are in The problem is in recreating models and getting results in the explicit LOOO loop. |
|
There are some things that are specific to GLM that needs a model specific subclass, mainly related to deviance. |
|
a quick try: MLE Newton updating versus IRLS based dparams explicit LOOO, results for res_m0, res_m3 one Newton step underestimates changes (values in db and db_oim) |
9f20b51 to
e0e4040
Compare
|
amended first commit with undoing mse_resid -> scale change that failed unit tests against SAS, but I'm using different definitions, inherited from OLSInfluence, and don't have Cbar yet. |
|
This pull request introduces 1 alert when merging e0e4040 into 3c2ea25 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
Codecov Report
@@ Coverage Diff @@
## master #4732 +/- ##
==========================================
+ Coverage 81.01% 81.05% +0.04%
==========================================
Files 578 579 +1
Lines 89103 89489 +386
Branches 9942 9967 +25
==========================================
+ Hits 72183 72536 +353
- Misses 14657 14681 +24
- Partials 2263 2272 +9
Continue to review full report at Codecov.
|
|
all green, R reports dffit and and cov_ratio (?) for glm, which I can add to the unit tests (inherited from OLSInfluence) The more difficult part is to come up with an API and inheritance structure, and specifically which variants of the influence measures to add as attributes and to cache, e.g. standardized dfbeta, variants of cooks distance. right now I should be able to get
not clear yet what will become available for
It's not clear to me what is the common denominator, i.e. what can we put into a superclass that the model specific Influence classes inherit. Not clear either is how to handle nonrobust cov_type. Refactoring: make delete obs i loop, _res_looo, generic and limit to provided indices. Most likely not in this PR. |
|
detail: last IRLS WLS weights are one iteration step behind using hessian_factor based on final params. |
|
reusing regressionplots this works for GLM now, without changes this doesn't, and needs resid options: |
|
I finally read Cook and Weisberg chapter 5 on "other problems", i.e. not linear regression. |
|
dfbeta in R influence.measures sounds wrong. one observation they use weighted residuals from the model which is resid_deviance, while I use the explicit formulas for GLM using resid_pearson. my and R's dffits also differs but I haven't looked yet what the version inherited from OLSInfluence actually does. |
|
one possible naming convention or post fix not clear API w.r.t. options
also naming for scaled or studentized variants if separate attributes, e.g. dfbeta dfbetas also should we wrap individual attributes as pandas Series? Also, I want to add an unscaled or optionally scaled d_fitted or d_predict with linear=False/True option in analogy to dffits. (Neither R's dffits nor my inherited dffits seem to be close to delta_predict in the binomial count example. So I want to have a different name for the actual thing.) |
|
cov_type for influence simplest possibility: cov_type in influence is always the same as cov_type in fit. The users need to refit with a different cov_type to get influence with a different cov_type. That's one extra step compared to using results.get_influence(cov_type = ...). backwards compatibility: OLSInfluence is currently completely Do any current users actually care about this? If the only problem is the standard error of predicted mean (fittedvalues), then it's just one line to compute it with the nonrobust cov_type. |
|
I need a generic function for do we have an index plot with annotation for selected indices? |
|
another naming issue: postfix: _scaled, _standardized, _studentized The literature has several names for resid_studentized, OLSInfluence uses resid_studentized_internal and resid_studentized_external. I now have dfbetas is dfbeta plus "scaled" by bse in the literature, i.e. it should be d_params_scaled. aside: The distribution of resid is messy in general, because it contains endog y, which has the randomness in the response and is correlated with the estimate of beta and predict. Cook Weisberg have some discussion in chapter 5 for generalized residuals. edit maybe studentized wouldn't be a misnomer, i.e. not if dfxxx/d_xxx has expected value of zero, which might be the case in many cases, but most likely not for some non-linear functions like predicted response in GLM and discrete models. |
|
In my notebook for development, the main method that doesn't exist anymore in GLMInfluence is I think it's time and a reasonable place to stop. Still needs some cleanup and reviewing of docstrings. |
ea58cbc to
3200fb3
Compare
|
My mistake, I only ran some test classes locally |
|
This pull request introduces 2 alerts when merging 3200fb3 into 65312bb - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
looking at coverage: https://coveralls.io/builds/17600536/source?filename=statsmodels%2Fstats%2Foutliers_influence.py#L190
|
|
This pull request introduces 1 alert when merging fa2499e into 65312bb - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
another test case: Binomial count from Williams article and R docs I needed to lower test precision a bit comparing GLM versus MLE, but rtol and atol are still around 1e-7 or 5e-9, cooks_distance has only rtol=5e-5. This uses the same results instance, so it's not affected by convergence tolerance in fit. (That's still much closer than what would make a meaningful difference in interpretations.) |
|
BUG: LGTM finds a hardcoded external in the call to plot_influence, ignores keyword. |
|
This pull request introduces 1 alert when merging 66af430 into 65312bb - view on LGTM.com new alerts:
Comment posted by LGTM.com |
66af430 to
1b128ca
Compare
|
LOOO: |
|
parking some initial code that is still in a test function but I will delete the unused parts. |
|
I also added the notebook for the GLM-Logit example. I took the example from the SAS documentation, but actually it's the main example in Pregibon 1981. Time to stop here and merge. One thought while working on docstrings. A review of this before the next release would be useful. I'll merge when green. |
|
This pull request introduces 1 alert when merging 43a59ce into 01ce369 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
|
||
| from statsmodels.tools.sm_exceptions import (PerfectSeparationError, | ||
| DomainWarning) | ||
| from cvxopt.base import matrix |
There was a problem hiding this comment.
how did this get in here? unit tests fail
That's the second time in this PR that I get an unrelated import added to a module.
I'm only editing the statsmodels source in pydev/Eclipse.
43a59ce to
d8dcabe
Compare
|
all green, except coveralls changed how it counts. |
see #4268 and #4257
just getting started to figure out what the structure should be and if we can reuse code from OLSInfluence.
Note: SAS logistic has two differences in an example printout, compared to OLSInfluence, My results agree if I correct for different definitions.
short cuts, not working yet.
OLSInfluence external standardization and some other methods use explicit LOOO loops.
I faked them or skipped them for now, summary_frame has fewer columns than in OLSInfluence.
We should use only one step approximations by default.