1 | function [cc,p] = pcorr(X) |
---|

2 | % PCORR - Calculate partial correlation coefficients |
---|

3 | % |
---|

4 | % |
---|

5 | % Synopsis: |
---|

6 | % |
---|

7 | % |
---|

8 | % Description: |
---|

9 | % |
---|

10 | % Examples: |
---|

11 | % |
---|

12 | % |
---|

13 | % See also: |
---|

14 | % |
---|

15 | |
---|

16 | % This function is a part of Aedes - A graphical tool for analyzing |
---|

17 | % medical images |
---|

18 | % |
---|

19 | % Copyright (C) 2011 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uef.fi> |
---|

20 | % |
---|

21 | % Department of Applied Physics, Department of Neurobiology |
---|

22 | % University of Eastern Finland, Kuopio, FINLAND |
---|

23 | % |
---|

24 | % This program may be used under the terms of the GNU General Public |
---|

25 | % License version 2.0 as published by the Free Software Foundation |
---|

26 | % and appearing in the file LICENSE.TXT included in the packaging of |
---|

27 | % this program. |
---|

28 | % |
---|

29 | % This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
---|

30 | % WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|

31 | |
---|

32 | t=perms(1:size(X,2)); |
---|

33 | t=t(1:2:end,:); |
---|

34 | T = size(t,1); |
---|

35 | |
---|

36 | Z_ind = t(:,1:end-2); |
---|

37 | X_ind = t(:,end-1); |
---|

38 | Y_ind = t(:,end); |
---|

39 | |
---|

40 | dz = size(Z_ind,2); |
---|

41 | n = size(X,1); |
---|

42 | |
---|

43 | cc = diag(ones(1,size(X,2))); |
---|

44 | p = zeros(size(cc)); |
---|

45 | |
---|

46 | for ii=1:T |
---|

47 | x=X(:,X_ind(ii)); |
---|

48 | y=X(:,Y_ind(ii)); |
---|

49 | z=[ones(size(y,1),1) X(:,Z_ind(ii,:))]; |
---|

50 | xx = x-z*(z\x); |
---|

51 | yy = y-z*(z\y); |
---|

52 | C = cov(xx,yy); |
---|

53 | C=C./(std(xx)*std(yy)); |
---|

54 | coef = C(2); |
---|

55 | |
---|

56 | % Correlation coefficients |
---|

57 | cc(X_ind(ii),Y_ind(ii)) = coef; |
---|

58 | cc(Y_ind(ii),X_ind(ii)) = cc(X_ind(ii),Y_ind(ii)); |
---|

59 | |
---|

60 | % P-values |
---|

61 | df = max(n - dz - 2,0); % degrees of freedom |
---|

62 | t = sign(coef) .* Inf; |
---|

63 | k = (abs(coef) < 1); |
---|

64 | t(k) = coef(k) ./ sqrt(1-coef(k).^2); |
---|

65 | t = sqrt(df).*t; |
---|

66 | |
---|

67 | pval1 = 2*tdist(-abs(t),df); % Two-tailed |
---|

68 | %pval2 = tdist(-t,df); % greater than... |
---|

69 | %pval3 = tdist(t,df); % lower than... |
---|

70 | |
---|

71 | p(X_ind(ii),Y_ind(ii)) = pval1; |
---|

72 | p(Y_ind(ii),X_ind(ii)) = p(X_ind(ii),Y_ind(ii)); |
---|

73 | end |
---|

74 | |
---|