ENH: Check input to binary models #1978

Merged
merged 2 commits into from Sep 20, 2014

Projects

None yet

2 participants

@jseabold
Member

see #1053

jseabold added some commits Sep 20, 2014
@jseabold jseabold TST: Test for non-binary input. b913645
@jseabold jseabold ENH: Check binary input for correctness. Closes #1053.
c4e71c0
@jseabold jseabold merged commit 1c54d66 into statsmodels:master Sep 20, 2014

1 of 2 checks passed

continuous-integration/travis-ci The Travis CI build is in progress
Details
continuous-integration/appveyor AppVeyor build succeeded
Details
@jseabold jseabold deleted the jseabold:binary-check branch Sep 20, 2014
@josef-pkt
Member

@jseabold can you mention, link to the issue in the description of a PR.
I always have huge problems finding a PR when the issue only shows the commit.

@josef-pkt josef-pkt commented on the diff Sep 20, 2014
statsmodels/discrete/discrete_model.py
@@ -360,6 +360,14 @@ def _derivative_exog(self, params, exog=None, dummy_idx=None,
raise NotImplementedError
class BinaryModel(DiscreteModel):
+
+ def __init__(self, endog, exog, **kwargs):
+ super(BinaryModel, self).__init__(endog, exog, **kwargs)
+ if (self.__class__.__name__ != 'MNLogit' and
+ not np.all(np.unique(self.endog) == [0, 1])):
@josef-pkt
josef-pkt Sep 20, 2014 Member

I don't think that's what we want. It still works for continuous in interval [0,1].
My guess is that the right check is not (endog < 0 & endog > 1).any()

but I haven't gone through the code. S-shaped continuous variables, fractions seem to work well.

@jseabold
jseabold Sep 20, 2014 Member

Feel free to submit a new PR. We need to close remaining issues and get a RC out though. I don't recall seeing any theory for non-binary response for logit/probit.

@josef-pkt
josef-pkt Sep 20, 2014 Member

I think it's the same way as Poisson regression not requiring integers.
The few examples that I tried looked fine.
And I'm pretty sure that it's possible to find the theory somewhere. (I didn't go through all details in the Stata manuals yet.)

@jseabold
jseabold Sep 20, 2014 Member

I've seen fractional logit but I don't recall seeing that it just goes
through in the MLE.

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