【问题标题】:R: wilcoxon test Error: Grouping Factor must have exactly 2 levelsR:wilcoxon 测试错误:分组因子必须恰好有 2 个级别
【发布时间】:2017-06-29 14:32:36
【问题描述】:

我阅读了this SO questionthat one,但仍然无法解决我的问题。我有以下 data.table,其中仅包含我的 data.table 的总列和行中的一部分。

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>)

我想在访问为 1 和访问为 9 时对第 4 列进行 t.test。 我检查了 NA 以及两列的长度。

感谢您的帮助!

      #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)

【问题讨论】:

    标签: r compiler-errors statistics


    【解决方案1】:

    我刚刚发现, 而不是~ 可以解决我的问题。

    【讨论】:

      【解决方案2】:

      这里是如何对 column 4 分组 Value 执行 wilcoxon 测试

       library(dplyr)
       wilcox.test( filter(df, Visit==1)$CD38, filter(df, Visit==9)$CD38, paired=TRUE)
      

      【讨论】:

      • 我不想使用列名,因为我通常不知道它。我也在为多个列运行测试,并将使用循环对所有列运行测试。
      • 听起来你很难在所有列上自动运行它。每列只能有 2 个因子,并且每列都不适合测试。
      • 为什么不呢?它们都是数字列。我想始终对那些访问 ==1 和访问 ==9 的人运行测试,并在 2 中划分一列
      • 我明白了。我误解了你的意思multiple columns
      【解决方案3】:

      试试这个公式:

      wilcox.test(numeric_var ~ two_level_group_var)
      

      【讨论】:

        猜你喜欢
        • 2020-08-19
        • 1970-01-01
        • 1970-01-01
        • 2015-06-07
        • 2023-02-24
        • 1970-01-01
        • 1970-01-01
        • 2021-07-24
        • 1970-01-01
        相关资源
        最近更新 更多