rmcelreath / glmer2stan

Define Stan models using glmer-style (lme4) formulas
55 stars 11 forks source link

missing a fixed effect level in model without intercept #1

Open ilyagoldin opened 11 years ago

ilyagoldin commented 11 years ago

This should work, using the VerbAgg dataset in lme4, but the Stan model doesn't compile:

library(glmer2stan)
library(lme4)
# glmer2stan doesn't like factor grouping variables
VerbAgg$id <- as.integer(VerbAgg$id)
lltm <- glmer2stan(r2 ~ -1 + btype + mode + situ + (1 | id), data=VerbAgg,
  family="binomial", calcDIC=FALSE, sample=FALSE)

The problem is that with the intercept removed (-1), all 3 levels of btype should be included in the data block, but glmer2stan only includes 2 levels. (It correctly uses all 3 levels in the parameters and model blocks.)

rmcelreath commented 11 years ago

Thanks for noting this. Not sure why it goes wrong in only the data block, since it's using the internal R methods for building the design matrix. But I will take a look early next week.

rmcelreath commented 11 years ago

I found the corner case, and I understand what's going wrong. BUT fixing it is not trivial, not without risking breaking other things. So it won't be an immediate fix. I have a couple of ideas, but not sure I'll get to work on this right away.

In the meantime, I'm happy that the bug prevents compilation, rather than running the wrong model.