figure_priming_col_vs_shape.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. function figure_priming_col_vs_shape(fld)
  2. % this function is another adaptation of the sup_figure_1 function. since
  3. % we see a small effect of color switch, and a big effect of shape switch,
  4. % but not much of reward, let's compare shape to color directly (maybe
  5. % there is interaction). so here, color is back to being color, and reward
  6. % now means shape.
  7. fprintf('\n======================================================\n');
  8. fprintf('-- Running figure_priming_col_vs_shape --\n');
  9. fprintf('-- COLOR vs SHAPE SWAP --\n');
  10. fprintf('======================================================\n');
  11. %% get sessions
  12. datainfo = session_info();
  13. datadir = fld.procdatadir;
  14. savedir = fullfile(fld.basedir,'results','figure_priming');
  15. %% settings
  16. green = [23, 105, 13]./255;
  17. red = [201, 0, 34]./255;
  18. cols = [green; 0.3 0.3 0.3; red];
  19. %% plots
  20. % load traces
  21. monkeys = {'M1','M2'};
  22. f1 = figure; set(gcf,'Position',[100 100 600 1000]);
  23. for mi = 1:2
  24. monkey = monkeys{mi};
  25. info = datainfo(mi);
  26. sessions = info.dates;
  27. clut = [];
  28. for sid = 1:length(sessions)
  29. session = sessions{sid};
  30. % session info
  31. q = strsplit(session,'_');
  32. cdate = q{2};
  33. block = q{3}(4);
  34. % load the data
  35. session_id = [monkey '_' cdate '_' num2str(block)];
  36. sessiondir = fullfile(datadir, monkey, session_id);
  37. % load the data for this session for this channel
  38. load(fullfile(sessiondir, [session_id '_LUT.mat'])); % loads 'lut'
  39. clut = [clut; lut];
  40. end
  41. lut = clut;
  42. % add a shapeswitch column, because apparently no one ever looked at
  43. % this before
  44. shapeSwitch = zeros(size(lut,1),1);
  45. shapeSwitch(1) = nan;
  46. shapeSwitch(abs(lut.TarShape - [nan; lut.TarShape(1:end-1)]) > 0) = 1;
  47. %lut.addvars(shapeSwitch,'after','colSwitch');
  48. lut.rewardVal = shapeSwitch+1;
  49. % calculate mean across all sessions
  50. [meanperf, condinfo] = calculate_perf(lut);
  51. % calculate mean across individual sessions
  52. incl_sessions = unique(lut.session);
  53. dayperf = [];
  54. for sid = 1:length(incl_sessions)
  55. clut = lut(strcmp(lut.session,incl_sessions{sid}),:);
  56. dayperf(end+1,:) = calculate_perf(clut);
  57. end
  58. % calculate std based on individual sessions
  59. perfstd = std(dayperf)/sqrt(size(dayperf,1));
  60. yellow = [247 148 29]./255;
  61. blue = [27 117 188]./255;
  62. cols = [blue; yellow];
  63. subplot(2,2,mi)
  64. gap = 0.05;
  65. qp = [];
  66. for colswitch = [0 1]
  67. i = condinfo(:,1)==colswitch;
  68. mn = meanperf(i);
  69. st = perfstd(i);
  70. qp(colswitch+1) = plot([1 2]+gap*colswitch*-1,mn,'Color',cols(colswitch+1,:)); hold all;
  71. errorbar([1 2]+gap*colswitch*-1,mn,st,'o','Color',cols(colswitch+1,:),'MarkerFaceColor', cols(colswitch+1,:));
  72. end
  73. xlim([0.8 2.2]);
  74. set(gca,'XTick',[1 2],'XTickLabel',{'Shape-same','Shape-swap'});
  75. title(monkey);
  76. ylabel('Performance Ratio');
  77. legend({'no colorswap','','colorswap',''})
  78. ylim([0.4 1]);
  79. %% stats
  80. % let's start with a two-way anova. we have two conditions, each with
  81. % two levels (reward, color switch). in matlab, the 2d matrix supplying
  82. % the data needs to be a bit weird. columns contain the first
  83. % condition (reward value in our case). rows contains the second
  84. % condition (color switch), and it concatenates the
  85. % repetitions for each level of that condition.
  86. nocolswitch = dayperf(:,1:2);
  87. colswitch = dayperf(:,3:4);
  88. Y = [nocolswitch; colswitch];
  89. [p,tbl,stats] = anova2(Y,size(colswitch,1),'off');
  90. tbl
  91. disp('-------performance-------');
  92. disp([monkey ', interaction colswap and rewval, p=' num2str(p(3))]);
  93. disp([monkey ', main effect for color swap, p=' num2str(p(2))]);
  94. disp([monkey ', main effect for shape swap, p=' num2str(p(1))]);
  95. %% reaction time
  96. % select trials that have:
  97. % - current trial correct
  98. % - previous trial correct
  99. % - trial immediately followed previous trial
  100. % - color switch/ color same
  101. % - reward high/ reward low (on previous trial)
  102. rt = []; rtst = [];
  103. Y_rt = []; Y_colswitch = []; Y_rewval = [];
  104. for colswitch = [0 1]
  105. for rewval = [1 2]
  106. inclTrls = strcmp(lut.Status,'Target') & strcmp(lut.prevStatus,'Target') & lut.colSwitch==colswitch & lut.rewardVal==rewval & lut.immediateFollow;
  107. rt(end+1) = mean(lut.reactTime2(inclTrls));
  108. rtst(end+1) = std(lut.reactTime2(inclTrls))./sqrt(sum(inclTrls));
  109. % collect in a vector for statistics
  110. Y_rt = [Y_rt; lut.reactTime2(inclTrls)];
  111. Y_colswitch = [Y_colswitch; repmat(colswitch,sum(inclTrls),1)];
  112. Y_rewval = [Y_rewval; repmat(rewval,sum(inclTrls),1)];
  113. end
  114. end
  115. subplot(2,2,mi+2);
  116. for colswitch = [0 1]
  117. i = condinfo(:,1)==colswitch;
  118. mn = rt(i);
  119. st = rtst(i);
  120. plot([1 2]+gap*colswitch*-1,mn,'Color',cols(colswitch+1,:)); hold all;
  121. errorbar([1 2]+gap*colswitch*-1,mn,st,'o','Color',cols(colswitch+1,:),'MarkerFaceColor', cols(colswitch+1,:));
  122. end
  123. xlim([0.8 2.2]);
  124. set(gca,'XTick',[1 2],'XTickLabel',{'Shape-same','Shape-swap'});
  125. title(monkey);
  126. ylabel('Reaction Time (ms)');
  127. legend({'no colorswap','','colorswap',''})
  128. ylim([180 280]);
  129. %% stats
  130. % in this case, we have unbalanced design, because we take all the
  131. % trials as repetitions, and they are not equal amounts for each
  132. % condition, so we use anovan. here, Y is a vector, and the second
  133. % input gives the group number.
  134. [p,tbl,stats] = anovan(Y_rt,{Y_colswitch, Y_rewval},'model','interaction','varnames',{'Color swap','Shape swap'},'display','off');
  135. tbl
  136. disp('-------reaction time-------');
  137. disp([monkey ', interaction colswap and shapeswap, p=' num2str(p(3))]);
  138. disp([monkey ', main effect for shape swap, p=' num2str(p(2))]);
  139. disp([monkey ', main effect for color swap, p=' num2str(p(1))]);
  140. end
  141. suptitle('Behavioral effects of color & size swap')
  142. savefig(f1,fullfile(savedir, 'figure_priming_col-vs-shape'));
  143. print(f1,fullfile(savedir, 'figure_priming_col-vs-shape'),'-dpng');
  144. end
  145. function [perf, cond] = calculate_perf(lut)
  146. % select trials that have:
  147. % - are not aborted
  148. % - current trial correct
  149. % - previous trial correct
  150. % - trial immediately followed previous trial
  151. % - color switch/ color same
  152. % - reward high/ reward low (on previous trial)
  153. perf = []; cond = [];
  154. for colswitch = [0 1]
  155. for rewval = [1 2]
  156. inclTrls = strcmp(lut.Status,'Aborted')==0 & strcmp(lut.prevStatus,'Target') & lut.colSwitch==colswitch & lut.rewardVal==rewval & lut.immediateFollow;
  157. curlut = lut(inclTrls,:);
  158. perf(end+1) = sum(strcmp(curlut.Status,'Target'))/size(curlut,1);
  159. cond(end+1,:) = [colswitch rewval];
  160. end
  161. end
  162. end