I've been working on a GLMM in R and I see that an assumption of the test is that the random factor must be normally distributed (that is, unless you're using a package like hglm where you can specify a different distribution). However, I can't find any sort of code for how to test the distribution of the random effect, does anyone here have any ideas?

I'm only aware of how to test the residuals of the GLMM for normality, via:

resid <- residuals(model)
qqline(resid, col = 2)


shapiro.test(residuals(model, type = "normalized"))

1 Answer 1


In lme4 you can use the ranef() function which extracts the conditional modes of the random effects as a list of data frames, one entry in the list corresponding to one grouping factor. Further details are here. For example, with one grouping factor (for Subject), the following model has a random intercept and a random slope (for Days)

model <- lmer(Reaction ~ Days + (Days | Subject), data=sleepstudy)

r_int<- ranef(model)$Subject$`(Intercept)`

r_slope<- ranef(model)$Subject$Days
  • 1
    $\begingroup$ What exactly does ranef do? Readers who use non-R software surely would want to know so that they could apply your answer, too. $\endgroup$
    – whuber
    Commented Sep 29, 2014 at 20:48
  • $\begingroup$ Good point. I have added some info about ranef and a link $\endgroup$ Commented Sep 29, 2014 at 21:21
  • $\begingroup$ Thanks @RobertLong! To make sure I'm doing this right...My data has one random effect, "FocalID", that contains 40 different clusters. I used the following code: model<-lmer(VPL~Age+Sex+DET+DOC+GS+NND+Month+(1|FocalID),data=VPtest) ranef.model<-ranef(model)$FocalID$(Intercept)` qqnorm(ranef.model) qqline(ranef.model) shapiro.test(ranef.model)` Which gives me tests run on 40 different points. I'm confused about the use of Intercept and slope in your example though, could you explain how that might apply to my model? Do I need to use the actual output intercept value? $\endgroup$
    – Reese
    Commented Sep 30, 2014 at 0:24
  • $\begingroup$ Sorry, I'm new at formatting on these forums...so my code isn't quite posted correctly... and it wouldn't let me edit after my 5 minute timeframe was up! $\endgroup$
    – Reese
    Commented Sep 30, 2014 at 0:31
  • $\begingroup$ In your model you only have a random intercept, not a random slope, so you just need ranef(model)$Subject$``(Intercept) $\endgroup$ Commented Sep 30, 2014 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.