Skip to content

Betareg rebased3 Beta regression - #7543

Merged
josef-pkt merged 36 commits into
statsmodels:mainfrom
josef-pkt:betareg_rebased3
Jul 16, 2021
Merged

josef-pkt merged 36 commits into
statsmodels:mainfrom
josef-pkt:betareg_rebased3

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Jul 6, 2021 •

Copy link
Copy Markdown
Member

rebased version of #7282 Betareg_rebased2

This PR includes changes to the GenericLikelihoodModel classes

earlier PRs superseded by this PR
closes #7282 , closes #4238 , closes #4238 #2030

API still needs improvements

notebook with basic example from unit tests in gist https://gist.github.com/josef-pkt/4d0fd829c8fbc1c4237d989ba3dbb088

@pep8speaks

pep8speaks commented Jul 6, 2021 •

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 2021-07-16 17:52:56 UTC

@josef-pkt

Copy link
Copy Markdown
Member Author

If there are no serious problems here, then I can continue with the previous rebased2 branch and PR (that one is only 5 months old)

Comment thread statsmodels/miscmodels/betareg.py Outdated
if observed:
jgg += (mu * ymu_star + yt - mut) * q * h**3 # **3 ?

return np.column_stack((sf1, sf2)), (-jbb, -jbg, -jgg)

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.

has return_hessian
but seems to return it always

("different from expected", name, list(a), list(b))

def assert_close(a, b, eps):
assert np.allclose(a, b, rtol=0.01, atol=eps), (list(a), list(b))

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.

should be obsolete
use assert_allclose directly

Comment thread statsmodels/miscmodels/betareg.py Outdated
return var_endog


def nloglikeobs(self, params):

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.

I will deprecate nloglikeobs
just use loglikeobs

@lgtm-com

lgtm-com Bot commented Jul 13, 2021

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging 193d040 into 195be20 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once
  • 1 for Module is imported with 'import' and 'import from'

@lgtm-com

lgtm-com Bot commented Jul 13, 2021

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging d741310 into 195be20 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Module is imported with 'import' and 'import from'

@lgtm-com

lgtm-com Bot commented Jul 13, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 4e64f29 into 195be20 - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'

@josef-pkt

Copy link
Copy Markdown
Member Author

all green, including style check
pre testing still fails in statespace

get_distribution
I extended the results class version. But that does not take params, so it's less useful for simulation for, e.g., power where we have user specified params.

But if I use model.predict, then we don't get the transform/formula handling from inherited Results.predict.
I think that's also a limitation of current GLM.get_distribution.

Also inherited Results.predict cannot handle formula for second exog, i.e. exog_precision_formula in current api.

@josef-pkt

josef-pkt commented Jul 14, 2021 •

Copy link
Copy Markdown
Member Author

problem in predict with auxiliary data arrays

currently it assumes either both exog are specified or neither.
If only exog is given as arg not None, and exog_precision is None, then we should not take the model exog_precision.

GenericZeroInflated does not check for a default exog_infl, so user will have to specify all or nothing. #4757 #4952
Similar to offset, exposure in GLM, we can have the case where exog_precision is constant, and we use a default if exog_precision is None. In that case predict needs to check whether exog_precision is constant-only.

I think we need a flag, model attribute, to indicate whether the second exog_xxx was set by the default.
If users didn't specify exog_xxx in model, then they also don't need to specify it in predict. If exog_xxx was given by users, then it is required in predict and similar, unless it's the model attributes (no exog given in predict)

@josef-pkt

Copy link
Copy Markdown
Member Author

changing get_distribution to go through predict
predict inherits formula transformation for exog, but it's not available for exog_precision

two separate get_distribution with currently no code sharing,

  • results.get_distribution includes transformation from results.predict
  • model.get_distribution uses model.predict and needs numpy arrays

@lgtm-com

lgtm-com Bot commented Jul 15, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 40212c8 into 1745692 - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'

@lgtm-com

lgtm-com Bot commented Jul 15, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging b407be6 into 592133c - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'

@josef-pkt

josef-pkt commented Jul 16, 2021 •

Copy link
Copy Markdown
Member Author

results name BetaRegressionResults doesn't match the pattern, need to rename to ???

for discrete models, the convention is that the model class only uses the distribution name, results class is <distribution name>Results

in distributions I started with distribution_name is the name of the distribution class, and with postfix Model it's a model class and postfix Results for the results class
not so consistent DiscretizedCount is distribution class, DiscretizedModel is model class (without exog) and misses the "Count" in the name.
maybe not: DiscretizedModel in the current form might/should also work for ordered or categorical models, because all the discretized count details are delegated to the distribution instance.

For beta, I'm going with BetaModel, BetaResults
which can be used as pattern e.g. WeibullModel, WeibullResults,
AFTModel (?), AFTResults (?) maybe AFT is not a common enough acronym but AcceleratedFailureTimeModel is a bit long.

@lgtm-com

lgtm-com Bot commented Jul 16, 2021

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging 31de807 into fcc8b50 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Module is imported with 'import' and 'import from'

@josef-pkt

Copy link
Copy Markdown
Member Author

all green, merging

@josef-pkt
josef-pkt merged commit 6fcba02 into statsmodels:main Jul 16, 2021
@josef-pkt josef-pkt mentioned this pull request Jul 16, 2021
1 task done
@lgtm-com

lgtm-com Bot commented Jul 16, 2021

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging d343f64 into 1e1c54d - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Module is imported with 'import' and 'import from'

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