Open cgonza12 opened 9 years ago
Thanks for the example. This package is low priority for me right now, but I have a colleague who is thinking of rewriting the parsing, which would likely fix these issues (as well as initially introduce new ones, no doubt).
Something that sometimes fixes it is to put the random effects first in the formula: (1|group) + x instead of x + (1|group).
Thanks Richard, I saw that you're thinking of discontinuing the package (it worked really well for me!). Never tried the reordering...looking forward to whatever's coming next!
Christian
On Tue, May 12, 2015 at 11:08 AM, Richard McElreath < notifications@github.com> wrote:
Thanks for the example. This package is low priority for me right now, but I have a colleague who is thinking of rewriting the parsing, which would likely fix these issues (as well as initially introduce new ones, no doubt).
Something that sometimes fixes it is to put the random effects first in the formula: (1|group) + x instead of x + (1|group).
— Reply to this email directly or view it on GitHub https://github.com/rmcelreath/glmer2stan/issues/6#issuecomment-101312510 .
I've never looked in detail at glmer2stan
but from an lme4
perspective, these lines look reasonable:
if (formula == nobars(formula)) {
ranef <- list()
}
The point of nobars
is to remove random effects terms from a mixed model formula. Therefore, in this example, random effects are only 'killed' if there are no random effects in the formula, which seems reasonable. From this I might guess that the real problem is actually upstream of these lines, perhaps another call to nobars
?
Issue: Disappearing Random effects
While I was using glmer2stan to run my dissertation I noticed that some of my more complex models woud have myseriously disappearing random effects. I've replicated the bug below and my solution. Not sure if anyone else has experienced this, but I figured its worth documenting
The above code seems to shit the bed when there's a mix of high and low level interactions specified with ':' instead of fully with '*'. Specifically when this mix is present, the model does not contain any random effects (but will run just fine which is scary).
The source of the issue is the parse_formula function. basically, lines 66 - 69
kill the random effects for some reason. I understand they are there in case the user is actually running a model with no random effects, e.g. a bivariate regression or something simple, but for some reason the inclusion of a mix of ':' throws things off.
In order to run my analyses, which had a mix of high and low-level interactions I tweaked your code slightly and wrote myglmer2stan. I included a function arguement 'Ranef' which specifies explicitly wehter or not there are random effects present. If there are, parse formula is declared without lines 66-69. If there are no randome effects than the existing parse formula function is specified. my function can be found here.
no more issue!