12
$\begingroup$

Does anyone know how to compute (or extract) leverage and Cook's distances for a mer class object (obtained through lme4 package)? I'd like to plot these for a residuals analysis.

$\endgroup$
16
$\begingroup$

You should have a look at the R package influence.ME. It allows you to compute measures of influential data for mixed effects models generated by lme4.

An example model:

library(lme4)
model <- lmer(mpg ~ disp + (1 | cyl), mtcars)

The function influence is the basis for all further steps:

library(influence.ME)
infl <- influence(model, obs = TRUE)

Calculate Cook's distance:

cooks.distance(infl)

Plot Cook's distance:

plot(infl, which = "cook")

enter image description here

$\endgroup$
5
  • $\begingroup$ Thanks! This certainly helps. How about computing the leverage for a Cook's distance vs. leverage plot? $\endgroup$
    – Roey Angel
    Apr 1 '13 at 9:31
  • $\begingroup$ @RoeyAngel I suppose this is not possible with the influence.ME package. Unfortunately, I don't have a solution for this task. $\endgroup$ Apr 1 '13 at 9:34
  • $\begingroup$ Shouldn't it be infl <- influence(model, group = "cyl"), because you specified random effect as (1|cyl)? I don't know, I don't understand this at all, I just installed influence... but I don't really know when to use obs = TRUE and when to use group... $\endgroup$
    – Tomas
    Dec 28 '15 at 10:11
  • $\begingroup$ I would like to add the following: If you would like to get the row number that Cook's D distances occur - the same number occuring in the plot without plotting, then you may use the following r formula about Cooks' D distances numbers with a cut off value of e.g. 0.1 cooksD_data<-as.data.frame(cooks.distance(ft1)) cooksD_data_select<-cooksd[cooksD_data>0.1,drop=FALSE,] cooksD_oultiers<-as.numeric(rownames(cooksD_data_select))] $\endgroup$ May 26 '17 at 14:29
  • $\begingroup$ Is this any better than the hatvalues() function recommended here? $\endgroup$
    – Tomas
    Jun 19 '19 at 18:04

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.