gpt4 book ai didi

R - stat_compare_means 从 Kruskal-Wallis 测试返回不同的值

转载 作者:行者123 更新时间:2023-12-05 03:56:17 24 4
gpt4 key购买 nike

我想使用 ggpubr 包中的 R 函数 stat_compare_means 将 Kruskal-Wallis 检验的 p 值绘制到我的 ggplot 中。

但是,绘制的值与我简单运行该函数时的值不同:

kruskal.test(value ~ type, data = Profile_melt)

我绘制 p 值的代码是:

ggplot(Profile_melt, aes(type, value)) + 
geom_boxplot(aes(fill = factor(type), alpha = 0.5),
outlier.shape = NA, show.legend = FALSE) +
geom_jitter(width = 0.2, size = 2, show.legend = FALSE,
aes(colour = factor(type)), alpha = 0.5) +
theme_bw() +
facet_grid(Case ~ Marker, scales = 'free') +
stat_compare_means(comparison = list(c("Real", "Binomial")),method = 'kruskal.test')+
background_grid(major = 'y', minor = "none") + # add thin horizontal lines
xlab('Category') +
ylab('Cell counts (Frequencies)')+
theme(axis.text = element_text(size = 15),
axis.title = element_text(size = 20),
legend.text = element_text(size = 38),
legend.title = element_text(size = 30),
strip.background = element_rect(colour="black", fill="white"),
strip.text = element_text(margin = margin(10, 10, 10, 10), size = 25)) +
panel_border()

这是我的数据 sample data

最佳答案

有许多代码行可能与问题无关。或许,您的问题可能是:

为什么

kruskal.test(value ~ type, data = Profile_melt)

#Kruskal-Wallis chi-squared = 4.9673, df = 1, p-value = 0.02583

产生不同的p值

ggboxplot(Profile_melt, x="type", y = "value") + 
stat_compare_means(comparison = list(c("Real", "Binomial")), method = 'kruskal.test')

# p-value = 0.49

您可以通过查看原始代码来找出原因。 ggpubr 的开发人员可能会更好地解释这一点,如果出现问题,可能会在那里修复它。要获得正确且一致的 p 值,请删除 comparison = list(c("Real", "Binomial")):

ggboxplot(Profile_melt, x="type", y = "value") + 
stat_compare_means(method = 'kruskal.test')

编辑

ggboxplot(Profile_melt, x="type", y = "value") + 
stat_compare_means(comparison = list(c("Real", "Binomial")))

使用您的其他代码,图形如下所示:

enter image description here

关于R - stat_compare_means 从 Kruskal-Wallis 测试返回不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59494025/

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