fabianp / mord

Ordinal regression algorithms
Other
263 stars 71 forks source link

Coefficients differs from statsmodel when there is no regularization (alpha = 0) #26

Open guilhermeparreira opened 1 year ago

guilhermeparreira commented 1 year ago

Hi There! I am enjoying using your package to analyse ordinal data. However, when I compared the results of mord.LogisticAT(alpha = 0) against from statsmodels.miscmodels.ordinal_model import OrderedModel I obtained different coefficients. Should not they be the same? (As long as I am not using any regularization technique?).

Here is a reproducible 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)
X, y = data_student[['pared', 'public', 'gpa']], data_student['apply'] 
mod_prob = OrderedModel(y,
                        X,
                        distr='logit')

res_prob = mod_prob.fit(method='bfgs')
res_prob.summary()

image

MORD:

import mord
from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()
y = le.fit_transform(y)
model_mord = mord.LogisticAT(alpha = 50)
model_mord.fit(X, y)
y_pred = model_mord.predict(X)
print('\nCoef mord', model_mord.coef_)
Coef mord [-0.02192845  0.12534365  0.01633311]

which differ a lot from OrderedModel (coefficient of pared is 1.0476 in stasmodel and -0.02192845 in mord).

Also, could I exponentiate the model_mort.coef_ and interpret it as the traditional Odds_Ratio?

Thanks in advance!!

varkmiti commented 1 year ago

Hi, I have noticed the same issue recently. I am not sure if I am using an outdated version, but I would like to see this addressed. After extensive testing, it looks like Mord LogitsticAT agrees with MatLab's mnrfit (link here)––at least up to some floating point accuracy. I would be interested in working on a solution or at least a better understanding of the differences between mord, MatLab, and statsmodels.