How to find 2d spearman and kendall correlations using corr2?

2 ビュー (過去 30 日間)
Lauren
Lauren 2020 年 6 月 4 日
コメント済み: Lauren 2020 年 6 月 4 日
I've been using corr2 to find correlation between two arrays. It calculates Pearson correlation.
I was hoping to repeat the code using Spearman or Kendall. Documentation doesn't mention the option to change type, but I tried anyway. Error says there are too many inputs.
A=[ 3 4 3; 0 3 0; 1 5 7];
B=[ 3 4 3; 0 3 0; 1 5 7];
C=corr2(A,B, 'Type', 'Kendall' );
Error using corr2>ParseInputs (line 30)
Too many input arguments.
Error in corr2 (line 21)
[a,b] = ParseInputs(varargin{:});
C=corr2(A,B) works just fine.
Does anyone know if it's possible to find Spearman or Kendall 2d correlation using corr2? If not, any suggestions?

採用された回答

Jeff Miller
Jeff Miller 2020 年 6 月 4 日
corr2 is doing the same computation as corr, except that it allows 2d inputs rather than 1d. So, you can get your Spearman or Kendall correlation using corr with the 'type' option, but pretending you have 1d rather than 2d inputs, e.g.
spear = corr(A(:),B(:),'type','Spearman')
  1 件のコメント
Lauren
Lauren 2020 年 6 月 4 日
Thank you!! That was really simple. Appreciate it!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by