Repository navigation
Closed
Milestone
Description
Below there is the traceback from a GEE Binomial fit example (from my notebook comparing GEE, GLM and discrete).
I just discovered that my problem was because I used count data in GEE, instead of the binaries data. There is no problem with the binary data.
So the main problem, I guess, is to fail with an informative message, or be able to do some basic checking on the data.
endog.values
array([ 0., 0., 3., 4., 6., 18., 11., 39., 29., 58., 53.,
12., 44., 18., 1., 1., 0., 1., 6., 2., 1., 0.,
0., 0., 0., 2., 11., 4., 0., 7., 7., 5., 12.,
1.])
fam = families.Binomial()
ind = Independence()
mod1 = GEE(endog, exog, group, cov_struct=ind, family=fam)
res_gee = mod1.fit() #start_params=res_glm_logit_clu.params)
#print res_gee.summary()
print(res_gee.bse)
---------------------------------------------------------------------------
LinAlgError Traceback (most recent call last)
<ipython-input-136-768f8c8ca52d> in <module>()
2 ind = Independence()
3 mod1 = GEE(endog, exog, group, cov_struct=ind, family=fam)
----> 4 res_gee = mod1.fit() #start_params=res_glm_logit_clu.params)
5 #print res_gee.summary()
6 print(res_gee.bse)
e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\genmod\generalized_estimating_equations.pyc in fit(self, maxiter, ctol, start_params, params_niter, first_dep_update, covariance_type)
851 for itr in range(maxiter):
852
--> 853 update, score = self._update_mean_params()
854 if update is None:
855 warnings.warn("Singular matrix encountered in GEE update",
e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new2_py27\statsmodels\statsmodels\genmod\generalized_estimating_equations.pyc in _update_mean_params(self)
646 score += np.dot(dmat.T, vinv_resid)
647
--> 648 update = np.linalg.solve(bmat, score)
649
650 self.fit_history["cov_adjust"].append(
C:\Programs\Python27\lib\site-packages\numpy\linalg\linalg.pyc in solve(a, b)
326 results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)
327 if results['info'] > 0:
--> 328 raise LinAlgError, 'Singular matrix'
329 if one_eq:
330 return wrap(b.ravel().astype(result_t))
LinAlgError: Singular matrix
Activity
kshedden commentedon Sep 24, 2014
GEE can not uncommonly fail with an uninformative "LinAlgError", for example, when endog is entirely zero. I suppose we should trap these errors and return a results instance with nan's everywhere, and some sort of informative message.
josef-pkt commentedon Sep 24, 2014
If endog is entirely zero, then there will not be any information in the results. I think in those cases we should just raise an exception.
Related: Skipper merged a check for binary models in discrete to contain valid endog.
But I don't like ruling out the "misuse" of models if they might work also for initially unintended use cases.
bashtage commentedon Jul 30, 2026
Fixed by commit 980cd16 ("Handle singularities better"): _update_mean_params (statsmodels/genmod/generalized_estimating_equations.py) now falls back to np.linalg.pinv instead of crashing with LinAlgError. Reran the issues Binomial-on-count-data repro against current code - no crash, just a NaN result with an overflow warning. The residual "clearer error message" ask is tracked separately under still-open #1908. Closing as fixed.