19
$\begingroup$

I would like to run an ordinal logistic regression in Python - for a response variable with three levels and with a few explanatory factors. The statsmodels package supports binary logit and multinomial logit (MNLogit) models, but not ordered logit. Since the underlying math is not that different, I wonder if it can be implemented easily using these? (Alternatively, other Python packages that work are appreciated.)

$\endgroup$
5
  • 1
    $\begingroup$ The only code in python that I know of is by Fabian see the statsmodels issue github.com/statsmodels/statsmodels/issues/807 . I think it wouldn't be difficult to implement for statsmodels, but nobody volunteered yet. $\endgroup$
    – Josef
    Aug 23 '15 at 14:37
  • 3
    $\begingroup$ This is not Python, but in R the orm function in the rms package efficiently handles thousands of levels of the response variable. $\endgroup$ Dec 30 '15 at 12:59
  • 2
    $\begingroup$ In conjunction w/ @FrankHarrell's comment above, note that you can call R functions from Python w/ rpy2 (see also: A Slug's Guide to Python). $\endgroup$ Dec 30 '15 at 16:24
  • 1
    $\begingroup$ This is arguably on-topic since the question doesn't seem to be a pure code request - whether one can cobble an ordered logit model out of the computational ingredients of binary logit and MNLogit seems to me to be a question with a statistical character (even if the ultimate solution turns out to be something like "no, use a different package") $\endgroup$
    – Silverfish
    Dec 30 '15 at 16:57
  • 1
    $\begingroup$ Indeed, I ended up using R modules through rpy2, as well as simplifying my model specification to binary logit. $\endgroup$
    – Hadi
    Dec 31 '15 at 19:32
7
$\begingroup$

Have you tried Mord? It seems there are very few packages to do the same, and it is one of them; though, as Fabian himself suspects, code may not scale properly. Source: Logistic ordinal regression in Python

$\endgroup$
7
$\begingroup$

statsmodels now supports Ordinal Regression:

from statsmodels.miscmodels.ordinal_model import OrderedModel

see their documentation here

$\endgroup$
1
  • 1
    $\begingroup$ statsmodels now supports Ordinal Regression, but not in the released version. They say that installing the dev version of statsmodels is okay for everyday use. So I did: pip3 install git+git://github.com/someuser/someproject.git $\endgroup$
    – CPBL
    Jun 9 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.