Attachment 'dcor_uc.m'
Download 1 function [R,T,p,df] = dcor_uc(X,Y)
2 % [R,T,p,df] = dcor_uc(X,Y)
3 % Computes the U-centered (bias corrected) distance correlation between X and Y. Also outputs the
4 % associated t-value (T) and p-value (p). Rows represent the examples, and columns the variables.
5
6 % Based on: http://www.mathworks.com/matlabcentral/fileexchange/49968-dcorr--x--y--
7 % and, the R package energy and papers by Szekely and Rizzo (2007; 2013 and 2014).
8
9 % Author: Linda Geerligs (lindageerligs@gmail.com), Date: 22-10-2015
10
11 a = pdist2(X, X);
12 b = pdist2(Y, Y);
13 n=size(X,1);
14
15 A = Ucenter(a,n);
16 B = Ucenter(b,n);
17
18 dcovXY = sum(sum(A.*B)) ./ (n*(n-3));
19 dvarX = sum(sum(A.*A)) ./ (n*(n-3));
20 dvarY = sum(sum(B.*B)) ./ (n*(n-3));
21
22 R=dcovXY / sqrt(dvarX * dvarY);
23
24 df=(n*(n-3))/2 -1;
25 T=sqrt(df).*(R./sqrt(1-R.^2));
26 p = tcdf(T,df,'upper');
27
28 if R<0
29 R=0;
30 else
31 R=sqrt(R);
32 end
33
34 function A = Ucenter(a,n)
35 m = sum(a,2);
36 M = sum(m)/((n - 1) * (n - 2));
37 m = m./(n-2);
38 A = a - repmat(m,[1 n]);
39 A = A - repmat(m,[1 n])';
40 A = A+M;
41 A(eye(size(A))==1)=0;
42 end
43
44 end
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.