Skip to content

WIP ENH Tobit rebased2 - #7637

Open
josef-pkt wants to merge 21 commits into
statsmodels:mainfrom
josef-pkt:tobit_rebased2
Open

josef-pkt wants to merge 21 commits into
statsmodels:mainfrom
josef-pkt:tobit_rebased2

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Aug 11, 2021 •

Copy link
Copy Markdown
Member

rebased #2139 which was a rebase of skipper's original PR

conflict with tools decorator, I skipped the commit as conflict resolution
Patch failed at 0009 ENH: Add transform decorators with tests

needs another interactive rebase:

  • do file still in scikit namespace
  • tools/mat2nparray.ado is, I guess, an old, outdated version
  • tools/bigmat.ado I have no idea what this is or was used for

I guess this largely predates python 3
PR does not include unit tests results files. I had removed them in 2139.

@pep8speaks

Copy link
Copy Markdown

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

Line 194:19: W605 invalid escape sequence '('
Line 194:26: W605 invalid escape sequence ')'
Line 713:17: E711 comparison to None should be 'if cond is None:'
Line 883:18: E999 SyntaxError: invalid syntax

Line 2:1: F401 'numpy as np' imported but unused

@@ -0,0 +1,236 @@
import numpy.testing as npt
import numpy as np
from scikits.statsmodels.regression.censored_model import Tobit

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.

still uses scikit namespace

predict stdp, stdp
* calculates Pr(a < xb + u < b), the probability that y|x would be
* observed in the interval (a,b). Takes inf and neg. inf
predit pr2535, pr(25,35)

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.

type for predict?

return TobitResults(self, mlefit)

class TobitResults(base.LikelihoodModelResults):
def __init__(self, model, mlefit):

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.

no super call in __init__

#TODO: fix this to remove params, we need a general solution here
predict.__doc__ = Tobit.predict.__doc__

def webuse(data, baseurl='http://www.stata-press.com/data/r11/'):

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.

outdated
I think we have/had a function like this merged, but it should also work with pandas directly

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.

returns structured dtype, recarray

dta = StringIO(dta.read()) # make it truly file-like
return genfromdta(dta)

if __name__ == "__main__":

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.

remove
make notebook

true_params = np.array([-1.530712955415909, -.1051385059749894, .1282901151942823, -.0277671231250877, -.9434969317125149, -.085975029751076, .3128387422989903, .0142119678926689, 7.836529294458556, 4.498874144181835])

# ok
print 'Newton'

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.

py 2 print statement

@josef-pkt

Copy link
Copy Markdown
Member Author

two model classes TobitOlsen and Tobit
TobitOlsen seems to be unused and not unit tested, at least with code in this PR

@transform2(_exponentiate_sigma)
def score(self, params):
params, sigma = params[:-1], params[-1]
return self._score(params, sigma)

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.

too many helper functions and methods, makes it difficult to follow code.
params is not uniquely defined, params including scale/sigma, and params without scale/sigma

@lgtm-com

lgtm-com Bot commented Aug 11, 2021

Copy link
Copy Markdown

This pull request introduces 9 alerts when merging ab79784 into 47137eb - view on LGTM.com

new alerts:

  • 4 for Unused import
  • 2 for First argument to super() is not enclosing class
  • 1 for Testing equality to None
  • 1 for Module is imported more than once
  • 1 for Unused local variable

@josef-pkt

josef-pkt commented Aug 11, 2021 •

Copy link
Copy Markdown
Member Author

design: This PR splits observations into 3 arrays (for each, endog, exog) depending on the censoring type of the observation.
With this we loose information about the original sequence of observations. This is irrelevant in the pure cross-section case.

score_obs could be defined on arrays with rearranged observations. e.g. useful for HC cov_type.

Alternative design is to keep loglikeobs, score_obs and similar in original order. This is, for example, what I did in OrderedModel.
disadvantage is that we select/index arrays each time depending on membership of observations in different "regimes".

robust cov_type, brief coogle search for tobit

aside: Giles argues for specification testing instead of robust cov
http://web.uvic.ca/~dgiles/downloads/binary_choice/index.html for Logit and Probit

(I don't agree with Giles (and others that argue similarly), second comment by Jonah B. Gelbach sounds good to me)

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.

3 participants