# How to extract/compute leverage and Cook's distances for linear mixed effects models

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.

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")


• Thanks! This certainly helps. How about computing the leverage for a Cook's distance vs. leverage plot? – Roey Angel Apr 1 '13 at 9:31
• @RoeyAngel I suppose this is not possible with the influence.ME package. Unfortunately, I don't have a solution for this task. – Sven Hohenstein Apr 1 '13 at 9:34
• 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... – Curious Dec 28 '15 at 10:11
• 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))] – Elias Estatistics May 26 '17 at 14:29
• Is this any better than the hatvalues() function recommended here? – Curious Jun 19 '19 at 18:04