Repository navigation
Conversation
|
Major refactoring: moved all plotting code to regressionplots.py, moved method wrappers from genmod up to base. Added variable plots should work for any regression model with fitted values and residuals. Partial regression and ceres plots will currently work for GLM, GEE, OLS, WLS, and GLS. It needs a link function derivative. The idea could be extended to any single index model with a smooth link. |
|
about the single link (I'm still too distracted for the rest) similar issue is when users transform the y, e.g. endog = log(y) in linear regression. We have an open issue about getting the prediction, properties for the original y. Without being able to guess the transformation, users would have to specify which "link" they used. |
af06ff2 to
677294b
Compare
There was a problem hiding this comment.
plot_ first convention for methods.
|
I'm slightly wary of adding these to the top-level Result. It's almost certain they're going to show up for models they're not appropriate for this way no? |
|
I see what you mean. Added variable plot should be immediately applicable to GLM, GEE, OLS, discrete, and Cox models. Basically all it needs is some way of calculating residuals of the dependent variable. Partial residuals and CERES should work with GLM, GEE, and linear models. I'm not sure if there is a way to extend it to Cox models. Of course these things would be available from the functions in regressiongraphics, but it would be nice to have class methods. Would it make sense to have a RegressionModel subclass (of Model and Results), or mixin so that things that only make sense when there is a regression relationship can be easily attached to the model and results classes? |
|
I still have mixed feelings about the location for this. A Mixin might be a good solution (and we should get started with those anyway). Changing the class hierarchy requires more thought, and cannot just be added to a graphics PR. (I prefer to wait until we have a few more different model types before refactoring the class structure.) The other issue is that this needs unit tests for all major models where this is included. For example, fittedvalues in discrete still returns the linear prediction instead of the conditional expectation of endog. (I usually prefer to start with a narrower set of models until we know how it will work across all main models.) On the other hand this (or something like it) is applicable to a large number of classes. |
|
How about I remove all the attachments to model classes and results, and we can just focus on the functions in regressiongraphics for now? |
|
That would be much easier for merging this PR because we don't have to worry about every model that inherits it. We still want to add it to all relevant models, but we could also do it incrementally or for a larger group of models in a later PR. (Related similar issue: I think we can get score_tests pretty generally, but for my implementation I focus on OLS, discrete and GLM and don't think about whether it works for RLM and Quantile Regression for example.) |
There was a problem hiding this comment.
does fig still need to be closed after save?
I guess it should still be open.
|
@kshedden given that you have the unit tests for the GLM method. It will be a simple cut and paste later when we add it to a wider class or Mixin. |
|
I moved everything out of base and into GLM and GEE. Tests run fine locally, but travis doesn't seem to be running after my latest commit. |
1a0d2cb to
c52fb1a
Compare
|
@kshedden Do you know what the problem was with TravisCI? or why it went away? |
|
I think my master had gotten messed up. I did a hard reset of my master On Sun, Nov 23, 2014 at 6:38 PM, Josef Perktold [email protected]
|
|
OK, I will check the git history more carefully when I do a interactive rebase to squash before merging. Related: I opened a |
|
just as update: I checked out the branch and looked at the pdf file created by the test run. I hope to finish reviewing tomorrow (which is already today local time). |
There was a problem hiding this comment.
my guess is that we need to close the figure here also, since it will have been created with the matplotlib global registry.
I was just looking at the matplotlib testing facilities, There is a cleanup decorator but I haven't figured out enough yet whether and how to use it.
closing should be enough in our case, I think.
fig = result.plot_ceres_residuals(1)
fig.close()
|
Should the plots get a default |
|
merged in #2018 after rebase and squashing all commits into one. I didn't review all the details (again). I would expect some follow up changes when it is more used. |
This PR adds three diagnostic plots for GLM and GEE. Most of the code is shared between GLM and GEE.
I discovered a few missing things in GEEResults (family, various types of residuals) that are needed to make the plots work generically between GLM and GEE, so I added them.
The idea behind the CERES plot is a bit complicated. I believe that the implementation is correct, but the example in the test script doesn't highlight the technique well (it is an example where theoretically you don't need the CERES plot, the partial residual plot is adequate).
One possible extension is to allow the "focus" variable to be more than a single variable, e.g. a set of basis functions or indicators derived from a common underlying variable. I haven't figured out a clean way to do that yet, so am leaving it out for now (the approach has been defined in the literature, but implementing it involves figuring out which variables should be grouped)
The plots generated by the test script are here:
http://dept.stat.lsa.umich.edu/~kshedden/test_genmod_added_variable_plot.pdf
http://dept.stat.lsa.umich.edu/~kshedden/test_genmod_partial_residual_plot.pdf
http://dept.stat.lsa.umich.edu/~kshedden/test_genmod_ceres_plot.pdf