gpt4 book ai didi

r - R中箱线图中的上下四分位数

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

我有

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

使用 boxplot,我试图绘制 quantile(X,0.25)quantile(X,0.75)但这与R中的箱形图的上下四分位数并不完全相同
boxplot(X)
abline(h=quantile(X,0.25),col="red",lty=2)
abline(h=quantile(X,0.75),col="red",lty=2)

enter image description here
你知道为什么吗?

最佳答案

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

?boxplot.stats:

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.



要查看这些值与奇数个观测值一致,请尝试以下代码:
set.seed(1234)
x <- rnorm(9)

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

enter image description here

关于r - R中箱线图中的上下四分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40634693/

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