这是很长的时间来解释我在做什么,因为我希望你对 R 和统计数据都没有经验。我什至不会解释为什么 Conover vs Dunn 更多的是统计数据交换,请参见此处
请在将来清楚您正在使用的软件包,rstatix
例如,您从未提及。 请附上您的数据样本。
# https://stackoverflow.com/questions/61922336/r-problems-plotting-p-values-from-conover-test-dunns-works-fine
library(dplyr)
library(ggpubr)
library(rstatix)
# I'm going to get the Conover test from this package
require(DescTools)
# You didn't provide data I will use mtcars
mydata <- mtcars %>% select(mpg, gear)
mydata$gear <- factor(mydata$gear)
# Here's what you were doing
stat.test.dunn <- mydata %>% dunn_test(mpg ~ gear, p.adjust.method = "hochberg")
stat.test.dunn <- stat.test.dunn %>% add_xy_position(x = "gear")
stat.test.dunn
#> # A tibble: 3 x 13
#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
#> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
#> 1 mpg 3 4 15 12 3.76 1.69e-4 5.06e-4 ***
#> 2 mpg 3 5 15 5 1.65 9.98e-2 2.00e-1 ns
#> 3 mpg 4 5 12 5 -1.14 2.54e-1 2.54e-1 ns
#> # … with 4 more variables: y.position <dbl>, groups <named list>, xmin <int>,
#> # xmax <int>
ggboxplot(mydata, x = "gear", y = "mpg", fill = "gear") +
stat_pvalue_manual(stat.test.dunn, hide.ns = FALSE)
这是我们如何“伪造”的方法
stat.test.Conover <- DescTools::ConoverTest(mpg ~ gear, mydata, method = "hochberg" )
stat.test.Conover
#>
#> Conover's test of multiple comparisons : hochberg
#>
#> mean.rank.diff pval
#> 4-3 13.658333 8.5e-05 ***
#> 5-3 7.966667 0.0767 .
#> 5-4 -5.691667 0.1434
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
stat.test.Conover[[1]]
#> mean rank diff pval
#> 4-3 13.658333 8.490683e-05
#> 5-3 7.966667 7.666748e-02
#> 5-4 -5.691667 1.433731e-01
things_we_want <- rstatix::add_significance(data = as.data.frame(stat.test.Conover[[1]]))
things_we_want
#> mean rank diff pval pval.signif
#> 1 13.658333 8.490683e-05 ****
#> 2 7.966667 7.666748e-02 ns
#> 3 -5.691667 1.433731e-01 ns
stat.test.Conover <- stat.test.dunn
stat.test.Conover
#> # A tibble: 3 x 13
#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
#> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
#> 1 mpg 3 4 15 12 3.76 1.69e-4 5.06e-4 ***
#> 2 mpg 3 5 15 5 1.65 9.98e-2 2.00e-1 ns
#> 3 mpg 4 5 12 5 -1.14 2.54e-1 2.54e-1 ns
#> # … with 4 more variables: y.position <dbl>, groups <named list>, xmin <int>,
#> # xmax <int>
stat.test.Conover$p.adj <- things_we_want$pval
stat.test.Conover$p.adj.signif <- things_we_want$pval.signif
stat.test.Conover
#> # A tibble: 3 x 13
#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
#> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
#> 1 mpg 3 4 15 12 3.76 1.69e-4 8.49e-5 ****
#> 2 mpg 3 5 15 5 1.65 9.98e-2 7.67e-2 ns
#> 3 mpg 4 5 12 5 -1.14 2.54e-1 1.43e-1 ns
#> # … with 4 more variables: y.position <dbl>, groups <named list>, xmin <int>,
#> # xmax <int>
ggboxplot(mydata, x = "gear", y = "mpg", fill = "gear") +
stat_pvalue_manual(stat.test.Conover, hide.ns = FALSE)