Repository navigation
ENH: Ordinal models - #6982
ENH: Ordinal models#6982Bolzano-Weierstrass wants to merge 13 commits into
Conversation
|
This pull request introduces 3 alerts when merging 49d6360 into 1659994 - view on LGTM.com new alerts:
|
| @@ -0,0 +1,97 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
| Created on Mon Aug 24 11:17:06 2015 | |||
There was a problem hiding this comment.
Could you do a notebook? We don't really use ex_... Python files anymore and they dont' show up in the docs.
|
This pull request introduces 3 alerts when merging bcd1fa2 into 26d901a - view on LGTM.com new alerts:
|
|
I just checked out the branch. Having ordered categorical support from pandas is very useful. When I wrote this initially, that support had just started. I need to go through the code, but my impression is that with enough unit tests we can move it from misc_models into |
|
from_formula
currently I see two ways to have original endog in formula
wrapper for returning pandas results is missing. |
|
score and hessian http://people.stern.nyu.edu/wgreene/OrderedChoiceModeling.pdf section 5.9.5 p. 142 aside: In the notebook example, the hessian of polr and our hessian are very different for ordinal probit. I haven't looked at details or possible parameterization or scaling issues |
|
patsy attaches If we leave missing value handling to patsy, then we cannot use the original data directly. But we could also run into problems with inherited nan handling, i.e. we are delegating most of the formula data handling up to the Model class and it might be difficult to override specific parts. I haven't tried yet. (users can just do .dropna, so lower priority) not clear to me: |
|
formulatools has functions like |
|
another possibility: because of patsy's eval, using the full name |
|
ynames in predict, currently missing predict is inherited from base.Model, that returns conditionally a pandas Series or DataFrame with appropriate index but no column names. We can add the ynames there. We just raise an exception in the formula if endog is not a pandas Categorical or numeric. We don't want some weird patsy behavior to sneak in as for Binomial. see #2181 and related issues |
|
@Bolzano-Weierstrass Do you have any changes left for this PR? I think it's easier if I take over this PR, for now, to add changes that require more of the statsmodels internals and inheritance. If you have additional improvements and enhancements, then we could add them after I made my changes to integrate it better with the statsmodels structure. |
Sounds good, thanks ! |
|
@Bolzano-Weierstrass question on using pandas Categorical. I would like to get the Does it preserve the index and missing values? The advantage would be that super classes of OrderedModel will use the standard data handling for pandas endog, e.g. attaching the I found |
|
Missing values are given the code -1 no matter what and the index is indeed preserved. |
|
Thanks,
This means our nan/missing detection will not find it. |
|
I'm going to allow pandas endog that is not Categorical. Any reason against it? |
|
@Bolzano-Weierstrass Thanks for working on this, especially unit tests and showing how to use pandas Categorical |
see PR #2600 and issue #807
Picked up the ordinal regression model started a few years ago.
Mostly focused on the bodywork and left the engine untouched as the results seem correct.
It is currently in miscmodels and relies on GenericLikelihoodModel.
In this PR:
added support for the Pandas ecosystem, endog can be a categorical Serie and exog can be a Serie or a DataFrame.
added a minimal Result class that embellishes .summary() by using variables names if the inputs are from Pandas.
added tests: formula mode, Pandas inputs, custom distributions, ...
tested against R MASS package