Search code examples
rplotdiagnosticslmer

dotplot_diag for cooks distance (lmer model) - subject value instead of index


I'm using the tools in the HLMdiag package to look at diagnostics for a model fitted by lmer. I have a question about the dotplot_diag function for plotting cooks distances.

Here's an example of what I'm doing.

mod <- lmer(distance~age+Sex+(1|Subject), data=Orthodont)

cooksd <- cooks.distance(mod, group = "Subject")

dotplot_diag(x = cooksd, cutoff = "internal", name = "cooks.distance") + ylab("Cook's distance") + xlab("ID")

I get the following plot: enter image description here

Question: Is there a way to have influential points labelled with their Subject value instead of their index? i.e., it would show something like M13 or F10 (values in the Subject variable, see below).

head(unique(Orthodont$Subject))
[1] M01 M02 M03 M04 M05 M06

Thank you in advance for your help.


Solution

  • I think the index argument will work:

    dotplot_diag(x = cooksd, index=levels(Subject), 
     data=Orthodont, cutoff = "internal", name = "cooks.distance") + 
     ylab("Cook's distance") + xlab("ID")