如何从箱形图提取正值和负值离群值到R中的单独变量中? [英] How do I extract positive and negative outliers from boxplots into separate variables in R?

查看:79
本文介绍了如何从箱形图提取正值和负值离群值到R中的单独变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制从箱形图到地图的离群值.我的讲师给我提供了从此箱线图

I need to plot the outliers from a boxplot on to a map. My lecturer gave me the function to extract all outliers from this boxplot:

离群值=匹配(名称(boxplot(pc3,图= FALSE)$ out),名称(pc3))

outliers = match(names(boxplot(pc3, plot = FALSE)$out), names(pc3))

(以pc3为数据)

然后我使用以下方法绘制它们:

I am then plotting them using:

points(Data.1 $ X [outliers],Data.1 $ Y [outliers],col ="red",cex = 3,lwd = 2)

points(Data.1$X[outliers], Data.1$Y[outliers], col = "red", cex = 3, lwd = 2)

但是我想将正离群值提取到一个变量中,将负离群值提取到另一个变量中,以便将它们绘制成不同的颜色.我该怎么做?

However I want to extract the positive outliers into one variable and the negative outliers into a different variable in order to plot them in different colours. How do I do this?

谢谢.

推荐答案

离群值由 boxplot 定义为距离框边(第75位和第25位)四分位数间距的1.5倍的点百分位数).您可以直接应用该定义:

Outliers are defined by boxplot as points farther than 1.5 times the inter-quartile range from the sides of the box (75th and 25th percentile). You can apply that definition directly:

iq.range <- quantile(pc3, probs=c(0.25, 0.75))
lower.bound <- iq.range[1] - 1.5*diff(iq.range)
upper.bound <- iq.range[2] + 1.5*diff(iq.range)

low.out <- pc3[pc3 < lower.bound]
high.out <- pc3[pc3 > upper.bound]

这是从头开始计算的.您还可以使用中位数拆分从 boxplot 获得的向量.以上是最重要的部分.

That's computing it from scratch. You can also split the vector that you get from boxplot using the median. Anything above is the higher part.

这篇关于如何从箱形图提取正值和负值离群值到R中的单独变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆