gpt4 book ai didi

r - 在 R 中使用来自 MVN 的 mvOutlier 标记异常值

转载 作者:行者123 更新时间:2023-12-04 10:32:25 25 4
gpt4 key购买 nike

我正在尝试使用 mvOutlier() 在卡方 Q-Q 图上标记异常值MVN的功能包裹在 R .

我设法通过标签识别异常值并获得它们的 x 坐标。我尝试使用 text() 将前者放在情节上,但 x 和 y 坐标似乎颠倒了。

基于文档中的示例:

library(MVN)
data(iris)
versicolor <- iris[51:100, 1:3]
# Mahalanobis distance
result <- mvOutlier(versicolor, qqplot = TRUE, method = "quan")
labelsO<-rownames(result$outlier)[result$outlier[,2]==TRUE]
xcoord<-result$outlier[result$outlier[,2]==TRUE,1]
text(xcoord,label=labelsO)

这会产生以下结果:
Resulting plot

我也试过 text(x = xcoord, y = xcoord,label = labelsO) ,当点靠近 y = x 线时这很好,但当不满足正态性(并且点偏离这条线)时可能会失败。

有人可以建议如何访问卡方分位数或为什么 text() 的 x 坐标函数似乎不遵守输入参数。

最佳答案

看内部 mvOutlier函数,看起来它不保存卡方值。现在您的 text代码正在处理 xcoord作为 y 值,并假设实际的 x 值是 1:2 .幸运的是,卡方值是一个相当简单的计算,因为在这种情况下它是基于等级的。

result <- mvOutlier(versicolor, qqplot = TRUE, method = "quan")
labelsO<-rownames(result$outlier)[result$outlier[,2]==TRUE]
xcoord<-result$outlier[result$outlier[,2]==TRUE,1]
#recalculate chi-squared values for ranks 50 and 49 (i.e., p=(size:(size-n.outliers + 1))-0.5)/size and df = n.variables = 3
chis = qchisq(((50:49)-0.5)/50,3)
text(xcoord,chis,label=labelsO)

关于r - 在 R 中使用来自 MVN 的 mvOutlier 标记异常值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com