我正在尝试为 R 中的配对 wilcox 测试添加 p 值。我正在使用以下代码。下面的代码为两种饮食(治疗)创建结果读数(二头肌)的小提琴(密度分布)。这些小提琴在时间 1、时间 2、时间 3 上动画。图的顶部打印 p 值。我希望这些 p 值是成对的值,这样
对于饮食“a”,将时间 2 的二头肌读数与时间 1 进行比较,并将时间 3 的二头肌读数与时间 1 进行比较。
饮食“b”也是如此。因此,在时间 2 和时间 3 的小提琴顶部应该有两个单独的 p 值。指示饮食“a”和饮食“b”的配对测试(时间 2 与时间 1 和时间 3 与时间 1) .
这个测试的正确代码应该是什么?我根据昨天收到的建议在下面尝试了一些方法,但遇到了错误。我还认为下面的代码只是对时间 2 与时间 1 和时间 3 与时间 2 进行配对测试。这不是我想要的。
谢谢阅读。
library(ggplot2)
library(ggpubr)
library(gganimate)
library(tidyverse)
示例数据
structure(list(code = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L), diet = c("a",
"a", "a", "b", "b", "b", "a", "a", "a", "b", "b", "b", "a", "a",
"a", "b", "b", "b", "a", "a", "a", "b", "b", "b"), time = c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), bicep = c(8L, 7L, 7L, 9L, 9L, 9L,
11L, 10L, 9L, 11L, 11L, 12L, 12L, 11L, 10L, 9L, 9L, 9L, 12L,
10L, 8L, 12L, 12L, 12L)), class = "data.frame", row.names = c(NA,
-24L))
示例代码
example3 %>%
group_by(time) %>%
mutate(p=pairwise.wilcox.test(example3$bicep, interaction(example3$diet, example3$time), p.adjust.method = "none")$p.value,
max=max(bicep, na.rm = T)) %>%
ggplot() +
geom_violin(aes(x=diet, y=bicep, fill=diet)) +
geom_text(data = . %>% distinct(p, max, time),
aes(x=1.5, y = max+.5, label=as.character(round(p,2))),
size=12) +
transition_time(time) +
ease_aes('linear')
这是我得到的错误
Error in mutate_impl(.data, dots) :
Column `p` must be length 8 (the group size) or one, not 25
In addition: There were 15 warnings (use warnings() to see them)