Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access outlier ids in lme plot

Tags:

plot

r

outliers

I'm plotting an lme fit object in r and get outlier ids (studyID) displayed on the graph, but I'd like to access these IDs automatically by looking them up in the plot object. I cannot figure out how to do this. I'm doing many analyses, thus it would help to be able to do this automatically rather than actually looking at each graph for the outlier id numbers.

Here's a simplified example of what I'm doing:

fit <- lme(dv ~ studyID + Gender + Group * DOP, random=~1|studyID, cor=corSymm(), na.action="na.omit", method="ML", data=x$data)

require (car)

plotObject <- plot(fit, resid(., type = "p") ~ fitted(.) | Group*DOP, abline = 0, id=.05)

What I want to be able to do is access some attribute of plotObject that stores the id numbers being used to identify outliers in the graph that results from the plot statement.

Thank you.

like image 855
user1895891 Avatar asked Dec 11 '12 20:12

user1895891


1 Answers

I don't know if this information is actually stored in the plot object, but it's easy enough to compute yourself. From ?plot.lme:

 id: an optional numeric value, or one-sided formula. If given as
          a value, it is used as a significance level for a two-sided
          outlier test for the standardized, or normalized residuals.
          Observations with absolute standardized (normalized)
          residuals greater than the 1 - value/2 quantile of the
          standard normal distribution are identified in the plot using
          ‘idLabels’.

So I would say that something like

library(nlme)
fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
which(abs(residuals(fm1,type="normalized"))>qnorm(0.975))
## M09 M09 M13 
##  34  35  49 
plot(fm1,id=.05)  ## for comparison

seems to do the trick.

like image 165
Ben Bolker Avatar answered Nov 17 '22 11:11

Ben Bolker