使用箱线图的结果从数据框中提取离群值
Subsetting Outliers from a data frame by using the results of a boxplot diagram
我将我的数据转换为箱线图(使用 geom_boxplot 的 ggplot),以便异常值可见。之后我想从我的数据中删除它们。这就是为什么我使用 "ggplot_build" 获取情节的所有信息并用新名称保存它的原因。
Outlier_boxplot<-ggplot_build(boxplot)
现在可以提取具有离群值的列。在下一步中,我使用函数 "subset" 来 select 只有我的 data.frame 的值不等于提取的异常值。
Without_Outlier_dF<-subset(round(dF[1],digits=3),Test !=c(round(Outlier_boxplot$data[[1]]$outliers[[4]],digits=3))))
这几乎适用于所有情况。问题是,有时值(即使它们看起来相同)并没有被排除在外。
值提取 data.frame:
-234,347 75,764 93,34 95,237 99,005 100,044 97,924 98,875 98,072 99,569 98,848 98,414 99,33 96,901 99,29 100,359 99,169 97,828 97,146 97,229 94,278 97,146 97,229 94,278
异常值
-234.347 75.764 93.340 94.278
结果:除了值 94,278
之外的异常值被移除
95,237 99,005 100,044 97,924 98,875 98,072 99,569 98,848 98,414 99,33 96,901 99,29 100,359 99,169 97,828 97,146 97,229 94,278
我已经尝试对所有值进行四舍五入(如您所见),但没有用。你有什么想法吗?
geom_boxplot
调用boxplot.stats
计算上下胡须的位置。你也可以这样做:
> boxplot.stats(v)
$stats
[1] 93.340 96.069 97.876 99.087 100.359
$n
[1] 24
$conf
[1] 96.90265 98.84935
$out
[1] -234.347 75.764
(v
假定为您的输入数据向量):
来自 boxplot.stats
文档:
stats a vector of length 5, containing the extreme of the lower
whisker, the lower ‘hinge’, the median, the upper ‘hinge’ and the
extreme of the upper whisker.
n the number of non-NA observations in the sample.
conf the lower and upper extremes of the ‘notch’ (if(do.conf)). See
the details.
out the values of any data points which lie beyond the extremes of
the whiskers (if(do.out)).
我猜它包含您可能需要进行进一步分析的所有数据。
我将我的数据转换为箱线图(使用 geom_boxplot 的 ggplot),以便异常值可见。之后我想从我的数据中删除它们。这就是为什么我使用 "ggplot_build" 获取情节的所有信息并用新名称保存它的原因。
Outlier_boxplot<-ggplot_build(boxplot)
现在可以提取具有离群值的列。在下一步中,我使用函数 "subset" 来 select 只有我的 data.frame 的值不等于提取的异常值。
Without_Outlier_dF<-subset(round(dF[1],digits=3),Test !=c(round(Outlier_boxplot$data[[1]]$outliers[[4]],digits=3))))
这几乎适用于所有情况。问题是,有时值(即使它们看起来相同)并没有被排除在外。
值提取 data.frame:
-234,347 75,764 93,34 95,237 99,005 100,044 97,924 98,875 98,072 99,569 98,848 98,414 99,33 96,901 99,29 100,359 99,169 97,828 97,146 97,229 94,278 97,146 97,229 94,278
异常值
-234.347 75.764 93.340 94.278
结果:除了值 94,278
之外的异常值被移除95,237 99,005 100,044 97,924 98,875 98,072 99,569 98,848 98,414 99,33 96,901 99,29 100,359 99,169 97,828 97,146 97,229 94,278
我已经尝试对所有值进行四舍五入(如您所见),但没有用。你有什么想法吗?
geom_boxplot
调用boxplot.stats
计算上下胡须的位置。你也可以这样做:
> boxplot.stats(v)
$stats
[1] 93.340 96.069 97.876 99.087 100.359
$n
[1] 24
$conf
[1] 96.90265 98.84935
$out
[1] -234.347 75.764
(v
假定为您的输入数据向量):
来自 boxplot.stats
文档:
stats a vector of length 5, containing the extreme of the lower whisker, the lower ‘hinge’, the median, the upper ‘hinge’ and the extreme of the upper whisker.
n the number of non-NA observations in the sample.
conf the lower and upper extremes of the ‘notch’ (if(do.conf)). See the details.
out the values of any data points which lie beyond the extremes of the whiskers (if(do.out)).
我猜它包含您可能需要进行进一步分析的所有数据。