根据第二个矩阵中的 p 值从相关矩阵中提取值 [英] Extract values from a correlation matrix according to their p-value in a second matrix

查看:23
本文介绍了根据第二个矩阵中的 p 值从相关矩阵中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用外部程序创建了一个相关矩阵(SparCC).我也从 SparCC 中的相同数据计算了 p 值,最终得到了我导入到 R 中的两个对象,我们称它们为 corrpval

I have created a correlation matrix with an external program (SparCC). I have calculated p-values from the same data in SparCC as well and I end up with two objects which I imported into R, let's call them corr and pval and

> ncol(corr)==nrow(corr)
[1] TRUE

> ncol(pval)==nrow(pval)
[1] TRUE

> colnames(corr)==rownames(pval)
[1] TRUE ...

反之亦然.

由于矩阵(或者我应该使用 data.frame?)相当大(大约 1000 个项目),我想从 corr 矩阵通过在 pval 矩阵中查找它们的 p 值,我研究了用 apply 做一些事情:

Since the matrices (or should I be using data.frame?) are fairly large (about 1000 items), I would like to extract the significant correlations from the corr matrix by looking up their p-value in the pval matrix, I have looked into doing something with apply:

 extracted.values <- apply(corr, nrows(corr), which(pval<0.1))

但是由于带有which的部分并不是真正的函数,它会输出并出错.由于 which 命令输出 pval 矩阵中的位置列表,我对如何检索 colnamesrownames 用于每个所需的项目.

But since the part with which isn't really a function, it will output and error. Since the which command output a list of the position in the pval matrix, I'm a bit at loss as to how to retrieve the colnames and rownames for each desired items.

有没有更简单的方法来做我想做的事,比如在 R 中从头开始创建一个相关对象(这可能吗?)它包含 corrpval> 矩阵并提取显着值?我在 Python 中找到了这个解决方案,但是如果 R 的解决方案没有我想象的那么复杂,我们将不胜感激.

Is there an easier way of doing what I want, like creating a correlation object from scratch in R (is this at all possible?) which contains both corr and pval matrices and extracting the significant values? I have found this solution in Python, but a solution with R would be much appreciated if it's less complicated than what I think it is.

感谢您的帮助!

python 示例不保留标题.

edit: the python example doesn't keep headers.

推荐答案

你可以简单地做

corr[pval < 0.1]

这篇关于根据第二个矩阵中的 p 值从相关矩阵中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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