1 function r = spearman(x,y)
2 % SPEARMAN Spearman's rank correlation coefficient.
3 % This function is replaced by CORRCOEF.
4 % Significance test and confidence intervals can be obtained from CORRCOEF.
6 % [R,p,ci1,ci2] = CORRCOEF(x, [y, ] 'Rank');
8 % For some (unknown) reason, in previous versions Spearman's rank correlation
9 % r = corrcoef(ranks(x)).
10 % But according to [1], Spearman's correlation is defined as
11 % r = 1-6*sum((ranks(x)-ranks(y)).^2)/(N*(N*N-1))
12 % The results are different. Here, the later version is implemented.
14 % see also: CORRCOEF, RANKCORR
17 % [1] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html
18 % [2] http://mathworld.wolfram.com/CorrelationCoefficient.html
20 % $Id: spearman.m 8223 2011-04-20 09:16:06Z schloegl $
21 % Copyright (C) 2000-2002 by Alois Schloegl <alois.schloegl@gmail.com>
22 % This function is part of the NaN-toolbox
23 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
25 % This program is free software; you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation; either version 3 of the License, or
28 % (at your option) any later version.
30 % This program is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
35 % You should have received a copy of the GNU General Public License
36 % along with this program; If not, see <http://www.gnu.org/licenses/>.
39 % warning('SPEARMAN might become obsolete; use CORRCOEF(...,''Spearman'') instead');
42 r = corrcoef(x,'Spearman');
44 r = corrcoef(x,y,'Spearman');