How to use Outlier Tests in R Code

前端 未结 4 1507
难免孤独
难免孤独 2020-12-04 18:52

As part of my data analysis workflow, I want to test for outliers, and then do my further calculation with and without those outliers.

I\'ve found the outlier pack

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 19:32

    Try the outliers::score function. I don't advise removing the so called outlier's, but knowing your extreme observations is good.

    library(outliers)
    set.seed(1234)
    x = rnorm(10)
    [1] -1.2070657  0.2774292  1.0844412 -2.3456977  0.4291247  0.5060559 -0.5747400 -0.5466319
    [9] -0.5644520 -0.8900378
    outs <- scores(x, type="chisq", prob=0.9)  # beyond 90th %ile based on chi-sq
    #> [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
    x[outs]  # most extreme
    #> [1] -2.345698
    

    You'll find more help with outlier detection here

提交回复
热议问题