hopefully this post isn't a duplicate, but I've spent quite some time searching and haven't been able to find the answer.
I have two matrices that I am trying to make pairwise correlations between, that look like this.
Matrix 1
gene1 gene2 gene3
ID1 12 32 43
ID2 94 34 95
ID3 90 54 23
ID4 43 76 65
Matrix2
TE1 TE2 TE3
ID1 94 90 82
ID2 23 46 94
ID3 23 49 39
ID4 39 34 46
I'm able to get a table of R^2 values using the base function cor(), which only makes comparisons BETWEEN the matrices, in a pairwise way. The result looks something like this:
gene1 gene2 gene3
TE1 0.98 0.48 0.45
TE2 0.77 0.46 0.76
TE3 0.45 0.56 0.76
Which is great! But the problem is I need p values too, so I can cut the matrix down to those that have only p values less than a certain cutoff (because my real matrices are [30,800] and [30,1000] and I need a way to cut down the data to something intelligible).
The rcorr() package is great at this, as it produces a matrix r of correlations, a matrix P of p values, and a vector of the number of observations. BUT, I have not been able to figure out a way to compare only BETWEEN matrices- it also compares WITHIN matrices. I get a result looking like this:
gene1 gene2 gene3 TE1 TE2 TE3
gene1 1.0 0.5 0.5 0.5 0.3 0.9
gene2 1.0 0.4 0.7 0.7 0.5
gene3 1.0 0.8 0.8 0.5
TE1 1.0 0.8 0.2
TE2 1.0 0.7
TE3 1.0
This is made up data, but it illustrates the point. This produces twice as much data as I actually need, and slows down the calculations as well as produces correlation graphs that are nonsense, visually.
So my question is this: Is there a way to compare only between, not within matrices using the Hmisc package function rcorr()?
I've also tried the cor.test on lists of the matrices:
cor.test(c(matrix1),c(matrix2), method="pearson")
but I get an error that 'x' and 'y' must have the same length.
Next I have to figure out how to actually subset the matrices based on the list of those with high correlation and low p value, but I see there's some helpful answers here that I need to scrutinize.