dput(df)
structure(list(Process = c("PROC050D", "PROC051D", "PROC100D",
"PROC103D", "PROC104D", "PROC106D", "PROC106D", "PROC110D", "PROC111D",
"PROC112D", "PROC113D", "PROC114D", "PROC130D", "PROC131D", "PROC132D",
"PROC154D", "PROC155D", "PROC156D", "PROC157D", "PROC158D", "PROC159D",
"PROC160D", "PROC161D", "PROC162D", "PROC163D", "PROC164D", "PROC165D",
"PROC166D", "PROC170D", "PROC171D", "PROC173D", "PROC174D", "PROC177D",
"PROC180D", "PROC181D", "PROC182D", "PROC185D", "PROC186D", "PROC187D",
"PROC190D", "PROC191D", "PROC192D", "PROC196D", "PROC197D", "PROC201D",
"PROC202D", "PROC203D", "PROC204D", "PROC205D", "PROC206D"),
Date = structure(c(15393, 15393, 15393, 15393, 15393, 15393,
15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393,
15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393,
15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393,
15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393,
15393, 15393, 15393, 15393, 15393, 15393, 15393, 15393), class = "Date"),
Duration = c(30L, 78L, 20L, 15L, 129L, 56L, 156L, 10L, 1656L,
1530L, 52L, 9L, 10L, 38L, 48L, 9L, 26L, 90L, 15L, 23L, 13L,
9L, 34L, 12L, 11L, 16L, 24L, 11L, 236L, 104L, 9L, 139L, 11L,
10L, 22L, 11L, 55L, 35L, 12L, 635L, 44L, 337L, 44L, 9L, 231L,
32L, 19L, 170L, 22L, 19L)), .Names = c("Process", "Date",
"Duration"), row.names = c(NA, 50L), class = "data.frame")
我正在尝试使用 IQR 方法从我的数据中捕获异常值。但是当我使用这些数据时,我也捕获了可能正常的数据。我喜欢从我的数据点中删除季节性,然后应用异常值规则。
进程列上有数千个不同的进程。我只需要捕获不正常的进程持续时间。任何想法如何从我的数据集中删除季节性?下面的代码计算异常值,但由于季节性因素,异常值可能是正常的。在计算异常值之前,我想从我的数据框中删除季节性。
library(data.table)
df<-df[, seventyFifth := quantile(Duration, .75), by = Process]
df<-df[, twentyFifth := quantile(Duration, .25), by = Process]
df<-df[, IQR := (seventyFifth-twentyFifth), by = Process]
df$diff<-df$Duration-df$seventyFifth
df<-df[, outlier := diff > 3 * IQR, by = Process]