% Spearman Rank Order Correlation % Written by Wonho Song, October 2002 % E-mail: whsong@cau.ac.kr, whsong73@hotmail.com function [Rs,rr]=spearman(a) % Rs is the Spearman rank correlation % rr is the ranks matrix [n,p]=size(a); rr=[]; for i=1:p rr=[rr rankindx(a(:,i))]; end; Rs=zeros(p,p); for i=1:p for j=1:p r1=rr(:,i); r2=rr(:,j); d=r1-r2; d2=d'*d; Rs(i,j)=1-6*d2/(n^3-n); end; end; function [indexs]=rankindx(a) [n,p]=size(a); [x,I]=sort(a); index=zeros(n,1); index=1:n; index=index'; i=1; while i