【问题标题】:t-test in R between individuals columns and the rest of a given dataframe在个人列和给定数据框的其余部分之间的 R 中的 t 检验
【发布时间】:2013-04-24 18:54:24
【问题描述】:

这是在 R 中。我需要帮助来获取基本格式的数据框

       NAC     cOF3     APir       Pu       Tu     V2.3     mOF3     DGpf
1 6.314770 6.181188 6.708971 6.052134 6.546938 6.079848 6.640716 6.263770
2 8.825595 8.740217 9.532026 8.919598 8.776969 8.843287 8.631505 9.053732
3 5.518933 5.982044 5.632379 5.712680 5.655525 5.580141 5.750969 6.119935
4 6.063098 6.700194 6.255736 5.124315 6.133631 5.891009 6.070467 6.062815
5 8.931570 9.048621 9.258875 8.681762 8.680993 9.040971 8.785271 9.122226
6 5.694149 5.356218 5.608698 5.894171 5.629965 5.759247 5.929289 6.092337

并简化对每一列与所有其他列组合进行 t 检验的任务。我还需要 p 值,我计划通过以下一些变化来获得:

#t-test
test.result = mapply(t.test, select.column, other.columns)
#store p-values
p.values = stack(mapply(function(x, y) t.test(x,y)$p.value, select.column, other.columns))

或者 aov() 会是这种分析的更好选择吗?

【问题讨论】:

  • ANOVA 与常见的事后测试(例如 Tukey's)是更好的选择,因为它可以降低 1 类错误的风险

标签: r statistics dataframe


【解决方案1】:
sapply(names(dat), function(x) 
         sapply( names(dat), function(y) t.test(dat[[x]],dat[[y]])$statistic ))

可以使用函数 t.test 在列表中返回的任何值。也可以循环遍历combn(names(dat), 2) 的结果,这将是一个choose(n,2) 矩阵。 (方阵有明显的冗余结果)显然需要对多次测试进行合理的调整。可以使用p.adjust

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2013-04-25
    • 1970-01-01
    相关资源
    最近更新 更多