【问题标题】:Error in match.arg(p.adjust.method) : 'arg' must be NULL or a character vectormatch.arg(p.adjust.method) 中的错误:“arg”必须为 NULL 或字符向量
【发布时间】:2018-07-25 10:48:54
【问题描述】:

这是我的数据

mydat=structure(list(id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), group = c(1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 3L, 3L, 3L, 3L), var = c(23L, 24L, 24L, 23L, 23L, 
24L, 24L, 23L, 23L, 24L, 24L, 23L, 23L, 24L, 24L, 23L, 23L, 24L, 
24L, 23L, 23L, 24L, 24L, 23L)), .Names = c("id", "group", "var"
), class = "data.frame", row.names = c(NA, -24L))

我想加入两个表。 id 是标识符。

library(tidyverse)
mdyat %>% 
  with(.,pairwise.wilcox.test(var,id, group, exact =F)) %>% 
  broom::tidy() %>% 
 complete(id,group) %>% 
  left_join(mydat %>% 
              group_by(id,group)) %>% 
              summarise_all(c("mean", "sd", "median")) 
            by=c("id,group")

并得到错误

Error in match.arg(p.adjust.method) : 
  'arg' must be NULL or a character vector

如何做到这一点,这个脚本分别为每个标识符执行 IE。期望的输出

id      mean    sd      median  p.value
1   1   23,5    0.5773503   23,5    NA
1   2   23,5    0.5773503   23,5    1
1   3   23,5    0.5773503   23,5    1
2   1   23,5    0.5773503   23,5    NA
2   2   23,5    0.5773503   23,5    1
2   3   23,5    0.5773503   23,5    1

【问题讨论】:

  • 您的错误发生在pairwise.wilcox.test方法中。您刚刚尝试了 with 部分吗?
  • @Roland,我删除它。我不小心
  • @Linus ,这个问题与这个话题有关stackoverflow.com/questions/51495838/…。我该怎么做才能正确?
  • @Linus,我也试过这部分并得到同样的错误
  • pairwise.wilcox.test 将 x= 作为向量和组。之后是 p.value 校正。你交出 3 个变量而不是 2 个

标签: r dplyr tidyr


【解决方案1】:

可以使用group_bydo 修复第一部分,如下所示。

mydat %>% 
  group_by(id) %>%
  do({
    with(., pairwise.wilcox.test(var, group, exact =F)) %>% broom::tidy()
  }) 

 ## # A tibble: 6 x 4
 ## # Groups:   id [2]
 ##      id group1 group2 p.value
 ##   <int> <fctr>  <chr>   <dbl>
 ## 1     1      2      1       1
 ## 2     1      3      1       1
 ## 3     1      3      2       1
 ## 4     2      2      1       1
 ## 5     2      3      1       1
 ## 6     2      3      2       1

为了将其与汇总统计信息结合起来,您需要决定要加入哪个组(group1group2)。下面我加入了group1,所以meansdmedian指的是group1p.value指的是group1group2之间的区别。

mydat %>% 
  group_by(id) %>%
  do({
    with(., pairwise.wilcox.test(var, group, exact =F)) %>% broom::tidy()
  }) %>% 
  mutate(group1 = as.numeric(as.character(group1)), 
         group2 = as.numeric(as.character(group2))) %>%
  complete(group1 = mydat$group) %>%
  left_join(mydat %>% group_by(id,group) %>% summarise_all(c("mean", "sd", "median")), 
            by=c('id', 'group1'='group'))

【讨论】:

  • shadow,是错误df2=mydat。我编辑了帖子。请检查一下
  • 如何加入第二部?
  • 我看到你的编辑。但我需要加入描述性统计数据
  • 我不明白你想如何连接这两个部分。 Wilcoxon 检验是两组之间的检验。在您的预期输出中,您似乎总是与第 1 组进行比较,因此您得到 NA p 值。这是你想做的吗?
  • 我想对每个组分别进行id,计算wilcox检验,然后计算描述性统计。在我想要的输出中,我展示了它。我不知道该怎么做。类似的任务在这篇帖子stackoverflow.com/questions/51495838/… 中,但是Jimbou 的解决方案只能按组工作,没有按ID 分隔。
【解决方案2】:

你的函数参数错误:

pairwise.wilcox.test(var,id, group, exact =F)

?pairwise.wilcox.test 将正确的语法表述为:

pairwise.wilcox.test(x, g, p.adjust.method = p.adjust.methods,
                      paired = FALSE, ...)

这意味着第三个函数参数应该是p.adjust.method,而不是group

【讨论】:

  • 我需要为 id 和 group 计算 U.test,然后计算描述性统计数据并将结果连接到所需的表中。
  • for id and group 是什么意思?分别作为分组变量,还是分别将每个idgroup 作为分组变量?
  • 是的,每个id分别用group作为分组变量
猜你喜欢
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多