1
$\begingroup$

Here's a plot of my residuals from a mixed-effects model in R (using lme4).

Residuals

There's one 'outlying' residual with a value of around 35 (index circa 90) that seems anomalous. I don't know if it has any statistical significance (any advice of that would be appreciated) but I'm curious if perhaps I've made an error entering that data point... but how can I find out what the record number for that observation is in my original data set?

$\endgroup$

2 Answers 2

2
$\begingroup$

Here is an example that illustrates how to find the indices of observations based on residuals.

An example:

library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
plot(residuals(fm1))

enter image description here

There are two residuals with a absolute value above 100. You can use which to obtain the indices.

which(residuals(fm1) > 100)
# 57 
# 57 
which(residuals(fm1) < -100)
# 8
# 8

The numbers appear twice because the function residuals returns a named vector, and the names are the indices.

$\endgroup$
0
1
$\begingroup$

Another possibility (you may need the development version of lme4, installable via devtools::install_github("lme4/lme4")) is

plot(fm1,id=0.05,idLabels=~.obs)

which will add observation-number labels to all observations in the 5% Normal tail of the residuals.

$\endgroup$
1
  • $\begingroup$ Thank you for the suggestion. I'm wary of confusing versions of lme4. Your suggestion with the idLabels does work with my current version of lme4 (1.1-7) however it requires about two dozen zeroes after the decimal point to prevent it plotting all the id labels. $\endgroup$
    – lithic
    Feb 15, 2015 at 10:28

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.