Skip to content

ENH: Tweedie log-likelihood (+ridge regression by gradient for all GLM) - #5521

Merged
kshedden merged 5 commits into
statsmodels:masterfrom
kshedden:tweedie
Mar 24, 2019
Merged

kshedden merged 5 commits into
statsmodels:masterfrom
kshedden:tweedie

Conversation

@kshedden

@kshedden kshedden commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

The quasi-likelihood allows fit_regularized to be used with Tweedie family GLM's.

Also bypasses coordinate-descent when calling fit_regularized on a GLM with L1_wt=0. This is ridge regression and can be fit more efficiently and accurately using gradients optimization.

#3670

Comment thread statsmodels/genmod/families/family.py Outdated
llf *= -1 / 2

u = endog ** (2 - p) - (2 - p) * endog * mu ** (1 - p) + (1 - p) * mu ** (2 - p)
u *= var_weights / (scale * (1 - p)**2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When testing with sas's formula I realize they actually have a typo it is (1-p)*(2-p) not (1-p)**2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will fix it. It you have a separate PR with better tests we can go with yours.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So I actually liked a paper by Kaas when I was studying this...

https://lstat.kuleuven.be/research/seminars_events/files/3afmd/Kaas.PDF

Page 8 has his formula for EQL (formula 4). The deviance on page 7 (formula 3) should pretty much be our _resid_dev method. You could call the existing method instead of re-writing it. You just have to add on the var_weights piece and the 2 * pi * scale adjustment.

You might also want to note in the doctoring that I think this EQL function is only valid when 1 < p < 2.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes exactly, only valid between 1 < p < 2 because at 1 you would use poisson and at 2 gamma.

Comment thread statsmodels/genmod/families/family.py Outdated
http://support.sas.com/documentation/cdl/en/stathpug/67524/HTML/default/viewer.htm#stathpug_hpgenselect_details16.htm
"""
return np.nan
if self.eql == False:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also has this been PEP8'ed? I recall that its preferred just to do a if not self.eql: but I have no clue what the rule is... But I feel like I've seen it somewhere...

@coveralls

coveralls commented Mar 5, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 84.561% when pulling b60c41c on kshedden:tweedie into 859ac51 on statsmodels:master.

@codecov

codecov Bot commented Mar 5, 2019

Copy link
Copy Markdown

Codecov Report

Merging #5521 into master will decrease coverage by 0.02%.
The diff coverage is 98.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5521      +/-   ##
==========================================
- Coverage   82.05%   82.02%   -0.03%     
==========================================
  Files         586      586              
  Lines       92741    92790      +49     
  Branches    10281    10287       +6     
==========================================
+ Hits        76095    76112      +17     
- Misses      14290    14318      +28     
- Partials     2356     2360       +4
Impacted Files Coverage Δ
statsmodels/genmod/tests/test_glm.py 99.05% <100%> (+0.02%) ⬆️
statsmodels/genmod/families/family.py 97.42% <100%> (+0.99%) ⬆️
statsmodels/genmod/generalized_linear_model.py 90.75% <95.23%> (+0.17%) ⬆️
statsmodels/iolib/openfile.py 66.66% <0%> (-9.1%) ⬇️
statsmodels/base/wrapper.py 86.95% <0%> (-4.35%) ⬇️
statsmodels/datasets/utils.py 80.24% <0%> (-3.09%) ⬇️
statsmodels/tsa/tsatools.py 87.3% <0%> (-2.48%) ⬇️
statsmodels/tsa/base/tsa_model.py 87.03% <0%> (-2.32%) ⬇️
statsmodels/iolib/tests/test_foreign.py 96.85% <0%> (-1.58%) ⬇️
statsmodels/iolib/foreign.py 71.23% <0%> (-1.39%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a33ef0...4afde23. Read the comment docs.

@codecov

codecov Bot commented Mar 5, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5521 into master will decrease coverage by 0.01%.
The diff coverage is 93.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5521      +/-   ##
==========================================
- Coverage   82.04%   82.02%   -0.02%     
==========================================
  Files         586      586              
  Lines       92741    92793      +52     
  Branches    10281    10288       +7     
==========================================
+ Hits        76086    76112      +26     
- Misses      14296    14320      +24     
- Partials     2359     2361       +2
Impacted Files Coverage Δ
statsmodels/genmod/tests/test_glm.py 99.05% <100%> (+0.02%) ⬆️
statsmodels/genmod/families/family.py 96.18% <78.57%> (-0.25%) ⬇️
statsmodels/genmod/generalized_linear_model.py 90.75% <95.23%> (+0.17%) ⬆️
statsmodels/iolib/openfile.py 66.66% <0%> (-9.1%) ⬇️
statsmodels/base/wrapper.py 86.95% <0%> (-4.35%) ⬇️
statsmodels/datasets/utils.py 80.24% <0%> (-3.09%) ⬇️
statsmodels/tsa/tsatools.py 87.3% <0%> (-2.48%) ⬇️
statsmodels/tsa/base/tsa_model.py 87.03% <0%> (-2.32%) ⬇️
statsmodels/iolib/tests/test_foreign.py 96.85% <0%> (-1.58%) ⬇️
statsmodels/iolib/foreign.py 71.23% <0%> (-1.39%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 859ac51...b60c41c. Read the comment docs.

@LudvicLaberge

Copy link
Copy Markdown

@kshedden I've been using your modified version and really like the new tweedie regularized fit! I was wondering, in general, how often are pull requests released to master on this repo and also, secifically, do we have an idea of when this PR will be released? Thank you for the improvements!

@kshedden

Copy link
Copy Markdown
Contributor Author

@LudvicLaberge Thanks for the feedback. We are in a bit of limbo now with broken master. But I will merge anyway in a week or so if things don't clear up.

@kshedden
kshedden merged commit d2783db into statsmodels:master Mar 24, 2019
@thequackdaddy

Copy link
Copy Markdown
Member

@kshedden Looking at the test suite results, it looks like your new test is failing on the python 2.7 travis-ci instances. Want to take a look at that?

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.

5 participants