R中箱线图中的上下四分位数 [英] lower and upper quartiles in boxplot in R

查看:1942
本文介绍了R中箱线图中的上下四分位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

X=c(20 ,18, 34, 45, 30, 51, 63, 52, 29, 36, 27, 24)

使用boxplot,我试图绘制quantile(X,0.25)quantile(X,0.75) 但这与R中的箱形图的上下四分位数并不相同

With boxplot, i'm trying to plot the quantile(X,0.25) and quantile(X,0.75) but this is not realy the same lower and upper quartiles in boxplot in R

boxplot(X)
abline(h=quantile(X,0.25),col="red",lty=2)
abline(h=quantile(X,0.75),col="red",lty=2)

你知道为什么吗?

推荐答案

该框的值称为铰链,可能与四分位数重合(由quantile(x, c(0.25, .075))计算),但计算方式不同.

The values of the box are called hinges and may coincide with the quartiles (as calculated by quantile(x, c(0.25, .075))), but are calculated differently.

来自?boxplot.stats:

两个铰链"是第一个和第三个四分位数的版本,即接近分位数(x,c(1,3)/4).铰链等于奇数n的四分位数(其中n <-length(x)),而偶数n则不同.四分位数仅等于n %% 4 == 1(n = 1 mod 4)的观测值,而铰链另外等于n %% 4 == 2(n = 2 mod 4)的观测值,并且在两个中间否则观察.

The two ‘hinges’ are versions of the first and third quartile, i.e., close to quantile(x, c(1,3)/4). The hinges equal the quartiles for odd n (where n <- length(x)) and differ for even n. Whereas the quartiles only equal observations for n %% 4 == 1 (n = 1 mod 4), the hinges do so additionally for n %% 4 == 2 (n = 2 mod 4), and are in the middle of two observations otherwise.

要查看这些值是否与奇数个观测值一致,请尝试以下代码:

To see that the values coincide with an odd number of observations, try the following code:

set.seed(1234)
x <- rnorm(9)

boxplot(x)
abline(h=quantile(x, c(0.25, 0.75)), col="red")

这篇关于R中箱线图中的上下四分位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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