Skip to content

Commit

Permalink
REF: raise instead of warn if k_constant > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-pkt committed Sep 21, 2020
1 parent eeb1eb2 commit 01c95e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
13 changes: 8 additions & 5 deletions statsmodels/miscmodels/ordinal_model.py
Expand Up @@ -107,6 +107,9 @@ def __init__(self, endog, exog, offset=None, distr='probit', **kwds):
# Note: Doing the following here would break from_formula
# self.endog = self.endog.argmax(1)

if self.k_constant > 0:
raise ValueError("there should not be a constant in the model")

self._initialize_labels(labels)

self.results_class = OrderedResults
Expand Down Expand Up @@ -178,11 +181,11 @@ def from_formula(cls, formula, data, subset=None, drop_cols=None,
terms = re.split(r"[+\-~]", formula)
for term in terms:
term = term.strip()
if term in ("0", "1"):
import warnings
msg = ("OrderedModel formulas should not include any '0' or "
"'1' terms if those create an implicit constant.")
warnings.warn(msg, SpecificationWarning)
# if term in ("0", "1"):
# import warnings
# msg = ("OrderedModel formulas should not include any '0' or "
# "'1' terms if those create an implicit constant.")
# warnings.warn(msg, SpecificationWarning)

endog_name = formula.split("~")[0].strip()
original_endog = data[endog_name]
Expand Down
28 changes: 14 additions & 14 deletions statsmodels/miscmodels/tests/test_ordinal_model.py
Expand Up @@ -304,15 +304,15 @@ def test_setup(self):
# warns but doesn't raise
formula = "apply ~ 0 + pared + public + gpa + C(dummy)"

with pytest.warns(SpecificationWarning):
with pytest.raises(ValueError):
modf2 = OrderedModel.from_formula(formula, data, distr='logit')

with pytest.warns(HessianInversionWarning):
resf2 = modf2.fit(method='bfgs')
assert resf2.converged is False
# assert np.isnan(resf2.bse).all()
# with pytest.warns(HessianInversionWarning):
# resf2 = modf2.fit(method='bfgs')
# assert resf2.mle_retvals["converged"] is False
# # assert np.isnan(resf2.bse).all()

assert_allclose(resf2.predict(data[:5]), fittedvalues[:5], rtol=1e-4)
# assert_allclose(resf2.predict(data[:5]), fittedvalues[:5], rtol=1e-4)


class TestCLogLogModel(CheckOrdinalModelMixin):
Expand Down Expand Up @@ -342,14 +342,14 @@ def _cdf(self, x):
distr=cloglog)
resp = modp.fit(method='bfgs', disp=False)

with pytest.warns(UserWarning):
modf = OrderedModel.from_formula(
"apply ~ pared + public + gpa - 1",
data={"apply": data['apply'].values.codes,
"pared": data['pared'],
"public": data['public'],
"gpa": data['gpa']},
distr=cloglog)
# with pytest.warns(UserWarning):
modf = OrderedModel.from_formula(
"apply ~ pared + public + gpa - 1",
data={"apply": data['apply'].values.codes,
"pared": data['pared'],
"public": data['public'],
"gpa": data['gpa']},
distr=cloglog)
resf = modf.fit(method='bfgs', disp=False)

modu = OrderedModel(
Expand Down

0 comments on commit 01c95e7

Please sign in to comment.