⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kendall.m

📁 copular 多元时间变量统计学工具 计算相关性
💻 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 + -