diff --git a/NEWS.md b/NEWS.md index 5adbf6ec..ce91f435 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ ## Bug fixes +- Now `compare_means()` returns the same p-values as `stat_compare_means()` ([@wydty, #15](https://github.com/kassambara/ggpubr/issues/34)). - `stat_compare_means()` now reacts to label = "p.format" when comparisons specified ([#28](https://github.com/kassambara/ggpubr/issues/28)). - Now, the p.values are displayed correctly when ref.group is not the first group ([@sehufnkjesktgna, #15](https://github.com/kassambara/ggpubr/issues/27)). diff --git a/R/compare_means.R b/R/compare_means.R index 130bbc34..fbe0781f 100644 --- a/R/compare_means.R +++ b/R/compare_means.R @@ -299,7 +299,9 @@ compare_means <- function(formula, data, method = "wilcox.test", # pairwise test #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -.test_pairwise <- function(data, formula, method = "wilcox.test", ...) +.test_pairwise <- function(data, formula, method = "wilcox.test", + paired = FALSE, pool.sd = !paired, + ...) { x <- deparse(formula[[2]]) @@ -318,8 +320,16 @@ compare_means <- function(formula, data, method = "wilcox.test", test <- match.fun(method) test.opts <- list(x = .select_vec(data, x), - g = .select_vec(data, group), ...) + g = .select_vec(data, group), + paired = paired, + ...) if(method == "pairwise.wilcox.test") test.opts$exact <- FALSE + else if(method == "pairwise.t.test"){ + if(missing(pool.sd)){ + if(!paired) pool.sd <- FALSE + } + test.opts$pool.sd <- pool.sd + } pvalues <- do.call(test, test.opts)$p.value %>% as.data.frame()