我正在尝试使用mvOutlier()
中的MVN
软件包功能在卡方QQ图上标记异常值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)
这将产生以下结果:
我还尝试了text(x = xcoord, y = xcoord,label = labelsO)
,当点靠近y = x线时很好,但是当不满足正态性(并且点偏离此线)时可能会失败。
有人可以建议如何访问卡方位数或为什么函数的x坐标text()
似乎不服从输入参数。
从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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句