I have two matrices of equal dimensions (p and e) and I would like to make a spearman correlation between columns of the same name. I want to have the output of pair correlations in a matrix (M)
I used the corr.test() function from library Psych and here is what I did:
library(psych) M <- data.frame(matrix(ncol=3,nrow=ncol(p))) M[,1] <- as.character() G <- colnames(p) for(rs in 1:ncol(p){ M[rs,1] <- G[rs] cor <- corr.test(p[,rs],e[,rs],method="spearman",adjust="none") M[rs,2] <- cor$r M[rs,3] <- cor$p } But I get an error message:
Error in 1:ncol(y) : argument of length 0 Could you please show me what is wrong? or suggest another method?
corr.test(as.data.frame(p[,rs]), as.data.frame(e[,rs]), method="spearman", adjust="none"). The hint for this, from the error message, is that the function expects to have a two-dimensional data structure as x/y arguments.