12

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.

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
Roey Angel
  • 325
  • 1
  • 4
  • 11

1 Answers1

16

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

Sven Hohenstein
  • 6,285
  • 25
  • 30
  • 39
  • Thanks! This certainly helps. How about computing the leverage for a Cook's distance vs. leverage plot? – Roey Angel Apr 01 '13 at 09: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 01 '13 at 09:34
  • Shouldn't it be `infl – Tomas 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_data0.1,drop=FALSE,] cooksD_oultiers – Elias Estatistics May 26 '17 at 14:29
  • Is this any better than the `hatvalues()` function [recommended here](https://www.ssc.wisc.edu/sscc/pubs/MM/MM_DiagInfer.html)? – Tomas Jun 19 '19 at 18:04