Skip to content

BUG: Logit margeff summary TypeError #2817

Closed

Description

@TomAugspurger

Really the only example from my notebook cleanup that looks like a real bug.

import numpy as np
import statsmodels.api as sm

spector_data = sm.datasets.spector.load()
spector_data.exog = sm.add_constant(spector_data.exog, prepend=False)

logit_mod = sm.Logit(spector_data.endog, spector_data.exog)
logit_res = logit_mod.fit(disp=0)

margeff = logit_res.get_margeff()
print(margeff.summary())

raises

TypeError                                 Traceback (most recent call last)
<ipython-input-1-210bf23ad669> in <module>()
      9 
     10 margeff = logit_res.get_margeff()
---> 11 print(margeff.summary())

/Users/tom.augspurger/Envs/dev/lib/python3.4/site-packages/statsmodels/statsmodels/discrete/discrete_margins.py in summary(self, alpha)
    520         _, const_idx = _get_const_index(model.exog)
    521         if const_idx is not None:
--> 522             exog_names.pop(const_idx)
    523 
    524         J = int(getattr(model, "J", 1))

TypeError: only integer scalar arrays can be converted to a scalar index

Activity

  1. josef-pkt commented on Feb 16, 2016

    @josef-pkt
    Member

    I don't really understand this _get_const_index(model.exog) just uses np.where

    However, this code is outdated since const_idx is now attache to the model or model.data

    Same code is in GEE (copied and adjusted from discrete)

    no smoketests for summary method in test suite.
    discrete margins are only tested on Logit, AFAICS

    (I haven't installed numpy 1.11.0.bxxx yet because I either don't remember how to set up a virtualenv, or the python built in virtualenv in 3.4 doesn't work properly, or it's because pip hates me back)

  2. josef-pkt commented on Feb 16, 2016

    @josef-pkt
    Member

    the problem is that const_idx is a 1d array with one element, which cannot be used for indexing or popping a python list.

    The newer code in base data squeezes: np.where(...)[0].squeeze()
    AFAIK, the model const_idx is used quite often and should have proper functional unit test coverage

  3. theaverageguy commented on Mar 22, 2016

    @theaverageguy

    @kshedden Fixed?

  4. kshedden commented on Mar 22, 2016

    @kshedden
    Contributor

    I was not planning to fix this in Logit, I have not worked on that code at
    all.

    I have a pending PR (#2833) that fixes the same bug in GEE. There are a
    few more things that I need to deal with there before it can be merged
    though.

    On Tue, Mar 22, 2016 at 9:41 AM, theaverageguy [email protected]
    wrote:

    @kshedden https://github.com/kshedden Fixed?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #2817 (comment)

  5. added this to the 0.8 milestone on Jun 22, 2016
  6. josef-pkt commented on Jun 22, 2016

    @josef-pkt
    Member

    looks like we missed this one for 0.8.0rc1, I had thought it was incorporated somewhere

  7. josef-pkt commented on Aug 15, 2016

    @josef-pkt
    Member

    The error was fixed in #3037, example runs fine with master
    it still uses the outdated pattern with _get_const_index(model.exog), not urgent

  8. josef-pkt commented on May 27, 2017

    @josef-pkt
    Member

    I opened #3719 for the refactoring issue, so I can close this 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