Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the group1 name is group2 compare_means() error #450

Closed
wydty opened this issue Feb 15, 2022 · 0 comments
Closed

When the group1 name is group2 compare_means() error #450

wydty opened this issue Feb 15, 2022 · 0 comments

Comments

@wydty
Copy link

wydty commented Feb 15, 2022

When the group1 name is group2 compare_means() error

require(ggpubr)
tribble(
 ~val,    ~gp,  ~by,
 923 , 'group4','V1',
 1252, 'group4','V1',
 1442, 'group4','V1',
 1398, 'group2','V1',
 1858, 'group2','V1',
 1330, 'group2','V1',
 2593, 'group2','V1',
 23 ,  'group4','V2',
 252,  'group4','V2',
 442,  'group4','V2',
 398,  'group2','V2',
 858,  'group2','V2',
 330,  'group2','V2',
 593,  'group2','V2'
) %>% dplyr::mutate(gp=factor(gp, levels = c('group2','group4'))) -> dat
ggpubr::compare_means(formula = val ~ gp, data = dat, group.by = 'by', paired = F)
ggpubr:::.test_pairwise(dat, formula = val ~ gp)

Error: Problem with `mutate()` input `p`.
x Problem with `filter()` input `..1`.
x Input `..1` must be of size 1, not size 0.
ℹ Input `..1` is `!is.na(p)`.
ℹ Input `p` is `purrr::map(...)`.

image

ggppubr:::.test_pairwise

.test_pairwise2 <- function (data, formula, method = "wilcox.test", paired = FALSE, 
                             pool.sd = !paired, ...) 
{
 x <- deparse(formula[[2]])
 group <- attr(stats::terms(formula), "term.labels")
 if (ggpubr:::.is_empty(group)) {
  res <- .test(data, formula, method = method, ...)
  return(res)
 }
 method <- switch(method, t.test = "pairwise.t.test", wilcox.test = "pairwise.wilcox.test")
 test <- match.fun(method)
 test.opts <- list(x = ggpubr:::.select_vec(data, x), 
                   g =  ggpubr:::.select_vec(data,group), paired = paired)
 if (method == "pairwise.t.test") {
  if (missing(pool.sd)) {
   if (!paired) 
    pool.sd <- FALSE
  }
  test.opts$pool.sd <- pool.sd
 }
 pvalues <- suppressWarnings(do.call(test, test.opts)$p.value) %>% 
  as.data.frame()
 group1 <- group2 <- p <- NULL
 pvalues$.group2 <- rownames(pvalues)
 pvalues <- pvalues %>% tidyr::gather(
  key = "group1", value = "p", -.group2) %>%
  dplyr::select(group1, group2=.group2, p) %>%
  dplyr::filter(!is.na(p))
 pvalues
}
# .group2  temp name

.test_pairwise2(dat, formula = val ~ gp)
  group1 group2         p
1 group2 group4 0.3449883
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant