在 R 中的各个列和给定数据帧的其余部分之间的 t 检验 [英] t-test in R between individuals columns and the rest of a given dataframe

查看:22
本文介绍了在 R 中的各个列和给定数据帧的其余部分之间的 t 检验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆