R:wilcoxon测试错误:分组因子必须有2个水平
问题描述:
我读this SO question和that one,但仍然无法解决我的问题。我有以下data.table,其中只包括我的data.table的总列和行的几个。R:wilcoxon测试错误:分组因子必须有2个水平
library(data.table)
structure(list(Patient = c("MB108", "MB108", "MB108", "MB108",
"MB108", "MB108", "MB108", "MB108", "MB108", "MB108"), Visit = c(1,
1, 1, 1, 9, 9, 9, 9, 12, 12), Stimulation = c("NC", "SEB", "PPD",
"E6C10", "NC", "SEB", "PPD", "E6C10", "NC", "SEB"), `CD38 ` = c(83.3,
63.4, 83.2, 91.5, 90.9, 70.9, 71, 88.4, 41.7, 47.9)), .Names = c("Patient",
"Visit", "Stimulation", "CD38 "), class = c("data.table", "data.frame"
), row.names = c(NA, -10L), .internal.selfref = <pointer: 0x102806578>)
我想这样做在列4 t.test访问时为1,且当访问是9. 我检查对于NAS以及两列的长度。
感谢您的帮助!
#na.omit(boolean_dt3)
#print(length(unlist(boolean_dt3[Visit== 1,4, with = FALSE])))
#print(length(unlist(boolean_dt3[Visit== 9,4, with = FALSE])))
wilcox.test(unlist(boolean_dt3[Visit== 1,4, with = FALSE])~ unlist(boolean_dt3[Visit== 9,4, with = FALSE]) , paired = T, correct=FALSE)
答
下面是如何在column 4
分组由Value
library(dplyr)
wilcox.test(filter(df, Visit==1)$CD38, filter(df, Visit==9)$CD38, paired=TRUE)
答
我刚刚想出的,
代替~
作品我的问题进行Wilcoxon检验。
答
试试这个配方:
wilcox.test(numeric_var ~ two_level_group_var)
+0
这并没有提供问题的答案。一旦你有足够的[声誉](https://*.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://*.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/17849734) – QBrute
我不想使用的列名,因为我通常不知道它。我也在运行多列测试,并将使用一个循环来运行所有测试。 – Rivka
听起来像你会很难在所有列上自动运行它。每列只能有2个因子,每列不适合测试。 – CPak
为什么不呢?他们都是数字列。我想在访问== 1并访问== 9的人身上运行测试,并在我看到的2 – Rivka