多组配对 Wilcox 检验

问题描述

这是我的数据的随机生成版本:

df=data.frame(matrix(NA,nrow = 25,ncol = 4))
df$X1=c(rep(1,5),rep(2,rep(3,rep(4,rep(5,5))
df$X2=c(1.08,1.08,0.45,1.27,2.63,2.03,1.54,0.57,2.32,0.37,2.48,2.48)
df$X3=c("Run-in",rep("Intervention",2),rep("Wash-out",2))
df$X4=c(rep("OF",rep("YF",rep("OM",rep("YM",rep("OF",5))
colnames(df)=c("subject","ratio","period","group")
df$period = factor(df$period,levels=c("Run-in","Intervention","Wash-out"))
df

前几行如下所示:

    subject ratio       period group
        1    1.08       Run-in    OF
        1    1.08 Intervention    OF
        1    0.45 Intervention    OF
        1    1.08     Wash-out    OF
        1    0.45     Wash-out    OF
        2    1.27       Run-in    YF
        2    2.63 Intervention    YF
        2    2.03 Intervention    YF
        2    1.08     Wash-out    YF
        2    1.54     Wash-out    YF
        3    2.03       Run-in    OM
        3    2.63 Intervention    OM
        3    1.08 Intervention    OM
        3    0.57     Wash-out    OM

我想要做的是找出该比率在研究期间(磨合、干预、清洗)之间是否存在显着差异,为此我想使用配对 wilcox 检验,因为它是同一组每个采样点的受试者数量。

我最初使用 pairwise.wilcox.test 时没有意识到“成对”和“成对”之间的区别。如果我尝试 pairwise.wilcox.test(df$ratio,df$period,paired=T),我会收到错误消息:“wilcox.test.default(xi,xj,paired = paired,...) 中的错误:'x' 和 'y' 必须具有相同的长度”

如果我尝试使用 wilcox.test(ratio~period,df,paired=T) 进行配对 wilcox 测试,我会收到错误 Error in wilcox.test.formula(ratio ~ period,data = df,paired = T) : grouping factor must have exactly 2 levels

如何告诉 wilcox.test 函数我想比较磨合与干预、干预与洗出以及磨合与洗出进行配对测试?

如果我这样做

df %>%
  filter(period != "Intervention") %>%
  group_by(period) %>%
  summarise(p_value = wilcox.test(df$ratio,ratio,exact = FALSE)$p.value)

我得到了磨合到干预和干预到冲出的比较,但没有磨合到冲出。它也没有配对。如果我尝试通过添加 paired=T 使其配对,则会出现错误:

"Error: Problem with summarise() input p_value. x 'x' and 'y' must have the same length ℹ Input p_value is wilcox.test(df$ratio,exact = FALSE,paired = T)$p.value. ℹ the error发生在第 1 组:期间 = "磨合"。"

感谢任何帮助。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...