Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

figure_priming_shape.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. function figure_priming_shape(fld)
  2. % this function is the same as sup_figure_1, but it looks at shape switches
  3. % instead of color switches. everywhere it says "color", it means "shape",
  4. % because I didn't want to change all the code :). the only real change to
  5. % this function is that we compute a shapeSwitch column which is added in
  6. % place of the colorSwitch column to the lut.
  7. fprintf('\n======================================================\n');
  8. fprintf('-- Running figure_priming_shape --\n');
  9. fprintf('-- SHAPE SWAP & REWARD SIZE --\n');
  10. fprintf('======================================================\n');
  11. %% get sessions
  12. datainfo = session_info();
  13. datadir = fullfile(fld.basedir,'Processed_Data');
  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.colSwitch = shapeSwitch;
  48. % calculate mean across all sessions
  49. [meanperf, condinfo] = calculate_perf(lut);
  50. % calculate mean across individual sessions
  51. incl_sessions = unique(lut.session);
  52. dayperf = [];
  53. for sid = 1:length(incl_sessions)
  54. clut = lut(strcmp(lut.session,incl_sessions{sid}),:);
  55. dayperf(end+1,:) = calculate_perf(clut);
  56. end
  57. % calculate std based on individual sessions
  58. perfstd = std(dayperf)/sqrt(size(dayperf,1));
  59. yellow = [247 148 29]./255;
  60. blue = [27 117 188]./255;
  61. cols = [blue; yellow];
  62. subplot(2,2,mi)
  63. % LET'S PUT COLORSWITCH AS LINES, SO THAT WE CAN USE DROPLET ICONS ON
  64. % THE X AXIS
  65. gap = 0.05;
  66. for colswitch = [0 1]
  67. i = condinfo(:,1)==colswitch;
  68. mn = meanperf(i);
  69. st = perfstd(i);
  70. 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',{'Low Reward','High Reward'},...
  75. 'ylim',[0.4 1]);
  76. title(monkey);
  77. ylabel('Performance Ratio');
  78. legend({'no shapeswap','','shapeswap',''})
  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 shape swap, p=' num2str(p(2))]);
  94. disp([monkey ', main effect for reward value of previous trial, 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',{'Low Reward','High Reward'},...
  125. 'ylim',[180 280]);
  126. title(monkey);
  127. ylabel('Reaction Time (ms)');
  128. legend({'no shapeswap','','shapeswap',''})
  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','Reward value of prevtrial'},'display','off');
  135. tbl
  136. disp('-------reaction time-------');
  137. disp([monkey ', interaction shapeswap and rewval, p=' num2str(p(3))]);
  138. disp([monkey ', main effect for reward value of previous trial, p=' num2str(p(2))]);
  139. disp([monkey ', main effect for shape swap, p=' num2str(p(1))]);
  140. end
  141. suptitle('Behavioral effects of shape swap & reward')
  142. savefig(f1,fullfile(savedir, 'figure_priming_shape'));
  143. print(f1,fullfile(savedir, 'figure_priming_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