[R] outlier detection in nonlinear regression

anders.mehler at online.de anders.mehler at online.de
Thu Mar 13 13:27:34 CET 2014


Dear useR's,
 
I have several biological data sets from laboratory experiments
where a few experiments failed completely due to bacterial 
contamination. Such cases can easily be seen "by eye" as "outliers".
 
Fitting a Michaelis-Menten kinetics works well with robust nonlinear
regression from package robustbase, but this helps me only partly 
because I need to remove the outliers for a subsequent analysis, 
so I need a reproducible automatic method.
 
I tried the following two heuristic approaches by either using the 
robust weights directly (A) or by applying a 3-sigma rule to the 
residuals (B), see example below.
 
My question: Is there any method available in R that is less heuristic 
than this?

Thank you in advance
 
Anders
 

library(robustbase)

## create data
set.seed(375)
x <- rep(0:10, 3)
y <- 5 * x / (2 + x) + rnorm(x, sd = 0.2)

## make outliers
y[c(3, 5, 10)] <- y[c(3, 5, 10)] + c(2, -1, -2)

## robust regression
m <- nlrob(y ~ a * x /(b + x),
   data = list(x = x, y = y),
   start = list(a = 1, b = 1))
summary(m)
xnew <- list(x = seq(0, 10, 0.1))
plot(x, y)
lines(xnew$x, predict(m, newdata = xnew))

## A) use robust weights to detect outliers
##    ?? how to select a critical value?
outA <- m$rweight < 0.5
points(x[outA], y[outA], pch = 16, col = "red")

## B) use 3 sigma of residuals to detect outliers
eps  <- residuals(m)
outB <- abs(eps) > (3 * sd(eps))
points(x[outB], y[outB], pch = 3, col = "blue")



More information about the R-help mailing list