Repository navigation
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4716 +/- ##
==========================================
+ Coverage 80.8% 80.92% +0.11%
==========================================
Files 577 577
Lines 88571 88815 +244
Branches 9186 9902 +716
==========================================
+ Hits 71571 71873 +302
+ Misses 14732 14677 -55
+ Partials 2268 2265 -3
Continue to review full report at Codecov.
|
|
Binary/Logit has now |
|
the last commit attached score_test to GLMResults and DiscreteResults. It will not work with all subclasses of DiscreteResults, Only the binary (excluding MNLogit) and basic count models except NegativeBinomial have score_factor. (In Zero-Inflated it will be more difficult to get score_factor and hessian_factor arrays.) The comparison GLM-discrete tests in discrete test_sandwich_cov include Poisson, Logit and Probit. I'm currently skipping OLS which has a different We need to test the extra params cases, NBP and GPP where I added score and hessian factors. |
| res2 = self.res2 | ||
|
|
||
| if isinstance(res2.model, OLS): | ||
| # skip |
There was a problem hiding this comment.
pls use raise pytest.skip... here.
There was a problem hiding this comment.
(and in analogous places throughout)
|
|
||
|
|
||
| def check_jac(self): | ||
| # moved from CheckModelResults |
There was a problem hiding this comment.
why moved? The only arg to this is self, seems like it should definitely be a method.
| # moved from CheckModelResults | ||
| res1 = self.res1 | ||
| exog = self.res1.model.exog | ||
| #basic cross check |
There was a problem hiding this comment.
space after # pls. Also below for #Poisson.
| h2 = np.vstack((np.column_stack((h00, h10.T)), | ||
| np.column_stack((h10, h11)))) | ||
|
|
||
| assert_allclose(h2, h1, rtol=1e-10) |
There was a problem hiding this comment.
Would this make sense as three separate methods? Something like check_scoreobs_sum, check_score_factor_equiv, check_hessian_factor_equiv?
| rtol=0.01) | ||
|
|
||
| def test_jac(self): | ||
| self.res1 = self.res |
There was a problem hiding this comment.
is res1 set anywhere else? Editing self here makes me nervous.
|
|
||
|
|
||
| # this is a copy from stats._diagnostic_other | ||
| # this is a copy from stats._diagnostic_other to avoid circular imports |
| from statsmodels.regression.linear_model import OLS | ||
| from statsmodels.genmod.generalized_linear_model import GLM | ||
| from statsmodels.genmod import families | ||
| import statsmodels.stats._diagnostic_other as diao |
There was a problem hiding this comment.
+1 for removing unnecessary imports
There was a problem hiding this comment.
Thoughts on a separate PR just doing this?
| not np.all((self.endog >= 0) & (self.endog <= 1))): | ||
| raise ValueError("endog must be in the unit interval.") | ||
| if offset is None: | ||
| delattr(self, 'offset') |
There was a problem hiding this comment.
I know this is done elsewhere so it's not the absolute worst, but is there a compelling reason not to just leave self.offset = None? The only difference AFAICT would be that below instead of hasattr(self, 'offset') the check would be self.offset is not None.
| exog = self.exog | ||
| dF = self.pdf(np.dot(exog, params))[:,None] * exog | ||
| linpred = self.predict(params, exog, offset=offset, linear=True) | ||
| dF = self.pdf(linpred)[:,None] * exog |
There was a problem hiding this comment.
space after comma please (and below). Using self.predict here is nice.
|
|
||
| def _derivative_exog(self, params, exog=None, transform='dydx', | ||
| dummy_idx=None, count_idx=None): | ||
| dummy_idx=None, count_idx=None, offset=None): |
There was a problem hiding this comment.
+1 for fixing this. discrete_model is in dire need of these small fixups
| margeff = np.dot(self.pdf(np.dot(exog, params))[:,None], | ||
| linpred = self.predict(params, exog, offset=offset, linear=True) | ||
| margeff = np.dot(self.pdf(linpred)[:,None], | ||
| params[None,:]) |
There was a problem hiding this comment.
Looks like some whitespace needs to be trimmed here
| params = params[:-1] | ||
| p = self.parameterization | ||
| exog = self.exog | ||
| y = self.endog[:,None] |
| a1 = 1 + alpha * mu_p | ||
| a2 = mu + alpha * mu_p * y | ||
| a3 = alpha * p * mu ** (p - 1) | ||
| a4 = a3 * y |
There was a problem hiding this comment.
are there any more meaningful names that can be given to a1, a2, a3, a4? Do they correspond to moments or something?
| dparams = dmudb * (-a4 / a1 + | ||
| a3 * a2 / (a1 ** 2) + | ||
| (1 + a4) * ((y - 1) / a2 - 1 / a1) + | ||
| 1 / mu) |
There was a problem hiding this comment.
Take the two terms -a4 / a1 and (1 + a4) * ((y - 1) / a2 - 1 / a1):
(- a4 / a1
+ (1 + a4) * ((y - 1) / a2 - 1 / a1))
= (1 / a1
- 1 / a1
- a4 / a1
+ (1 + a4) * ((y - 1) / a2 - 1 / a1))
= (1 / a1
- (1 + a4) / a1
+ (1 + a4) * ((y - 1) / a2 - 1 / a1))
= (1 / a1
+ (1 + a4) * ((y - 1) / a2 - 2 / a1))
The term multiplying (1+a4) here also shows up in dalpha
| params = params[:-1] | ||
| p = self.parameterization | ||
| exog = self.exog | ||
| y = self.endog #[:,None] |
There was a problem hiding this comment.
pls delete commented-out
| nobs, k_vars = exog.shape | ||
| hess_fact = np.empty((nobs, 3)) | ||
|
|
||
|
|
| (y - 1) * a4 * (p - 1) / (a2 * mu) - | ||
| (y - 1) * (1 + a4)**2 / a2**2 - | ||
| a4 * (p - 1) / (a1 * mu) - | ||
| 1 / mu**2) + |
There was a problem hiding this comment.
The last -1/mu**2 term here cancels out with the +1/mu term on 1781. Ditto the a4 / (mu*a1) on 1771 with a4/a1 on 1777. ... and 1772 with 1778... Seriously, please let me help with this stuff. #4515.
| mu_p * (1 + a4) / a1**2 + | ||
| a5 * y * (y - 1) / a2 - | ||
| 2 * a5 * y / a1 + | ||
| a5 * a2 / a1**2) * dmudb) |
There was a problem hiding this comment.
I think the outer parens is unnecessary. Can you pls align the indentation?
| A reference to the exogenous design. | ||
| """ % {'params' : base._model_params_doc, | ||
| 'extra_params' : base._missing_param_doc} | ||
| 'extra_params' : |
There was a problem hiding this comment.
convention is no space before colon in dictionaries
| return np.sum(np.log(np.clip(self.cdf(q*np.dot(X,params)), | ||
| FLOAT_EPS, 1))) | ||
| linpred = self.predict(params, linear=True) | ||
| return np.sum(np.log(np.clip(self.cdf(q * linpred), FLOAT_EPS, 1))) |
There was a problem hiding this comment.
splitting this into multiple lines might be more readable
| X = self.exog | ||
| return np.log(np.clip(self.cdf(q*np.dot(X,params)), FLOAT_EPS, 1)) | ||
| linpred = self.predict(params, linear=True) | ||
| return np.log(np.clip(self.cdf(q*linpred), FLOAT_EPS, 1)) |
There was a problem hiding this comment.
whitespace around operator pls
|
Generally looks quite nice; I expect it'll improve performance for |
e031a98 to
4ad8e7f
Compare
|
rebased, the only merge conflict is because GLM score_test and get_hat_matrix_diag/get_influence are next to each other. |
|
This pull request introduces 8 alerts and fixes 5 when merging 4ad8e7f into 5139e47 - view on LGTM.com new alerts:
fixed alerts:
Comment posted by LGTM.com |
4ad8e7f to
fe7733c
Compare
|
This pull request introduces 8 alerts and fixes 5 when merging fe7733c into 4124437 - view on LGTM.com new alerts:
fixed alerts:
Comment posted by LGTM.com |
|
I don't know what happened, two out of three python 2.7 fail or just stop |
|
Close in favor of #5711? |
|
merged in #7825 |
first step towards #2107
see also #4714 sign convention in hessian_factor
score_factor and hessian_factor are copy/paste/adjust.
Unit tests verify that adjustment is correct, but need to be changed when we DRY out score and hessian by reusing the factor methods. How to recover score_obs and hessian is in the unit tests.
first target application is to make score_test from #2096 available for discrete distributions