2
$\begingroup$

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)
qqnorm(resid)
qqline(resid, col = 2)

and

shapiro.test(residuals(model, type = "normalized"))
$\endgroup$
3
$\begingroup$

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)

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

r_int<- ranef(model)$Subject$`(Intercept)`
qqnorm(r_int)
qqline(r_int)
shapiro.test(r_int)

r_slope<- ranef(model)$Subject$Days
qqnorm(r_slope)
qqline(r_slope)
shapiro.test(r_slope)
$\endgroup$
  • 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 Sep 29 '14 at 20:48
  • $\begingroup$ Good point. I have added some info about ranef and a link $\endgroup$ – Robert Long Sep 29 '14 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 Sep 30 '14 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 Sep 30 '14 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$ – Robert Long Sep 30 '14 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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