Repository navigation
Conversation
There was a problem hiding this comment.
Using centered=True option will give higher accuracy at the minimum or maximum
|
Can you add an example to statsmodels/examples (inside the source tree), so it's faster to try out an example. Also if you use an R script to generate reference numbers than you can commit it inside the test directory. |
|
Are there famous examples with public domain or non-restrictively licensed datasets that we can add for docs and unit tests, e.g. Binomial and Poisson? |
|
@gjhunt Do you have a list of references on which the implementation is based upon? We need references especially for the Laplace approximation both for review and maintenance internally, and also for users so they can check or learn what this actually does. |
Updated reg. with new lmm as base. Fixed file struct Removed unnec. files. Initital commit.
|
I'll look at finding some examples. I don't know if we can use the data that is used in the LME4 examples or vignettes? Those might be ideal but I'm not sure what the restrictions on using them are. Honestly the reference I've been using for the implementation is conversations with Kerby. I've been looking at some lecture notes form Michael Jordan for the Laplace approximation (http://www.cs.berkeley.edu/~jordan/courses/260-spring10/lectures/lecture16.pdf). I can look at getting some better references if we need them. I'll probably have to ask Kerby for what he views as good references. |
|
Some references: Also many references cited here: |
|
A document in progress attempting to derive the exact Laplace approximation for both canonical and non-canonical links: If this derivation is correct, then we need to add two things to the genmod base classes if we want to be able to use them with mixed models and non-canonical links:
|
There was a problem hiding this comment.
you can disable tests by changing the name instead of commenting out, that's less interuptive for the change history.
I often just add an underline like t_est_laplace_loglike_gamma or drop the "t" in "test", then nose will not identify as a unit tests
There was a problem hiding this comment.
Cool. I'll do that for future commits.
|
Updated. I got a correctly implemented gradient and hessian for the Laplace approximation sub-problem working for non-canonical links. It is noticeably faster than using the (albeit very accurate) numerical approximations. I need to now add some more tests for the log-like and add some tests showing the .fit() function. Things that might need to be fiddled with are the two optimization problems (1) for Laplace and (2) for .fit(). They can be temperamental. Although I'm highly confident that the things we are passing to them are correctly now. The current tests seem to pass well in the canonical cases however they still aren't matching quite perfectly for the non-canon cases. Its possible (probable?) that glmer is using an approximation to the Laplace approximation so I'll see if I can find anything about that. Something like that might explain the discrepancy. I'm fairly confident in these results so I'm starting to think that glmer is doing something different than a straight-up Laplace approximation. Strangely the log-like seems to be accurate for non-canon cases when the number of groups is small but diverges when this gets large. I'll look into that more. |
There was a problem hiding this comment.
So this is really a hack right now because MixedGLM assumes the log-likelihood to be in the normal form. We should probably support Gaussian case though? In which case this needs to be changed if it hasn't already in an updated version? I think I'm on .7 right now.
There was a problem hiding this comment.
|
For the binomial variance function it should be easy to use the analytic derivative. |
|
Do you have a derivation for your derivative and Hessian? I think what I derived earlier is the derivative and Hessian with respect to beta. We need the derivative and Hessian with respect to the random effects, right? |
|
We should retain the earlier simple canonical calculation and use it when applicable in the Laplace calculations. You can create a private variable _canonical_link for each family (e.g. _canonical_link = statsmodels.genmod.families.links.logit for Binomial family), then set a variable to true/false in the GLM class: self._canonical = isinstance(self.family.link, sm.family._canonical_link). If self._canonical is True you would use the old code that is simple and fast. It would also be good to come up with a test where you use the non-canonical code in a setting where the link is actually canonical, then compare the results using the old and new code. You could do that by creating a version of the link class that is not recognized as being the canonical link. |
|
So I added a GLM fit which initializes the start_params. I'm not sure it fixes or problems. I just added some fit tests comparing some canonical cases to R. As you can see the negative binomial test fails to fit even with the new GLM initialization. |
|
Viewed from the other side: Does this mean Gaussian, Binomial and Poisson work correctly? Those three are the important ones that are reasonably easy to optimize. The others might have messy optimization problems that need specific attention (after the GSOC). |
|
The short answer is yes. For canonical links those three fit correctly and quickly. |
Very good. I just remembered: R GLM doesn't have |
|
So for small data sets it can definitely fit some non-canonical links for those. Its a little more complicated than "which links work?". Things start to get difficult if the data gets too large. So for some links they work for small data sets and not for larger ones. Its hard to tell the accuracy because I don't have much to compare it against since R uses some approximation for non-canonical links. I added a Gaussian fit example which unfortunately isn't quite working yet. Not clear to me why the basic Gaussian case should be failing. |
|
General question: Does R also have adaptive quadrature as a numerical integration option? |
|
What I suggest given that we are running out of time for GSOC right now: Focus on the 3 cases that work: Gaussian, Binomial and Poisson with canonical link, and get the missing results (like bse/cov_params) and test coverage compared to R for those cases. |
|
That sounds like a good plan. I'll try to finish these up. |
|
What's the thoughts on leveraging some parallel computing for this stuff? the multiprocessing library is part of python's standard library. For larger data sets we might be able to justify the overhead. There are some embarrassingly parallel problems here e.g. computing the means for each point or even looping over groups. We could take advantage of multi-core processors this way. This wouldn't solve convergence problems but could give a speed-up. |
|
@gjhunt Yes, that will be a possibility to add. We have an optional dependency on However, I wouldn't add it in the first round when we still need to fix some problems, because it would make that more difficult. |
|
Yup. I think its best to try and get these convergence issues fixed. |
|
Is this still being worked on? It would be amazing to have a fully-featured LMM in statsmodels. |
|
Yes, I'm hoping to get this usable within a month or so. This is GLMM, our On Sun, Jan 10, 2016 at 9:06 PM, jona-sassenhagen [email protected]
|
|
Cool. The features I'm most missing would indeed be generalized linear mixed models plus crossed random effects. Both are huge right now in linguistics and psychology. |
|
We have decent support for crossed linear mixed models now. If you try it Mixed GLM is not really a "feature", it is an entirely different code base On Sun, Jan 10, 2016 at 9:15 PM, jona-sassenhagen [email protected]
|
Nice! |
It should be corrected in the documentation then, I was not using statsmodels LMM before because I needed crossed random effects and the docs say:
|
|
@mmagnuski I will change the docs. It remains unclear how powerful our implementation is when it comes to crossed effects. We do not use sparse Cholesky like R and some other packages. We do have some other tricks to help with performance. |
|
Is GLMM implementation still in progress? |
|
We have a new PR #4189 for this using a Bayesian approach. If you can try
it out and make comments that would be great.
…On Wed, Feb 7, 2018 at 11:25 AM, Paul Zivich ***@***.***> wrote:
Is GLMM implementation still in progress?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2516 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACiww3JujBwuJG0YlEbHij1DZ-Cc9NzOks5tSc5vgaJpZM4FWGiH>
.
|
|
This pull request introduces 14 alerts when merging 76b63d0 into b5cb3de - view on lgtm.com new alerts:
Comment posted by lgtm.com |
|
It looks like the Bayesian implementation of GLMMs is a great start but incomplete. What is the latest effort for supporting more families in GLMMs? I am just digging into this part of the code base, but would a reasonable implementation approach be to port/reuse some of the family (link and variance) calculations in the fit method for MixedLM to "prep" the model for fitting in GLM ? [Apologies if this seems like a rhetorical/naive question, really just trying to see how I can contribute] Conceptually, a GLMM can be thought of as a GLM with mixed effects, so it seems like we should be able to do some "matrix expansion" to include the random intercepts and slopes before using the GLM fitting procedure. I know that we might need a new fitting algo (which it seems the Bayesian implementation provides), but is there any reason we can't do this in GLM class? Am I missing something about the complexity of incorporating mixed effects in the the current GLM class implementation? |
Poisson and Binomial with cannonical links working. Non cannonical links not working yet. Gaussian not working.
edit (Josef)we need to squash the first 4 commits before merge, up to 0685f2f, to remove redundant copy of modules.