Skip to content
Prev 394229 / 398498 Next

grubbs test to detect all outliers

?s 14:09 de 28/04/2023, AbouEl-Makarim Aboueissa escreveu:
Hello,

With the data file you have attached I cannot reproduce any errors, all 
went well at the first try.


library(outliers)

fl <- "~/data_for_test.csv"
datafortest <- read.csv(fl)

# these are not needed to run the test
datafortest$factor1 <- as.factor(datafortest$factor1)
datafortest$factor2 <- as.factor(datafortest$factor2)
str(datafortest)
#> 'data.frame':    28 obs. of  7 variables:
#>  $ factor1: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 2 2 2 ...
#>  $ X      : num  4455 4348 10000 3813 7513 ...
#>  $ Y      : int  888 333 618 417 344 NA 341 999 265 557 ...
#>  $ factor2: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 2 ...
#>  $ Z      : int  999 475 507 603 442 486 927 971 388 888 ...
#>  $ U      : int  NA NA 252 332 216 217 698 311 999 444 ...
#>  $ V      : num  999 240 394 265 NA 275 479 562 512 777 ...
head(datafortest)
#>   factor1        X   Y factor2   Z   U   V
#> 1       1 4455.077 888       1 999  NA 999
#> 2       1 4348.031 333       1 475  NA 240
#> 3       1 9999.789 618       1 507 252 394
#> 4       1 3813.139 417       1 603 332 265
#> 5       1 7512.650 344       1 442 216  NA
#> 6       1 5642.667  NA       1 486 217 275

##### tried to use grubbs.test() on a single column of the dataframe, but
##### still not working
grubbs.test(datafortest$X, type = 11)
#>
#>  Grubbs test for two opposite outliers
#>
#> data:  datafortest$X
#> G = 4.6640014, U = 0.0091756, p-value = 0.02867
#> alternative hypothesis: 1826.851 and 99990.608 are outliers



Hope this helps,

Rui Barradas