Skip to content

input checking, corner case, convergence problem GEE "long panel" #1907

Closed

Description

@josef-pkt

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

  1. added this to the 0.7 milestone on Aug 18, 2014
  2. kshedden commented on Sep 24, 2014

    @kshedden
    Contributor

    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.

  3. josef-pkt commented on Sep 24, 2014

    @josef-pkt
    MemberAuthor

    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.

  4. modified the milestones: 0.8, 0.7 on Feb 6, 2015
  5. bashtage commented on Jul 30, 2026

    @bashtage
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions