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

查看:131
本文介绍了根据第二矩阵中的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矩阵中查找它们的p值来提取显着的相关性. c1>矩阵,我已经考虑使用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天全站免登陆