Skip to content
Advertisement

Ordered Logit in Python?

I’m interested in running an ordered logit regression in python (using pandas, numpy, sklearn, or something that ecosystem). But I cannot find any way to do this. Is my google-skill lacking? Or is this not something that’s been implemented in a standard package?

Advertisement

Answer

Update: Logit and Probit Ordinal regression models are now built in to statsmodels.

https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html

from statsmodels.miscmodels.ordinal_model import OrderedModel

Examples are given in the documentation above. For example:

import pandas as pd
from statsmodels.miscmodels.ordinal_model import OrderedModel
url = "https://stats.idre.ucla.edu/stat/data/ologit.dta"
data_student = pd.read_stata(url)

mod_log = OrderedModel(data_student['apply'],
                        data_student[['pared', 'public', 'gpa']],
                        distr='logit')

res_log = mod_log.fit(method='bfgs', disp=False)
res_log.summary()

The catch is that the development version of statsmodels is far ahead of the release. They say that installing the dev version of statsmodels is okay for everyday use. So I used the following:

pip3 install git+git@github.com:statsmodels/statsmodels.git

to do so.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement