1
0

findAbehavPerItemTrials.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. clear all
  2. load('behavdata/datperitemandtrial.mat')
  3. addpath(genpath([''])); %Add here the subfolder of subfunction (root folder)
  4. % This data contains participant responses (1 =CW and 0 = CCW)
  5. aCue{1,1}=squeeze(cw_resp_cu_uncue{1}(:,1,:,:)); % 1st obj and 1st Test
  6. aCue{1,2}=squeeze(cw_resp_cu_uncue{1}(:,2,:,:)); % 1st obj 2nd Test
  7. aCue{2,1}=squeeze(cw_resp_cu_uncue{2}(:,1,:,:)); % 2st obj and 1st Test
  8. aCue{2,2}=squeeze(cw_resp_cu_uncue{2}(:,2,:,:)); % 2st obj 2nd Test
  9. % This data contains the correct responses per trial (1 =CW and 0 = CCW)
  10. tCue{1,1}=squeeze(cw_test_cu_uncue{1}(:,1,:,:)); % 1st obj and 1st Test
  11. tCue{1,2}=squeeze(cw_test_cu_uncue{1}(:,2,:,:)); % 1st obj 2nd Test
  12. tCue{2,1}=squeeze(cw_test_cu_uncue{2}(:,1,:,:)); % 2st obj and 1st Test
  13. tCue{2,2}=squeeze(cw_test_cu_uncue{2}(:,2,:,:)); % 2st obj 2nd Test
  14. % groupave=0 % If we want to calculate A using the group average
  15. %
  16. % if groupave
  17. % for item=1:2
  18. % for test=1:2
  19. % aCue{item,test}=mean(aCue{item,test}(:,:),2)
  20. % end
  21. % end
  22. % end
  23. %% order the data in standard presentation
  24. ao=deg2rad(cw_resp_cu_uncue{3}(:));
  25. ao2=abs(2*pi-ao); %move anticlockwise
  26. ao3=(angdiff(-ao2,-(ones(16,1).*pi*1.5)))+pi;
  27. [bb ind]=sort(ao3);
  28. for item=1:2
  29. for test=1:2
  30. aCueo{item,test}=aCue{item,test}(ind,:,:);
  31. tCueo{item,test}=tCue{item,test}(ind,:,:);
  32. end
  33. end
  34. %% Obtaining the best parameters
  35. BestParams=nan(size(aCueo{1,1},2),4,2,2);
  36. CvetIn=-0.5:0.1:0.5;%vector grid search of C
  37. parfor ppp =1:size(aCueo{1,1},2)
  38. for item = 1:2
  39. for test=1:2
  40. aCueI=squeeze(aCueo{item,test}(:,ppp,:));
  41. tCueI=squeeze(tCueo{item,test}(:,ppp,:));
  42. BestParams(ppp,:,item,test)=gridsearch_jld_trial(aCueI,tCueI,0,0,CvetIn,0.01); % This fuction is the the same as original, but we can add some input (ssqmat only based on accu,granularity for the grid search)
  43. end
  44. end
  45. ppp
  46. end
  47. %% Changing format
  48. for item = 1:2
  49. for test=1:2
  50. Params{item,test}= squeeze(BestParams(:,:,item,test));% info about test 1
  51. Params{item,test}= squeeze(BestParams(:,:,item,test));% info about test 1
  52. end
  53. end
  54. %% Plotting all parameters
  55. outputlabels={'s (noise)',' A (squircle factor)', 'C (cardinal precision)',' min SSQ'};
  56. figure;
  57. for lp = 1:4
  58. all{1}= (cat(2,Params{1,1}(:,lp),Params{2,1}(:,lp),Params{1,2}(:,lp),Params{2,2}(:,lp)))
  59. subplot(2,2,lp)
  60. barplotbias(all{1},[min(all{1}(:)-0.0001),max(all{1}(:))+0.0001],' ',outputlabels{lp},1)
  61. end
  62. for lp = 2
  63. all{1}= (cat(2,Params{1,1}(:,lp),Params{2,1}(:,lp),Params{1,2}(:,lp),Params{2,2}(:,lp)))
  64. end
  65. %% C against zero
  66. allc{1}= (cat(2,Params{1,1}(:,3),Params{2,1}(:,3),Params{1,2}(:,3),Params{2,2}(:,3)))
  67. %T test againg 0
  68. mmm=mean(allc{1}(:,:),2);
  69. h = lillietest(mmm);
  70. [h,p,ci,stats] = ttest(mmm,0)
  71. [h,p,ci,stats] = ttest(allc{1},0)
  72. %% C - Linear trend
  73. cc=allc{1}
  74. for ppp = 1:size(cc,1)
  75. tof=[];
  76. for c=1:size(cc,2);
  77. tof=[tof; cc(ppp,c)];
  78. end
  79. [b,dev,stats] = glmfit(1:size(cc,2),tof,'normal');
  80. yfit(ppp,:) = polyval([b(2,1),b(1,1)],[1,2,3,4]);
  81. ball(ppp) = b(2);
  82. end
  83. [h,p,ci,stats] = ttest(ball,0)
  84. %% Anova
  85. addpath '\rm_anova2'
  86. removingout=0
  87. if removingout ==1 %if removing the outlier
  88. [m I]=max(Params{1,2}(:,4))
  89. ind = 1:length((Params{1,2}(:,4)))~=I;
  90. else
  91. ind = 1:length((Params{1,2}(:,4)))~=0;
  92. end
  93. a1= (cat(1,Params{1,1}(ind,2),Params{2,1}(ind,2),Params{1,2}(ind,2),Params{2,2}(ind,2))')
  94. p=(sum(ind));
  95. S=[1:p,1:p,1:p,1:p];
  96. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  97. F2=[ones(p*2,1);ones(p*2,1)*2]'
  98. FACTNAMES={'item order', 'test order'}
  99. stats = rm_anova2(a1,S,F1,F2,FACTNAMES)
  100. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  101. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  102. %% Testing A index vs. 0
  103. all{1}= (cat(2,Params{1,1}(:,2),Params{2,1}(:,2),Params{1,2}(:,2),Params{2,2}(:,2)))
  104. for rrr=1:4
  105. [h,p,ci,stats] = ttest(all{1}(:,rrr),0)
  106. ttesre(rrr,1)=stats.tstat;
  107. ttesre(rrr,2)=p;
  108. end
  109. %% Plotting A index (bars)
  110. all{1}= (cat(2,Params{1,1}(:,2),Params{2,1}(:,2),Params{1,2}(:,2),Params{2,2}(:,2)))
  111. names{1}='all'
  112. figure;
  113. for t=1
  114. avg=nanmean(all{t},1);
  115. sem=std(all{t})/sqrt(size(all{t},1));
  116. % subplot(1,3,t)
  117. % bar(rot_dif_list,avg);hold on,
  118. if groupave
  119. plot(avg,'o')
  120. else
  121. er=errorbar([],avg,sem,sem,'o');
  122. er.Color = [0 0 0];
  123. er.LineStyle = 'none';
  124. end
  125. % ylim([0 0.34])
  126. xlim([0 5])
  127. % line([0,5],[0.5 0.5], 'Color', 'k','LineStyle','--');hold on;
  128. xticks([1:4])
  129. xticklabels({'ori 1 1st test','ori 2 1st test','ori 1 2nd test','ori 2 2nd test'})
  130. % xlabel('distance between 1stcued minus 2nd cued ori (degrees)')
  131. ylabel('cardinal repulsion index (bias index)')
  132. title(['bias index - ' names{t}])
  133. end
  134. %% Plotting A index (bars) -version 2
  135. figure('Position' ,[100 600 950 600]);
  136. ax=notBoxPlot(all{1},'style','sdline')
  137. for i=1:4
  138. ax(i).semPtch.FaceColor = [0.75 0.75 0.75];
  139. ax(i).semPtch.EdgeColor = [0.75 0.75 0.75];
  140. ax(i).semPtch.LineWidth = 3;
  141. ax(i).mu.Color = [0 0 0];
  142. ax(i).sd.Color = [0 0 0];
  143. end
  144. xticks([1:4])
  145. xticklabels({'object 1 - test 1','object 2 - test 1','object 1 - test 2','object 2- test 2'})
  146. ylim([-0.41 .615])
  147. ylabel('A (bias index)')
  148. set(gca,'FontSize',13);
  149. %% and groupal polar plot per item and test
  150. for item = 1:2
  151. for test=1:2
  152. oi=bCueo{item,test};
  153. oiac=aCueo{item,test};
  154. yourBias=[];
  155. yourAccu=[];
  156. for ppp=1:size(oi,2)
  157. behB=oi(:,ppp)'; %BheaviouralBias
  158. s=Params{item,test}(ppp,1); % noise (in memory/decision-making)
  159. A=Params{item,test}(ppp,2); % Key Parameter (squircle) 0: all circle; 1: all square
  160. C=Params{item,test}(ppp,3); % Reduce noise near cardinal by this factor (1: off)
  161. makefig=0;
  162. [yourAccu(:,ppp) yourBias(:,ppp)]=squircleBehave2compB(s,A,C,behB,makefig);
  163. end
  164. counter=1;
  165. figure;
  166. subplot(1,2,counter)
  167. quickplotcompBerrors(bb',(yourBias),(oi),['bias - object - ' num2str(item) ' test- ' num2str(test)],1);
  168. counter=counter+1,
  169. set(gca,'FontSize',12);
  170. subplot(1,2,counter)
  171. quickplotcompBerrors(bb',(yourAccu),(oiac),['accuracy - item- ' num2str(item) ' test- ' num2str(test)],0);
  172. counter=counter+1,
  173. set(gca,'FontSize',12);
  174. end
  175. end
  176. %%
  177. bCueor=cat(3,bCueo{1,1},bCueo{1,2},bCueo{2,1},bCueo{2,2});
  178. avg_bCueor=mean(bCueor,3);
  179. aCueor=cat(3,aCueo{1,1},aCueo{1,2},aCueo{2,1},aCueo{2,2});
  180. avg_aCueor=mean(aCueor,3);
  181. Paramsr=cat(3,Params{1,1},Params{1,2},Params{2,1},Params{2,2});
  182. avg_Paramsr=mean(Paramsr,3);
  183. %% and general polar plot of bias (averaged across items and tests)
  184. oi=avg_bCueor;
  185. oiac=avg_aCueor;
  186. yourBias=[];
  187. yourAccu=[];
  188. for ppp=1:size(oi,2)
  189. behB=oi(:,ppp)'; %Bevah Bias
  190. s=avg_Paramsr(ppp,1); % noise (in memory/decision-making)
  191. A=avg_Paramsr(ppp,2); % Key Parameter (squircle) 0: all circle; 1: all square
  192. C=avg_Paramsr(ppp,3); % Reduce noise near cardinal by this factor (1: off)
  193. makefig=0;
  194. [yourAccu(:,ppp) yourBias(:,ppp)]=squircleBehave2compB(s,A,C,behB,makefig);
  195. end
  196. counter=1;
  197. figure;
  198. quickplotcompBerrors(bb',(yourBias),(oi),['bias'],1);
  199. counter=counter+1,
  200. set(gca,'FontSize',12);
  201. %%
  202. %% subfucntions
  203. function barplotbias(data,yl,tito,yla,beh)
  204. ax=notBoxPlot(data,'style','sdline')
  205. line([0,5], [0,0], 'Color', 'k','LineStyle',':','LineWidth',2);hold on;
  206. line([2.5,2.5], [-10,10], 'Color', 'k','LineStyle','--','LineWidth',2);hold on;
  207. for i=1:4
  208. ax(i).semPtch.FaceColor = [0.75 0.75 0.75];
  209. ax(i).semPtch.EdgeColor = [0.75 0.75 0.75];
  210. ax(i).semPtch.LineWidth = 3;
  211. ax(i).mu.Color = [0 0 0];
  212. ax(i).sd.Color = [0 0 0];
  213. end
  214. xticks([1:4])
  215. if beh
  216. xticklabels({'stim 1/test 1','stim 2/test 1','stim 1/test 2','stim 2/test 2'})
  217. else
  218. xticklabels({'stim 1/delay 1','stim 2/delay 1','stim 1/delay 2','stim 2/delay 2'})
  219. end
  220. xtickangle(45)
  221. ylim(yl)
  222. xlim([0.5 4.5])
  223. ylabel(yla)
  224. set(gca,'FontSize',20);
  225. title(tito)
  226. end