2

我正在使用lmrobR 中的函数,使用robustbase库进行稳健回归。我会用它作为,rob_reg<-lmrob(y~0+.,dat,method="MM",control=a1)。当我想返回我使用的摘要时summary(rob_reg),稳健回归所做的一件事就是识别数据中的异常值。摘要输出的某个部分给了我以下信息,

6508 observations c(49,55,58,77,104,105,106,107,128,134,147,153,...) are outliers with |weight| <= 1.4e-06 ( < 1.6e-06);

其中列出了所有异常值,在本例中为 6508(我删除了大部分并将其替换为 ...)。我需要以某种方式获取这些异常值并将它们从我的数据中删除。我之前所做的是用来summary(rob_reg)$rweights获取观察的所有权重,并删除那些权重小于上述示例中某个值的观察值 1.6e-06。我想知道,有没有办法在不首先获得所有观察值的权重的情况下获得仅包含异常值的列表?

4

1 回答 1

2

这是一篇旧帖子,但我最近需要这个,所以我想我会分享我的解决方案。

    #fit the model
    fit = lmrob(y ~ x, data)
    #create a model summary
    fit.summary = summary(fit)

    #extract the outlier threshold weight from the summary 
    out.thresh = fit.summary$control$eps.outlier

    #returns the weights corresponding to the outliers
    #names(out.liers) corresponds to the index of the observation
    out.liers = fit.summary$rweights[which(fit.summary$rweights <= out.thresh)]

    #add a True/False variable for outlier to the original data by matching row.names of the original data to names of the list of outliers
    data$outlier = rep(NA, nrow(data))
    for(i in 1:nrow(data)){
      data$outlier[i] = ifelse(row.names(data[i] %in% names(out.liers), "True", "False")
    }
于 2016-08-17T20:38:36.407 回答