フィルターのクリア

How to calculate correlation between two distance matrices?

28 ビュー (過去 30 日間)
Magdalena Kachlicka
Magdalena Kachlicka 2021 年 4 月 21 日
編集済み: Magdalena Kachlicka 2024 年 5 月 15 日
Hello everyone,
I have quite a naive question about correlations - which method is appropriate for establishing a correlation between two distance matrices?
I have data in the format of distance matrices (10 x 10, zeros on diagonal, examples attached), and I'd like to compare whether two such matrices are correlated with one another. The data comes from similarity ratings of pairs of 10 items and MDS analyses of the stimuli they were rating and, as such, can also be represented as similarity matrices or sets of coordinates in 2-dimensional space. What I want to do, is to check if there is any correlation between these two distance matrices.
As a first intuition, I've used Matlab corrcoef/corr2 function to compute a correlation coefficient between the two matrices, but it has been pointed out that I should use Spearman's rho instead. As far as I can tell, the function corr calculating Spearman's rho returns a matrix of values which I'm not sure how to interpret (what each of these values tells me about the overall correlation between the two matrices?) or how to convert these results into a single value that compares the two matrices.
I thought that perhaps my data is not in an appropriate format, so I tried converting it into condensed vectors (using the squareform function and transposing it into a column vector), but I'm not sure if that's the correct way of doing it. After doing this, the corr function produces dramatically lower correlation coefficients (from highly significant Spearman's r = 0.4468 to non-significant rho = 0.03). Other functions called spearman and spear produce the same results.
On the other hand, if I understand correctly, none of these methods (neither Pearson's nor Spearman's) is actually appropriate for capturing non-linear relationships in the data like this.
I've also been reading about Distance Correlation and Mantel's Test as more appropriate methods for calculating correlations between distances. I found the distcorr function, but it calculates only the r coefficient, not the significance measure. I haven't found any reliable source for Mantel's Test calculation.
As you can see, a simple correlation question confused me a bit, and I've been quite puzzled about what I should be doing, why and how to appropriately prepare my data for analysis. Do you have any suggestions about the best approach here? Any advice would be super appreciated, thanks!

採用された回答

Nipun
Nipun 2024 年 5 月 15 日
Hi Magdalena,
I understand that you are trying to find a correlation between two distance matrices. For a concise approach using MATLAB, you can use the Mantel test through custom functions or toolboxes since it is not directly available in MATLAB's standard functions. However, for simplicity and direct application, I will guide you through calculating Spearman's rho for the entire matrices by first converting them into vectors. This method provides a straightforward way to assess the correlation between your distance matrices.
Here is how you can do it:
  1. Convert your distance matrices into vectors excluding the diagonal (zero) elements using the squareform function.
  2. Calculate Spearman's rho between these two vectors to get a single correlation coefficient.
% Assuming matrix1 and matrix2 are your two distance matrices
% Convert matrices to vectors excluding diagonals
vec1 = squareform(matrix1);
vec2 = squareform(matrix2);
% Calculate Spearman's rho
[rho, pval] = corr(vec1', vec2', 'Type', 'Spearman');
% Display the results
fprintf('Spearman''s rho: %f\n', rho);
fprintf('P-value: %f\n', pval);
This MATLAB code snippet converts your distance matrices into a format suitable for correlation analysis and then computes Spearman's rho, providing you with both the correlation coefficient and its significance level. This approach is appropriate for your case, capturing the monotonic relationship between the distances in your matrices.
Hope this helps.
Regards,
Nipun
  1 件のコメント
Magdalena Kachlicka
Magdalena Kachlicka 2024 年 5 月 15 日
編集済み: Magdalena Kachlicka 2024 年 5 月 15 日
Hi Nipun,
Thanks for your response!
I completely forgot about this thread I posted years ago, but yes, Mantel test was indeed what I found to be a solution to this problem - I used the implementation of Mantel's test from ape package for R (putting it here just in case someone else needs it). Thanks for prividing a workable example in Matlab

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by