?? kendall.m
字號:
function tau = kendall(x,y)
%KENDALL Kendall's rank correlation coefficient.
% TAU = KENDALL(X) returns a matrix TAU of pairwise Kendall's rank
% correlation coefficients between columns of the matrix X.
%
% TAU = KENDALL(X,Y) returns Kendall's rank correlation coefficient TAU
% between the vectors X and Y.
% Written by Peter Perkins, The MathWorks, Inc.
% Revision: 1.0 Date: 2003/09/05
% This function is not supported by The MathWorks, Inc.
%
% Requires MATLAB R13.
if nargin == 1
[n,p] = size(x);
tau = eye(p);
for row = 1:(p-1)
for col = (row+1):p
s = 0;
for i = 1:n
s = s + sum(sign(x(i:n,row)-x(i,row)).*sign(x(i:n,col)-x(i,col)));
end
tau(row,col) = s .* 2./(n.*(n-1));
tau(col,row) = tau(row,col);
end
end
else
if ~((ndims(x) == 2) && any(size(x) == 1)) || ...
~((ndims(y) == 2) && any(size(y) == 1)) || (numel(x) ~= numel(y))
error('X and Y must be vectors of the same length.');
end
n = numel(x);
tau = 0;
for i = 1:n
tau = tau + sum(sign(x(i:n)-x(i)).*sign(y(i:n)-y(i)));
end
tau = tau .* 2./(n.*(n-1));
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -