Repository navigation
BUG: Handle non-invertible hessian from GLM scipy optimizers - #3299
Conversation
|
temporarily prio-high unit tests pass, but I need to think of the potential impact of this change. |
739cdfb to
01b081f
Compare
|
Changes Unknown when pulling 01b081f on thequackdaddy:glm_optimizer_summary_fix into ** on statsmodels:master**. |
|
alternative suggestions (while looking by chance at summary) AFAICS, we only need to set AFAIK, bse is not used in computation besides tvalues and similar. (That avoids having to figure out what further impact nans in cov_params would have. I assume t_test and similar still raise the |
|
Should I make this change? Happy either way. |
|
@thequackdaddy Yes, I think the nan bse should work for the use case. |
01b081f to
a218660
Compare
|
Updated the code. Note I had to make a similar change at the end of the (Sorry for the multiple pushes... I checked out master to look at something and forgot to switch back before pushing.) |
|
looks good to me, with minor changes. needs a rebase before merge (too far behind master) possible bug not affected by changes in this PR. |
f408a81 to
97d5a70
Compare
|
I've re-based to master. |
josef-pkt
left a comment
There was a problem hiding this comment.
(I still find this review feature very confusing. I never posted my comments from earlier today.)
| if ((not hasattr(self, 'cov_params_default')) and | ||
| (self.normalized_cov_params is None)): | ||
| hinv = np.empty(len(self.params)) | ||
| hinv[:] = np.nan |
There was a problem hiding this comment.
hinv is a confusing name, bse_ would be better
Also, I think it would be more readable without two returns and use
else:
bse_ = np.sqrt(np.diag(self.cov_params()))
return bse_
| if rslt.normalized_cov_params is None: | ||
| n_cov_params = None | ||
| else: | ||
| n_cov_params = rslt.normalized_cov_params / scale |
There was a problem hiding this comment.
again confusing name: we use n_xxx like nobs for a count of observations,
Given that it's internal just here I would use cov_p
| glm_results = GLMResults(self, rslt.params, | ||
| rslt.normalized_cov_params / scale, | ||
| n_cov_params, | ||
| scale, |
There was a problem hiding this comment.
not in this PR
scale here looks wrong to me, either we use scaled cov_params instead of normalized_cov_params and scale=1, or we use normalized_cov_params and the actual scale in the extra argument.
97d5a70 to
8e69e83
Compare
|
@josef-pkt Updated and re-based. |
| if ((not hasattr(self, 'cov_params_default')) and | ||
| (self.normalized_cov_params is None)): | ||
| bse_ = np.empty(len(self.params)) | ||
| bse_[:] = np.nan |
There was a problem hiding this comment.
FYI for future: np.full to create an array with a selected fill value
But I don't remember when it was added, and the numpy docstring doesn't say.
|
Looks good, nice and clean, merging Thanks @thequackdaddy |
Hello,
In a GLM if you are using one of the scipy optimizer and the Hessian inversion fails (i.e., it is not positive definite),
Noneis returned. When runningres.summary()later, a matrix is divided byNonewhich causes a crash.This fixes the problem by returning a matrix of
nanof the same shape asH.Example fail: