在R中使用3d绘图时识别异常值

在R中使用3d绘图时识别异常值,r,outliers,R,Outliers,我是R新手,有1024行数据和3列数字数据。我已经创建了一个plot3d,我需要识别异常值的行号,该异常值在plot3d中非常突出,但在任何其他图形中都是不可见的。使用内置的intarrayInd查找最大值(或最小值): 例如,我们将用一个拇指制作一个3列数据帧 df <- data.frame(structure(replicate(3, runif(1024, 0, 1), simplify = FALSE), .Names = c('one', 'two', 'three'))) d

我是R新手,有1024行数据和3列数字数据。我已经创建了一个plot3d,我需要识别异常值的行号,该异常值在plot3d中非常突出,但在任何其他图形中都是不可见的。

使用内置的int
arrayInd
查找最大值(或最小值):

例如,我们将用一个拇指制作一个3列数据帧

df <- data.frame(structure(replicate(3, runif(1024, 0, 1), simplify = FALSE), .Names = c('one', 'two', 'three')))
df[50, 2] <- 10

我们看到罪犯在第50行和第2列。

欢迎用户3479729。请发一封信。否则你要么得不到答案,要么就得不到好答案

如果“M”是您绘制的矩阵,“thres”是您的异常数据阈值(我需要在此假设您正在绘制矩阵?),您可以使用:

> which(M>thres,arr.ind=TRUE)

希望这能帮你完成工作

> data <- c(-1.5454, -0.6855, 0.1003, -0.5284, -0.4065, -0.2645, 
            -1.0868, -0.5329, 0.1623, -1e-04, -0.9569, -2.0055, 
            0.389, -0.8356, -2.2085, 0.5326, 0.0391, -0.5044, 
            -1.8376, -0.7834, 0.3436)
## original data
> dd <- data.frame(matrix(data, ncol = 3, byrow = TRUE))
## find the row number of the largest row maximum
> which.max(apply(dd, 1, max))
[1] 6
## Use the previous line to remove the unwanted row
> newDd <- dd[ -which.max(apply(dd, 1, max)), ] 
## plot the two data frames together to see the difference
> library(plot3D)
> par(mfrow = c(1, 2))
> with(dd, scatter3D(X1, X2, X3, phi = 0, theta = 50, bty = "g",
                     col = gg.col(100), pch = 19, cex = 2, colkey = FALSE))
> with(newDd, scatter3D(X1, X2, X3, phi = 0, theta = 50, bty = "g",
                        col = gg.col(100), pch = 19, cex = 2, colkey = TRUE))
>数据dd which.max(应用(dd,1,max))
[1] 6
##使用上一行删除不需要的行
>newDd库(plot3D)
>par(mfrow=c(1,2))
>具有(dd,散射体3d(X1,X2,X3,φ=0,θ=50,bty=“g”,
col=gg.col(100),pch=19,cex=2,colkey=FALSE)
>用(newDd,scatter3D,X1,X2,X3,φ=0,θ=50,bty=“g”,
col=gg.col(100),pch=19,cex=2,colkey=TRUE)

请发布您的数据样本,以及您迄今为止尝试过的代码,这是我的一些数据-1.5454-0.6855 0.1003-0.5284-0.4065-0.2645-1.0868-0.5329 0.1623-1e-04-0.9569-2.0055 0.389-0.8356-2.2085 0.5326 0.0391-0.5044-1.8376-0.7834 0.3436谢谢你的回答,但去掉最小值和最大值后,异常值似乎只出现在plot3D仍然存在。我被引导去创建一个人工构建的因子,我猜它会以某种方式分组,但我不知道该分组什么。我试着把行号放在一列中,并以此进行颜色编码,但我得到的只是一个浅绿色的异常值,我仍然不能确定它来自哪一行。
> which(M>thres,arr.ind=TRUE)
> data <- c(-1.5454, -0.6855, 0.1003, -0.5284, -0.4065, -0.2645, 
            -1.0868, -0.5329, 0.1623, -1e-04, -0.9569, -2.0055, 
            0.389, -0.8356, -2.2085, 0.5326, 0.0391, -0.5044, 
            -1.8376, -0.7834, 0.3436)
## original data
> dd <- data.frame(matrix(data, ncol = 3, byrow = TRUE))
## find the row number of the largest row maximum
> which.max(apply(dd, 1, max))
[1] 6
## Use the previous line to remove the unwanted row
> newDd <- dd[ -which.max(apply(dd, 1, max)), ] 
## plot the two data frames together to see the difference
> library(plot3D)
> par(mfrow = c(1, 2))
> with(dd, scatter3D(X1, X2, X3, phi = 0, theta = 50, bty = "g",
                     col = gg.col(100), pch = 19, cex = 2, colkey = FALSE))
> with(newDd, scatter3D(X1, X2, X3, phi = 0, theta = 50, bty = "g",
                        col = gg.col(100), pch = 19, cex = 2, colkey = TRUE))