我最近阅读了有关建议,您通常不应使用中位数来消除异常值。示例:以下文章 http://www.amazon.com/Forensic-Science-Introduction-Scientific-Investigative/product-reviews/1420064932/
目前有16条评论:
review= c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 3, 2, 1, 1)
summary(review) ## "ordinary" summary
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 3.750 5.000 4.062 5.000 5.000
因为他们使用平均数,所以该文章获得4星,但是如果使用中位数,它将获得5星。
中位数不是“更公平”的法官吗?
实验表明,中位数误差始终大于平均值。中位数更糟吗?
library(foreach)
#the overall population of bookjudgments
n<-5
p<-0.5
expected.value<-n*p
peoplesbelieve <-rbinom(10^6,n, p)
#16 ratings made for 100 books
ratings <- foreach(i=1:100, .combine=rbind) %do% sample(peoplesbelieve,16)
stat <- foreach(i=1:100, .combine=rbind) %do% c(mean=mean(ratings[i,]), median=median(ratings[i,]))
#which mean square error is bigger? Mean's or Median's?
meansqrterror.mean<-mean((stat[,"mean"]-expected.value)^2)
meansqrterror.median<-mean((stat[,"median"]-expected.value)^2)
res<-paste("mean MSE",meansqrterror.mean)
res<-paste(res, "| median MSE", meansqrterror.median)
print(res)