melff / mclogit

mclogit: Multinomial Logit Models, with or without Random Effects or Overdispersion
http://melff.github.io/mclogit/
22 stars 4 forks source link

Equivalent functions from lme4. #35

Closed barryrowlingson closed 4 months ago

barryrowlingson commented 4 months ago

I'm trying to fit a multinomial response mixed effects model on a largish (~150,000 row) data set and this package seems to be the only that can do it in reasonable time. But now I'm struggling to compare the model outputs with outputs from other mixed effects modelling packages, specifically lme4.

With an lme4 fitted model I can do ranef(m) and get the random effects, with the conditional variances matrix too. This can be fed into dotplot to get a plot of "confidence intervals" for the random effects. See help(lme4::ranef) for an example.

What I want to do is make these plots from mblogit output. It seems the $random.effects attribute has the random effects values, but I'm struggling to find or compute the equivalent conditional variances matrix.

My current working assumption is that the following two binomial models have the same model specification:

library(lme4)
library(HSAUR3) # toenail data
library(mclogit)
gl <- glmer(outcome~visit+(1|treatment), data=toenail, family=binomial)
mb = mblogit(outcome~visit, random=~1|treatment, data=toenail)

and if I can replicate ranef(gl) from mb then I'll be most of the way there. There are differences in these fitted models but I'm not sure if that's down to a completely different model specification or just a different optimiser stopping in essentially the same flat point of likelihood space.

melff commented 4 months ago

Recent commit c61be9dbdcf0ed4cf73784f32a3740e2f3101d58 implements support for ranef(). Can you check it out whether it works for you?