Skip to content
Prev 56131 / 398500 Next

detection of outliers

Hi Philippe,

you could consider using the Windsorized mean,

winds.mean <-  function(x, k=2){
    y <- x[!is.na(x)]
    mu <- mean(y)
    stdev <- sd(y)
    outliers.up <- y[y>mu+k*stdev]
    outliers.lo <- y[y<mu-k*stdev]
    y[y==outliers.up] <- mu+k*stdev
    y[y==outliers.lo] <- mu-k*stdev
    list(mean=sum(y)/length(y), outliers.up=outliers.up, 
outliers.lo=outliers.lo)
}
##################

x <- c(10,11,12,15,20,22,25,30,500)
mean(x)
winds.mean(x)

I hope this helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: <Phguardiol at aol.com>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, September 23, 2004 4:22 PM
Subject: [R] detection of outliers