r - ggplot 中的中位数统计差异

标签 r ggplot2 significance

我有一个像这样的 ggplot 箱线图:

library(ggplot2)
data(iris)
ggplot(iris, aes(x = "", y = Sepal.Width)) +
    geom_boxplot()

如您所见,中位数是 3。假设真实值为 3.8 我想知道真实值 3.8 和观察值 3 之间是否存在统计差异,那么我应该使用哪种统计差异方法?我可以在 R 中实现它吗?也可以在图中绘制 3.8 的实际值吗?

谢谢!

PS:我使用 iris 数据集作为我的真实数据的一个易于重现的例子。

最佳答案

您正在寻找单样本 Wilcoxon 符号秩检验:

wilcox.test(iris$Sepal.Width, mu = 3.8)
#> 
#>  Wilcoxon signed rank test with continuity correction
#> 
#> data:  iris$Sepal.Width
#> V = 113, p-value < 2.2e-16
#> alternative hypothesis: true location is not equal to 3.8

您可以使用 geom_hline 向箱线图添加水平线,使用 geom_text 添加文本注释

ggplot(iris, aes(x = "", y = Sepal.Width)) +
  geom_boxplot() + 
  geom_hline(aes(yintercept=3.8), linetype = 2) +
  geom_text(aes(label = "True median", x = 0.5, y = 3.9))

enter image description here

关于r - ggplot 中的中位数统计差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59914151/

相关文章:

r - 具有从输入数据生成的美学效果的 ggplot

r - 在 R 中的热图中在连接的单元周围绘制等高线

c - 使用 "NA"将 R 数组传递给 C 函数

r - 使用 fread() 读取后无法子集数据框

python - 创建时间范围时间序列螺旋图

r - ggplot alpha = 0 不工作

r - 在 R 中具有显着性的多元相关矩阵

python - 将条形图之间的统计显着差异添加到 plotnine 图(ggpubr 等效)

r - 自定义 Xgboost 超参数调整

r - 在 x 轴上绘制带有因子变量的折线图