Skip to content

ENH: Ordinal model rebased2 - #7035

Merged
josef-pkt merged 30 commits into
statsmodels:masterfrom
josef-pkt:ordinal_model_rebased2
Oct 1, 2020
Merged

josef-pkt merged 30 commits into
statsmodels:masterfrom
josef-pkt:ordinal_model_rebased2

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

continuation of #7021 without adding frame as Model.__init__ kwd

without last commit of #7021, and amended second to last commit to remove changes to base.Model

@pep8speaks

pep8speaks commented Sep 15, 2020 •

Copy link
Copy Markdown

Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-10-01 19:33:19 UTC

@lgtm-com

lgtm-com Bot commented Sep 15, 2020

Copy link
Copy Markdown

This pull request introduces 1 alert when merging dcff941 into 4328705 - view on LGTM.com

new alerts:

  • 1 for Unused import

@coveralls

coveralls commented Sep 15, 2020 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.06%) to 88.393% when pulling 42b9fa4 on josef-pkt:ordinal_model_rebased2 into 0376f69 on statsmodels:master.

@lgtm-com

lgtm-com Bot commented Sep 15, 2020

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging 0241fd5 into 4328705 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Variable defined multiple times

@josef-pkt

Copy link
Copy Markdown
Member Author

that worked, only failures are with lint check.

The advantage is that I keep the information now inside from_formula the hackish part is that I need to fix up the created instance and change the model outside __init__. Also, I guess missing handling works, but I don't have unit tests for that.
This could be refactored if we get #7033.

Comment thread statsmodels/miscmodels/ordinal_model.py Outdated
if exog is None:
exog = self.exog
if offset is None:
offset = self.offset

@josef-pkt josef-pkt Sep 16, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect if exog is not None but offset is None. that should raise error about shape mismatch of exog and self.offset (in line 279 below)
see #4595 and referenced commit that fixed this for count models

no unit test coverage for case when those are None.

@lgtm-com

lgtm-com Bot commented Sep 16, 2020

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging c1664d9 into 4328705 - view on LGTM.com

new alerts:

  • 1 for Illegal raise
  • 1 for Variable defined multiple times

@josef-pkt

josef-pkt commented Sep 16, 2020 •

Copy link
Copy Markdown
Member Author

all green, I have all the minimum parts that I wanted.

  • maybe change name to OrdinalModel instead of OrderedModel.
  • currently remains as subclasses of genericlikelihood
  • post-estimation, diagnostics: I haven't looked much yet for those
  • extensions,
    • with offset implemented, it would be relatively easy to add fit_constrained
    • I have not yet looked at margins for it.

still ambiguous: how can we ascertain that we have no constant when using formulas? i.e. get correct patsy behavior
update done below following PHReg pattern

I'm still not sure which parameterization of constant versus thresholds would be better. Green argues that if the parameterization includes a constant, then the model reduces to standard Logit or Probit in the binary case.

  • null model and loglike, needs interface, computed in unit tests and start_params
  • possible things to add to summary ?
  • confint for predicted probabilities, separate not jointly.

unit test for binary case are missing.
no verifying unit tests for offset
unit tests for predict with offset in model

np.exp(th_params[1:]))).cumsum()
thresh = np.concatenate(([-np.inf], thresh, [np.inf]))
xb = exog.dot(params[:-(self.k_levels - 1)])[:, None]
low = thresh[:-1] - xb

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUG: missing offset
and it should delegate to _linpred

also option for what to return, e.g. linear, cdf, ...

@josef-pkt

josef-pkt commented Sep 22, 2020 •

Copy link
Copy Markdown
Member Author

Now with null loglike and results wrapper.

todo: review docstrings, update notebook

undecided: resid, fittedvalues, endog_dummies maybe as non-cached properties
I haven't checked pickling and remove_data

in general: do we add something like wald_test_null?, it's just a oneliner like return wald_test(np.eye(len(params)[:k_vars])
"wald null pvalue" in summary ?

@josef-pkt

Copy link
Copy Markdown
Member Author

default optimizer is "nm", should be "bfgs" which converges much faster

@josef-pkt

Copy link
Copy Markdown
Member Author

I need to merge this before I get distracted to much by other things and extensions.

I have prototype functions for plots #6435 (comment)
but I don't want to wait for those to become "clean". maybe I name those plot_reset_binary or similar.
Reset plots (observed versus fitted) need axis limits that depend on model, e.g. [0, 1] for binary, positive for count, unrestricted (min-max of data) for gaussian.
related to that reset tests and similar #3690

MNLogit and OrderedModel can share some postestimation functions.
(margins works for MNLogit, but missing pieces for OrderedModel)
also no comparison yet to Kerby's GEE.

@josef-pkt

Copy link
Copy Markdown
Member Author

some diagnostic plots for countmodels are in semi-private discrete._diagnostics_count.plot_probs (mainly used in my notebooks)

@lgtm-com

lgtm-com Bot commented Sep 29, 2020

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 76bdf47 into 0376f69 - view on LGTM.com

new alerts:

  • 1 for Illegal raise

@josef-pkt

Copy link
Copy Markdown
Member Author

case exog=None, offset=None: is it allowed?

@josef-pkt

Copy link
Copy Markdown
Member Author

comparison to OrdinalGEE, see #7068

@josef-pkt
josef-pkt force-pushed the ordinal_model_rebased2 branch from 76bdf47 to 0e4578a Compare October 1, 2020 16:12
@josef-pkt

Copy link
Copy Markdown
Member Author

Merging to get it out of the way.

Might need another round of cleaning/docs

@josef-pkt

josef-pkt commented Oct 2, 2020 •

Copy link
Copy Markdown
Member Author

@bashtage
Can you check the last commit to see if I added the notebook correctly?
I received a message with jekyll page build error with "Page build timed out"

The notebook ordinal_regression is there in https://github.com/statsmodels/statsmodels.github.io/tree/master/devel/examples/notebooks/generated
but the html file doesn't show up in the docs

update
I rerun the page build and it finished without error.
notebook is at devel https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html
but dev gives me a 404 file not found at the moment
https://www.statsmodels.org/dev/examples/notebooks/generated/ordinal_regression.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants