jordan@2
|
1 function [asig pval a a_] = do_correlation3_fig3_only(megacube, songs, metrics, algos, algo_groups, merge_algos, merge_songs, merge_dsets, metric_labels, bonferroni, metrics2, metric_labels2)
|
jordan@2
|
2
|
jordan@2
|
3 % Script to make and analyze correlation plot.
|
jordan@2
|
4 % Example usage:
|
jordan@2
|
5 % To run your first experiment (Fig 1a) request:
|
jordan@2
|
6 % do_correlation(megacube, lab_measures, sind_manual1, [1:9], -1, 0, 1, -1, s_manual1)
|
jordan@2
|
7 %
|
jordan@2
|
8 % Note a few hard-coded decisions, such as:
|
jordan@2
|
9 % - use of 0.05 significance level with Bonferroni correction
|
jordan@2
|
10 % - in the image, decision that tau > 0.8 is strong, tau > 0.4 is weak, and tau < 0.4 is nothing.
|
jordan@2
|
11
|
jordan@2
|
12 maxtau = 0.8;
|
jordan@2
|
13 mintau = 0.33;
|
jordan@2
|
14
|
jordan@2
|
15
|
jordan@2
|
16
|
jordan@2
|
17 tmpcube1 = megacube(songs,[metrics metrics2],algos);
|
jordan@2
|
18 tmpcube2 = megacube(songs,metrics2,algos);
|
jordan@2
|
19
|
jordan@2
|
20
|
jordan@2
|
21 if merge_algos>0, % If we merge algorithms, take the median score across algorithms.
|
jordan@2
|
22 tmpcube1 = median(tmpcube1,3);
|
jordan@2
|
23 tmpcube2 = median(tmpcube2,3);
|
jordan@2
|
24 elseif merge_songs>0, % If we merge songs, take the median score across songs.
|
jordan@2
|
25 tmpcube1 = median(tmpcube1,1);
|
jordan@2
|
26 tmpcube2 = median(tmpcube2,1);
|
jordan@2
|
27 tmpcube1 = transpose(reshape(tmpcube1,size(tmpcube1,2),size(tmpcube1,3)));
|
jordan@2
|
28 tmpcube2 = transpose(reshape(tmpcube2,size(tmpcube2,2),size(tmpcube2,3)));
|
jordan@2
|
29 end
|
jordan@2
|
30
|
jordan@2
|
31
|
jordan@2
|
32 % Accept a matrix and its pvalues, determine which values are significant.
|
jordan@2
|
33 % Matrix is A, pvalues are PVAL
|
jordan@2
|
34 tic
|
jordan@2
|
35 [a pval] = corr(tmpcube2, tmpcube1,'type','Kendall');
|
jordan@2
|
36 toc
|
jordan@2
|
37 % Apply bonferroni correction:
|
jordan@2
|
38 m = sum(sum(tril(ones(size(a)), length(metrics)-1)))
|
jordan@2
|
39 asig = pval<0.05;
|
jordan@2
|
40 if bonferroni==1,
|
jordan@2
|
41 fprintf('Bonferroni applied.\n')
|
jordan@2
|
42 asig = (pval*m)<0.05; % This is the matrix of values that are significant.
|
jordan@2
|
43 end
|
jordan@2
|
44
|
jordan@2
|
45 % Make a pretty picture:
|
jordan@2
|
46 a_ = (abs(a)>=maxtau) + (abs(a)>=mintau);
|
jordan@2
|
47 a_ = tril(a_,length(metrics)-1);
|
jordan@2
|
48 % bg = 2*triu(ones(size(a_)));
|
jordan@2
|
49
|
jordan@2
|
50
|
jordan@2
|
51 % A contains the correlation values themselves.
|
jordan@2
|
52 % ASIG is a binary matrix that states whether the correlation is statistically significant.
|
jordan@2
|
53 % A_ is a matrix of -2, -1, 0, 1 and 2s that says whether a correlation is qualitatively strong (2), qualitatively weak (1), or nada (0).
|
jordan@2
|
54
|
jordan@2
|
55 % The values we display will always be straight from A. The image we display, though, to emphasize the strong correlations,
|
jordan@2
|
56 % should be the element-wise product of A, ASIG, and A_.
|
jordan@2
|
57
|
jordan@2
|
58 % So we will only display colours for values that are statistically significant.
|
jordan@2
|
59 % In addition, we will only put in inverted text those that are qualitatively large (>0.8).
|
jordan@2
|
60 % However, this leaves the possibility of large correlations (>0.8) that are insignificant, which show up as white text on white background.
|
jordan@2
|
61 % Therefore, let us change tacks:
|
jordan@2
|
62 %
|
jordan@2
|
63 % If tau>0.33 (a_>0), include text.
|
jordan@2
|
64 % If tau is significant (asig=1), include background.
|
jordan@2
|
65 % If tau>0.8 (a_=2), put in bold.
|
jordan@2
|
66 % If tau>0.8 AND significant, invert the color of the text.
|
jordan@2
|
67
|
jordan@2
|
68 img = a_.*a.*asig;
|
jordan@2
|
69 img = img(:,1:end-1);
|
jordan@2
|
70 figure,imagesc(img, [-1 1])
|
jordan@2
|
71 for i=1:size(a_,1),
|
jordan@2
|
72 for j=1:size(a_,2),
|
jordan@2
|
73 if a_(i,j)>0,
|
jordan@2
|
74 % tau is >0.33 so we definitely write the value. need to determine fontface and colour.
|
jordan@2
|
75 % if tau>.8, put in bold
|
jordan@2
|
76 if abs(a_(i,j))>1,
|
jordan@2
|
77 fontw = 'bold';
|
jordan@2
|
78 else
|
jordan@2
|
79 fontw = 'normal';
|
jordan@2
|
80 end
|
jordan@2
|
81 if abs(a_(i,j))>1 & asig(i,j)==1,
|
jordan@2
|
82 textcolor = [1 1 1];
|
jordan@2
|
83 else
|
jordan@2
|
84 textcolor = [0 0 0];
|
jordan@2
|
85 end
|
jordan@2
|
86 % h = text(j-.35,i,num2str(a(i,j),2),'Color',textcolor);
|
jordan@2
|
87 h = text(j,i,sprintf('%.2f',a(i,j)),'Color',textcolor,'FontWeight',fontw,'FontSize',8,'HorizontalAlignment','center');
|
jordan@2
|
88 set(h,'HorizontalAlignment','center','Rotation',90)
|
jordan@2
|
89 end
|
jordan@2
|
90 end
|
jordan@2
|
91 end
|
jordan@2
|
92 cmap_el = transpose([linspace(.3,1,50)]);
|
jordan@2
|
93 cmap = repmat(cmap_el,1,3);
|
jordan@2
|
94 cmap = [cmap; flipud(cmap)];
|
jordan@2
|
95 % Alternatively:
|
jordan@2
|
96 cmap = [ones(size(cmap_el)) cmap_el cmap_el; flipud([cmap_el cmap_el ones(size(cmap_el))])];
|
jordan@2
|
97 colormap(cmap);
|
jordan@2
|
98
|
jordan@2
|
99 set(gca,'YTickLabel',metric_labels2,'YTick',1:size(a,1),'FontAngle','italic','FontSize',10)
|
jordan@2
|
100 % set(gca,'XTickLabel',[metric_labels metric_labels2],'XTick',1:size(a,2),'FontAngle','italic','FontSize',10)
|
jordan@2
|
101
|
jordan@2
|
102 set(gca,'XTickLabel',[],'XTick',1:size(a,2)-1);
|
jordan@2
|
103 t = text((1:size(a,2)-1)-.5,size(a,1)*ones(1,size(a,2)-1)+.7,[metric_labels metric_labels2(1:end-1)]);
|
jordan@2
|
104 set(t,'HorizontalAlignment','right','VerticalAlignment','top', 'Rotation',90,'FontAngle','italic');
|
jordan@2
|
105
|
jordan@2
|
106
|
jordan@2
|
107 % set(gcf,'Position',[1000,1000,700,300])
|
jordan@2
|
108 % set(gca,'XTickLabel',metric_labels(2:2:end),'YTick',(1:length(a)/2))
|
jordan@2
|
109
|
jordan@2
|
110 % axis([0.5, length(a)-.5, 1.5, length(a)+.5]) |