0

I tried to follow the tutorial on ordinal regression using stats models from (https://www.statsmodels.org/dev/examples/notebooks/generated/ordinal_regression.html).

import numpy as np
import pandas as pd
import scipy.stats as stats

from statsmodels.miscmodels.ordinal_model import OrderedModel, OrderedResults

url = "https://stats.idre.ucla.edu/stat/data/ologit.dta"
data_student = pd.read_stata(url)
mod_prob = OrderedModel(data_student['apply'],
                        data_student[['pared', 'public', 'gpa']],
                        distr='probit')

res_prob = mod_prob.fit(method='bfgs')
my_result = OrderedResults(mod_prob, res_prob)
print(my_result.llr_pvalue)

On trying to run the code for getting the llr pvalue I am getting below error, how to remove it and get the llr pvalue? in the docs https://www.statsmodels.org/dev/generated/statsmodels.miscmodels.ordinal_model.OrderedResults.html the llr_pvalue is mentioned as an attribute

  File "/Users/pranavnerurkar/opt/anaconda3/lib/python3.9/site-packages/statsmodels/base/model.py", line 2736, in summary
    ('AIC:', ["%#8.4g" % self.aic]),
  File "pandas/_libs/properties.pyx", line 36, in pandas._libs.properties.CachedProperty.__get__
  File "/Users/pranavnerurkar/opt/anaconda3/lib/python3.9/site-packages/statsmodels/base/model.py", line 2360, in aic
    return -2 * self.llf + 2 * (self.df_modelwc)
  File "pandas/_libs/properties.pyx", line 36, in pandas._libs.properties.CachedProperty.__get__
  File "/Users/pranavnerurkar/opt/anaconda3/lib/python3.9/site-packages/statsmodels/base/model.py", line 1403, in llf
    return self.model.loglike(self.params)
AttributeError: 'OrderedResults' object has no attribute 'params'
pranav nerurkar
  • 596
  • 7
  • 19
  • 1
    use the results instance returned by `fit`, that is `print(res_prob.llr_pvalue)`. Creating a result instance is "internal" not for users, i.e. only the `fit` methods have the necessary information. – Josef Feb 24 '23 at 20:58

0 Answers0