필터 지우기
필터 지우기

Calculating Kendall's tau

조회 수: 78 (최근 30일)
Anna
Anna 2013년 8월 3일
편집: VENKATA PHANIKRISHNA B 2019년 10월 15일
Hi, I'm trying to calculate Kendall's tau using the 'corrcoef' command. My code so far is:
A_col = A_short'
idx = find(~isnan(B)+~isnan(A_col)==2);
[RHO,PVAL] = corrcoef(B(idx),A_col(idx),'type',Kendall)
The last line produces the error 'Undefined function or variable 'Kendall'. According to matlab help this is a valid value so how can I specify that I want a Kendall tau correaltion as oposed to a Pearson correlation?
Please help. Thanks

채택된 답변

Wayne King
Wayne King 2013년 8월 3일
편집: Wayne King 2013년 8월 3일
Hi Anna, 'Kendall' is not an option of corrcoef(). It is an option for the function corr(), which is part of the Statistics Toolbox.
So, this will work:
x = randn(30,4);
y = randn(30,4);
y(:,4) = sum(x,2);
[r,p] = corr(x,y,'type','Kendall');
provided you have the Statistics Toolbox
  댓글 수: 1
Anna
Anna 2013년 8월 3일
Hi Wayne, thank you that works brilliantly! I was worried that using corr instead of corrcoef would give me a huge matrix of r and p values but there's only one thankfully! Cheers :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

VENKATA PHANIKRISHNA B
VENKATA PHANIKRISHNA B 2019년 10월 15일
편집: VENKATA PHANIKRISHNA B 2019년 10월 15일
a = [15, 18, 21, 24, 27]' ;
b = [25, 25, 27, 31, 32]' ;
[RHO,PVAL] = corr(a,b,'Type','Pearson');
fprintf('Pearsons correlation: %.3f \n',RHO);
fprintf('Pearsons P: %.3f \n',PVAL);
[RHO,PVAL] = corr(a,b,'Type','Spearman');
fprintf('Spearman correlation: %.3f \n',RHO);
fprintf('Spearman P: %.3f \n',PVAL);
[RHO,PVAL] = corr(a,b,'Type','Kendall');
fprintf('Kendall correlation: %.3f \n',RHO);
fprintf('Kendall P: %.3f \n',PVAL);
Pearsons correlation: 0.953
Pearsons P: 0.012
Spearman correlation: 0.975
Spearman P: 0.033
Kendall correlation: 0.949
Kendall P: 0.033

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by