在个人列之间的R和在给定数据帧的其余部分进行t检验 [英] t-test in R between individuals columns and the rest of a given dataframe
问题描述
这是在R.我需要帮助采取基本格式的数据框
This is in R. I need help taking a dataframe of basic format
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值,我打算通过一些变化得到:
and streamlining the task of taking a t-test of every column versus all the other columns combined. I also will need the p-values, which I plan to get via some variation on:
#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 ()作为这样一个分析的更好的选择?
Or would aov() be a better alternative for such an analysis?
推荐答案
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
。
Can use any of the values returned in the list from the function t.test. Could also have looped across the results of combn(names(dat), 2)
, which would be a choose(n,2)
matrix. (The square matrix has obvious redundant results) Obviously need a sensible adjustment for multiple testing. Could use p.adjust
.
这篇关于在个人列之间的R和在给定数据帧的其余部分进行t检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!