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
JavaScript
x
2
1
from statsmodels.miscmodels.ordinal_model import OrderedModel
2
Examples are given in the documentation above. For example:
JavaScript
1
12
12
1
import pandas as pd
2
from statsmodels.miscmodels.ordinal_model import OrderedModel
3
url = "https://stats.idre.ucla.edu/stat/data/ologit.dta"
4
data_student = pd.read_stata(url)
5
6
mod_log = OrderedModel(data_student['apply'],
7
data_student[['pared', 'public', 'gpa']],
8
distr='logit')
9
10
res_log = mod_log.fit(method='bfgs', disp=False)
11
res_log.summary()
12
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:
JavaScript
1
2
1
pip3 install git+git@github.com:statsmodels/statsmodels.git
2
to do so.