简体   繁体   English

用 R 过滤相关矩阵及其 p 值矩阵

[英]Filter correlation matrix ands its p-value matrix with R

I have two matrix, one with correlation stats and another with p-values, they have 942 x 942 dimensions and I need to filter first the significative p-values (< 0.005) and then extract the significative correlations (> 0.60).我有两个矩阵,一个带有相关统计数据,另一个带有 p 值,它们的维度为 942 x 942,我需要先过滤显着的 p 值(< 0.005),然后提取显着的相关性(> 0.60)。

I alredy filter de p- values with the next code:我已经用下面的代码过滤了 p 值:

pvalues <- as.matrix (pvalues)
pvalues[pvalues > 0.05] <- NA

But now, I need to extract the stats and the same objects from the other matrix, and it must haver more than 0.60.但是现在,我需要从另一个矩阵中提取统计数据和相同的对象,并且它必须超过 0.60。 Is it any way to do this?有什么办法吗?

Any suggestion will be appreciate, thanks very much.任何建议将不胜感激,非常感谢。

I melted both df我融化了两个df

pvalues.melt <- melt(pvalues)
stats.corr.melt <- melt(stats.corr)

Then, I save de stats as a vector and add that column to the p-value data frame然后,我将 de stats 保存为向量并将该列添加到 p 值数据框中

stats <- as.vector(stats.corr.melt$value)
pvalues.stats <- cbind(pvalues.melt, stats)

Then, I filtered both.然后,我过滤了两者。 First, the p-values (<0.05).首先,p 值 (<0.05)。

pvalues.filter <- filter(pvalues.stats, value < 0.05)

And, next the stats (< -0.06 or > 0.06)并且,接下来是统计数据(< -0.06 或 > 0.06)

stats.filter <- filter(pvalues.filter, stats < -0.6 | stats > 0.6)

All that remains is to transform it back into a matrix.剩下的就是将其转换回矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM