简体   繁体   中英

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).

I alredy filter de p- values with the next code:

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. Is it any way to do this?

Any suggestion will be appreciate, thanks very much.

I melted both 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

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

Then, I filtered both. First, the p-values (<0.05).

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

And, next the stats (< -0.06 or > 0.06)

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

All that remains is to transform it back into a matrix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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