extracting signficant values from correlation matrix

Hello Dear friends
I was doing a correlation analysis from two data matrix.
From this large matrix, I want to get a significant one as a data frame for further analysis. The code and the data are simulated below.

mat = golub
rownames(mat) = paste0("G",1:nrow(mat))
#split the samples up randomly to get two matrix 
m1 = mat[,seq(1,ncol(mat),2)]
m2 = mat[,seq(2,ncol(mat),2)]
# run the correlation 
test = rcorr(t(rbind(m1,m2)))
n = nrow(m1)
# extract the top right block of the full matrix and reshape the data frame from wide to long
results = melt(test$r[1:n,(n+1):(2*n)],value.name ="pcc") %>% 
left_join(melt(test$P[1:n,(n+1):(2*n)],value.name ="p"),by=c("Var1","Var2")) 
 sig <- results[results$p < 0.05,]
#get the significant as data frame by change the data stracture from long to wide 
final <- results %>% filter(Var1 %in% sig$Var1 & Var2 %in% sig$Var2) %>% 
  recast(Var1 ~ Var2,data=.,measure.var="pcc")

Eeventhogh I have tried this but could get what I want( the significant).
It just returns me a data frame that contains the significant and the none significant elements.
Any help would be appreciated!
Best, AD

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.