Figure_4_panel_ab.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. clear all
  2. mainfolder='';
  3. addpath(genpath([mainfolder 'subfunctions/']))
  4. addpath(genpath([mainfolder 'behavioural_modeling/']))
  5. addpath(genpath('subfunctions/rm_anova2'))
  6. %% Panel 1
  7. clear all
  8. %data for polarplots
  9. [oriC, oriP, oriN]=orivectors(16,6.43);
  10. theta1=oriC
  11. theta=[0 0 pi/2 pi/2 pi/2 pi/2 pi pi pi pi pi*1.5 pi*1.5 pi*1.5 pi*1.5 0 0];
  12. uno=ones(1,16)
  13. thetaall{1}=[theta theta(1)];
  14. uno=[uno uno(1)];
  15. theta1=oriC
  16. theta2=[0 0 0 0 pi/2 pi/2 pi/2 pi/2 pi pi pi pi pi*1.5 pi*1.5 pi*1.5 pi*1.5]-pi/4
  17. theta3=[theta1;theta2]
  18. theta=mean(theta3)
  19. uno=ones(1,16)
  20. thetaall{2}=[theta theta(1)];
  21. uno=[uno uno(1)];
  22. theta=oriC
  23. uno=ones(1,16)
  24. thetaall{3}=[theta theta(1)];
  25. uno=[uno uno(1)];
  26. theta1=oriC
  27. theta2=[0 0 0 0 pi/2 pi/2 pi/2 pi/2 pi pi pi pi pi*1.5 pi*1.5 pi*1.5 pi*1.5]+pi/4
  28. theta3=[theta1;theta2]
  29. theta=mean(theta3)
  30. uno=ones(1,16)
  31. thetaall{4}=[theta theta(1)];
  32. theta=[0 0 0 0 pi/2 pi/2 pi/2 pi/2 pi pi pi pi pi*1.5 pi*1.5 pi*1.5 pi*1.5]+pi/4
  33. uno=ones(1,16)
  34. thetaall{5}=[theta theta(1)];
  35. uno=[uno uno(1)];
  36. A=0.2
  37. thetaall{4}=A.*thetaall{5}+(1-A)*thetaall{3};
  38. A=1
  39. thetaall{5}=A.*thetaall{5}+(1-A)*thetaall{3};
  40. a{1}=creatcatcardeucl;
  41. a{3}=creatcontmodel(1);
  42. a{5}=creatcatcardeucl45;
  43. A=0.5;
  44. a{2}=A*a{1}+(1-A)*a{3}
  45. a{4}=A*a{5}+(1-A)*a{3}
  46. % Plotting
  47. figure;
  48. subplot(2,5,1);
  49. polarmodelplot(thetaall{1},uno)
  50. subplot(2,5,2);
  51. polarmodelplot(thetaall{2},uno)
  52. subplot(2,5,3);
  53. polarmodelplot(thetaall{3},uno)
  54. subplot(2,5,4);
  55. polarmodelplot(thetaall{4},uno)
  56. subplot(2,5,5);
  57. polarmodelplot(thetaall{5},uno)
  58. subplot(2,5,6);
  59. moldelmatplot(a{5},theta1)
  60. subplot(2,5,7);
  61. moldelmatplot(a{4},theta1)
  62. subplot(2,5,8);
  63. moldelmatplot(a{3},theta1)
  64. subplot(2,5,9);
  65. moldelmatplot(a{2},theta1)
  66. subplot(2,5,10);
  67. moldelmatplot(a{1},theta1)
  68. %% Panel 2
  69. clear all
  70. %Loading data
  71. beh=load('data_for_plots/Figure_4/all_behaviour_n41_trialbytrial_C05.mat')
  72. load('data_for_plots/Figure_4/avg_polarbias_n41_C1.mat')
  73. %Loadin eyedata
  74. load('data_for_plots/Figure_4/test1_meanrecent_100pth_n41_lastsec.mat')
  75. eye.all{1}(:,1)=av_a1cued1(:)-av_a1cued2(:)
  76. eye.all{1}(:,2)=av_a2cued1(:)-av_a2cued2(:)
  77. load('data_for_plots/Figure_4/test2_meanrecent_100pth_n41_lastsec.mat')
  78. eye.all{1}(:,3)=av_a1cued1(:)-av_a1cued2(:)
  79. eye.all{1}(:,4)=av_a2cued1(:)-av_a2cued2(:)
  80. fp=(~isnan(eye.all{1}(:,1))+~isnan(eye.all{1}(:,2))...
  81. +~isnan(eye.all{1}(:,3))+~isnan(eye.all{1}(:,4)))==4; %checking we have data from all participants
  82. eye.all{1}=eye.all{1}(:,:)
  83. figure('Position' ,[100 600 950 600]);
  84. %behavioural plot
  85. subplot(1,3,1)
  86. colores=[0 0 0];
  87. % barplotbias(beh.all{1},[-0.51,0.51],'behaviour','A (bias index)',1)
  88. lineartrendana(beh.all,1,1,[-.4,0.7],'behaviour','B (bias index)',colores,-0.6)
  89. % polarplot of behav bias
  90. oi=avg_bCueor;
  91. oiac=avg_aCueor;
  92. yourBias=[];
  93. yourAccu=[];
  94. for ppp=1:size(oi,2)
  95. behB=oi(:,ppp)'; %BheaviouralBias
  96. s=avg_Paramsr(ppp,1); % noise (in memory/decision-making)
  97. A=avg_Paramsr(ppp,2); % Key Parameter (squircle) 0: all circle; 1: all square
  98. C=avg_Paramsr(ppp,3);
  99. makefig=0;
  100. [yourAccu(:,ppp) yourBias(:,ppp)]=squircleBehave2compB(s,A,C,behB,makefig);
  101. end
  102. counter=1;
  103. subplot(1,3,2)
  104. polarplot([0 pi],[1 1],'k-','LineWidth',1);hold on;
  105. polarplot([pi/2 pi*1.5],[1 1],'k-','LineWidth',1);hold on;
  106. Aave=round(mean(avg_Paramsr(:,2),1),3)
  107. Astd=std(avg_Paramsr(:,2),0,1);
  108. quickplotcompBerrors(bb',(yourBias),(oi),[''],1,Aave);
  109. counter=counter+1,
  110. set(gca,'GridAlpha',0.25);
  111. set(gca,'FontSize',20);
  112. %eye plot
  113. subplot(1,3,3)
  114. lineartrendana(eye.all,1,0,[-.1,.175],'gaze','\Delta (rho) repulsion - attraction',colores,-0.15)
  115. %% Analysis
  116. %T test againg 0
  117. mmm=mean(beh.all{1}(:,:),2);
  118. mean(beh.all{1}) %mean of B index in each condition
  119. h = lillietest(mmm);
  120. [h,p,ci,stats] = ttest(mmm,0)
  121. [h,p,ci,stats] = ttest(beh.all{1},0)
  122. [p,h,stats] = ranksum(mmm,0)
  123. % Anova
  124. al=[]
  125. al= cat(1,beh.all{1}(:,1),beh.all{1}(:,2),beh.all{1}(:,3),beh.all{1}(:,4))';
  126. p=size(beh.all{1},1);
  127. S=[1:p,1:p,1:p,1:p];
  128. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  129. F2=[ones(p*2,1);ones(p*2,1)*2]'
  130. FACTNAMES={'item order', 'test order'}
  131. stats = rm_anova2(al,S,F1,F2,FACTNAMES)
  132. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  133. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  134. %% Linear trend analysis beh
  135. b_beh=lineartrendana(beh.all,0);
  136. %%
  137. %T test againg 0
  138. mmm=mean(eye.all{1}(:,:),2);
  139. h = lillietest(mmm);
  140. [h,p,ci,stats] = ttest(mmm,0)
  141. [h,p,ci,stats] = ttest(eye.all{1},0)
  142. [p,h,stats] = ranksum(mmm,0)
  143. 1
  144. % Anova
  145. al=[]
  146. al= cat(1,eye.all{1}(fp,1),eye.all{1}(fp,2),eye.all{1}(fp,3),eye.all{1}(fp,4))';
  147. p=size(eye.all{1}(fp,1),1);
  148. S=[1:p,1:p,1:p,1:p];
  149. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  150. F2=[ones(p*2,1);ones(p*2,1)*2]'
  151. FACTNAMES={'item order', 'test order'}
  152. stats = rm_anova2(al,S,F1,F2,FACTNAMES)
  153. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  154. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  155. %% Linear trend analysis eye
  156. b_eye=lineartrendana(eye.all,0,0,[-.075,.2]);
  157. %% Correlation between slopes in beh and eyes
  158. [rho pval]=corr(b_beh',b_eye','Type','Pearson')
  159. %%
  160. figure; % barplotbias(beh.all{1},[-0.51,0.51],'behaviour','A (bias index)',1)
  161. lineartrendana(beh.all,1,1,[-.9,0.9],'behaviour','B (bias index)')
  162. %% Subfunctions
  163. function polarmodelplot(theta,uno)
  164. polarplot(theta,uno,'k-o','MarkerFaceColor', 'k', 'MarkerSize', 8);
  165. r=gca;
  166. r.FontSize=20;
  167. r.RTickLabel=[];
  168. r.RGrid='off';
  169. rlim([0 1.25])
  170. c=creat_u_d_model;
  171. d=creat_l_r_model;
  172. aa=c+d;
  173. cont=creatcontmodel(1);
  174. A=0.5;
  175. a=A*aa+(1-A)*cont
  176. end
  177. function moldelmatplot(a,theta1)
  178. imagesc(a);hold on;
  179. xlabel('orientation (°)')
  180. ylabel('orientation (°)')
  181. xticks = 1:16; %adjust as appropriate, positive integers only
  182. xlabels = round(rad2deg(theta1(1:4:16))); %time labels
  183. set(gca, 'XTick', 1:4:16, 'XTickLabel', xlabels, ...
  184. 'YTick', 1:4:16, 'YTickLabel', xlabels, 'YAxisLocation','left','FontSize',20);
  185. end
  186. function barplotbias(data,yl,tito,yla,labels,sublabels,colores,xpos)
  187. ax=notBoxPlot(data,'style','sdline')
  188. line([0,5], [0,0], 'Color', 'k','LineStyle',':','LineWidth',2);hold on;
  189. line([2.5,2.5], [-10,10], 'Color', 'k','LineStyle','--','LineWidth',2);hold on;
  190. for i=1:4
  191. ax(i).semPtch.FaceColor = [0.75 0.75 0.75];
  192. ax(i).semPtch.EdgeColor = [0.75 0.75 0.75];
  193. ax(i).semPtch.LineWidth = 3;
  194. ax(i).data.MarkerSize = 8;
  195. ax(i).mu.Color = [0 0 0];
  196. ax(i).sd.Color = [0 0 0];
  197. end
  198. xticks([1:4])
  199. xticklabels(labels)
  200. % xtickangle(45)
  201. ylim(yl)
  202. xlim([0.5 4.5])
  203. ylabel(yla)
  204. set(gca,'FontSize',20);
  205. title(tito)
  206. text(1.5,xpos,sublabels{1},'HorizontalAlignment','center','FontSize',20,'FontWeight','bold')
  207. text(3.5,xpos,sublabels{2},'HorizontalAlignment','center','FontSize',20,'FontWeight','bold')
  208. end
  209. function ball=lineartrendana(all,plotyes,beh,ylimits,btit,ylab,colores,xpos)
  210. distances(:,1)=all{1}(:,2) %stim 2 cued 1st
  211. distances(:,2)=all{1}(:,1) %stim 1 cued 1st
  212. distances(:,3)=all{1}(:,4)%stim 2 cued 2nd
  213. distances(:,4)=all{1}(:,3) %stim 1 cued 2nd
  214. %% Check linear trend
  215. % ball=[];
  216. % yfit = [];
  217. for ppp = 1:size(distances,1)
  218. tof=[];
  219. for c=1:size(distances,2);
  220. tof=[tof; distances(ppp,c)];
  221. end
  222. [b,dev,stats] = glmfit(1:size(distances,2),tof,'normal');
  223. yfit(ppp,:) = polyval([b(2,1),b(1,1)],[1,2,3,4]);
  224. ball(ppp) = b(2);
  225. end
  226. [h,p,ci,stats] = ttest(ball,0)
  227. if plotyes
  228. if beh
  229. labels={'Stim 2 ','Stim 1','Stim 2','Stim 1'};
  230. sublabel={'test 1', 'test 2'};
  231. else
  232. labels={'Stim 2 ','Stim 1','Stim 2','Stim 1'};
  233. % labels={'stim 2 - delay 1','stim 1 - delay 1','stim 2 - delay 2','stim 1 - delay 2'};
  234. sublabel={'delay 1', 'delay 2'};
  235. end
  236. plot(yfit','Color',[colores 0.25],'LineWidth',1);hold on;
  237. plot(mean(yfit,1)','Color',[0 0 0],'LineWidth',3);hold on;
  238. barplotbias(distances,ylimits,btit,ylab,labels,sublabel,colores,xpos)
  239. end
  240. end