figure_priming_color.m 6.3 KB

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