I have run the R function stl() function and use its generated residuals for grubbs test. The code is the following:
stl.res = stl(dataset, s.windows='periodic')
residuals = as.numeric(strl.res$time.series[, "remainder"])
grubbs.result = grubbs.test(residuals)
strsplit(grubbs.result$alternative,"")[[1]][3]
## [1] "38.4000349179783"
outlier = as.numeric(strsplit(grubbs.result$alternative,"")[[1]][3])
outlier
## [1] 38.40003492
which(residuals == outlier)
## integer(0)
My question is why the return value of which()
is 0. Actually residuals[1920] = 38.4000349179783
. So the call of which()
should return a value of 1921, not 0. I guess this is a problem with precision. I have tried many ways, but not managed to solve it.