# How to get the correlation between two large (sparse) matrices?

I have two large (sparse) matrices (500000*500000) and would like to perform the mantel test to get a similarity measure.

• Is there a way to break-up these matrices into smaller ones and perform the test?
• Or can you suggest a way to do it efficiently without running into memory problems?
-
 If you just want to estimate a "similarity measure," you don't need the Mantel test: just compute (say) the Pearson correlation between the two matrices. – whuber♦ Oct 17 '11 at 16:18

## migrated from stackoverflow.comOct 7 '11 at 0:37

However, as these are sparse matrices, it's better to go after a method for accessing the data via coordinate object lists (COO representation), i.e. (row, column, value), and implement a simple calculation for tabulating the test statistic across the two matrices. You can merge the two matrices' COO versions or perform more complex tabulations using the data.table package.