findAbehavPerItem.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. clear all
  2. load('behavdata/datPerItem.mat')
  3. addpath(genpath([''])); %Add here the subfolder of subfunction (root folder)
  4. aCue{1,1}=squeeze(accrot_cu_uncue{1}(:,1,:)); %Accuracy 1st obj and 1st Test
  5. aCue{1,2}=squeeze(accrot_cu_uncue{1}(:,2,:)); %Accuracy 1st obj 2nd Test
  6. aCue{2,1}=squeeze(accrot_cu_uncue{2}(:,1,:)); %Accuracy 2st obj and 1st Test
  7. aCue{2,2}=squeeze(accrot_cu_uncue{2}(:,2,:)); %Accuracy 2st obj 2nd Test
  8. bCue{1,1}=squeeze(bias_cue{1}(:,1,:)); %Bias 1st item 1st Test
  9. bCue{1,2}=squeeze(bias_uncue{1}(:,1,:)); %Bias 1st 2nd Test
  10. bCue{2,1}=squeeze(bias_cue{2}(:,1,:)); %Bias 1st item 1st Test
  11. bCue{2,2}=squeeze(bias_uncue{2}(:,1,:)); %Bias 1st 2nd Test
  12. % aCueg = ((aCue1+aCue2)./2)
  13. % bCueg = ((bCue1+bCue2)./2)
  14. groupave=0 % If we want to calculate A using the group average
  15. if groupave
  16. for item=1:2
  17. for test=1:2
  18. aCue{item,test}=mean(aCue{item,test}(:,:),2)
  19. bCue{item,test}=mean(bCue{item,test}(:,:),2)
  20. end
  21. end
  22. end
  23. %% order the data in standard presentation
  24. ao=deg2rad(accrot_cu_uncue{1}(:,3,1));
  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. bCueo{item,test}=bCue{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=1;%0.0:0.02:2;%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. aCue=(aCueo{item,test}(:,ppp)');
  41. bCue=(bCueo{item,test}(:,ppp)');
  42. BestParams(ppp,:,item,test)=gridsearch_jld(aCue,bCue,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. end
  46. %% Changing format
  47. for item = 1:2
  48. for test=1:2
  49. Params{item,test}= squeeze(BestParams(:,:,item,test));% info about test 1
  50. Params{item,test}= squeeze(BestParams(:,:,item,test));% info about test 1
  51. end
  52. end
  53. %% Plotting all parameters
  54. outputlabels={'s (noise)',' A (squircle factor)', 'C (cardinal precision)',' min SSQ'};
  55. figure;
  56. for lp = 1:4
  57. all{1}= (cat(2,Params{1,1}(:,lp),Params{2,1}(:,lp),Params{1,2}(:,lp),Params{2,2}(:,lp)))
  58. subplot(2,2,lp)
  59. barplotbias(all{1},[min(all{1}(:)-0.0001),max(all{1}(:))+0.0001],' ',outputlabels{lp},1)
  60. end
  61. %% Anova
  62. addpath '\rm_anova2'
  63. removingout=0
  64. if removingout ==1 %if removing the outlier
  65. [m I]=max(Params{1,2}(:,4))
  66. ind = 1:length((Params{1,2}(:,4)))~=I;
  67. else
  68. ind = 1:length((Params{1,2}(:,4)))~=0;
  69. end
  70. a1= (cat(1,Params{1,1}(ind,2),Params{2,1}(ind,2),Params{1,2}(ind,2),Params{2,2}(ind,2))')
  71. p=(sum(ind));
  72. S=[1:p,1:p,1:p,1:p];
  73. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  74. F2=[ones(p*2,1);ones(p*2,1)*2]'
  75. FACTNAMES={'item order', 'test order'}
  76. stats = rm_anova2(a1,S,F1,F2,FACTNAMES)
  77. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  78. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  79. %%
  80. all{1}= (cat(2,Params{1,1}(:,2),Params{2,1}(:,2),Params{1,2}(:,2),Params{2,2}(:,2)))
  81. for rrr=1:4
  82. [h,p,ci,stats] = ttest(all{1}(:,rrr),0)
  83. ttesre(rrr,1)=stats.tstat;
  84. ttesre(rrr,2)=p;
  85. end
  86. %% Plotting A index (bars)
  87. all{1}= (cat(2,Params{1,1}(:,2),Params{2,1}(:,2),Params{1,2}(:,2),Params{2,2}(:,2)))
  88. names{1}='all'
  89. figure;
  90. for t=1
  91. avg=nanmean(all{t},1);
  92. sem=std(all{t})/sqrt(size(all{t},1));
  93. % subplot(1,3,t)
  94. % bar(rot_dif_list,avg);hold on,
  95. if groupave
  96. plot(avg,'o')
  97. else
  98. er=errorbar([],avg,sem,sem,'o');
  99. er.Color = [0 0 0];
  100. er.LineStyle = 'none';
  101. end
  102. % ylim([0 0.34])
  103. xlim([0 5])
  104. % line([0,5],[0.5 0.5], 'Color', 'k','LineStyle','--');hold on;
  105. xticks([1:4])
  106. xticklabels({'ori 1 1st test','ori 2 1st test','ori 1 2nd test','ori 2 2nd test'})
  107. % xlabel('distance between 1stcued minus 2nd cued ori (degrees)')
  108. ylabel('cardinal repulsion index (bias index)')
  109. title(['bias index - ' names{t}])
  110. end
  111. %% Plotting A index (bars) -version 2
  112. figure('Position' ,[100 600 950 600]);
  113. ax=notBoxPlot(all{1},'style','sdline')
  114. for i=1:4
  115. ax(i).semPtch.FaceColor = [0.75 0.75 0.75];
  116. ax(i).semPtch.EdgeColor = [0.75 0.75 0.75];
  117. ax(i).semPtch.LineWidth = 3;
  118. ax(i).mu.Color = [0 0 0];
  119. ax(i).sd.Color = [0 0 0];
  120. end
  121. xticks([1:4])
  122. xticklabels({'object 1 - test 1','object 2 - test 1','object 1 - test 2','object 2- test 2'})
  123. ylim([-0.41 .615])
  124. ylabel('A (bias index)')
  125. set(gca,'FontSize',13);
  126. %% and groupal polar plot per item and test
  127. for item = 1:2
  128. for test=1:2
  129. oi=bCueo{item,test};
  130. oiac=aCueo{item,test};
  131. yourBias=[];
  132. yourAccu=[];
  133. for ppp=1:size(oi,2)
  134. behB=oi(:,ppp)'; %BheaviouralBias
  135. s=Params{item,test}(ppp,1); % noise (in memory/decision-making)
  136. A=Params{item,test}(ppp,2); % Key Parameter (squircle) 0: all circle; 1: all square
  137. C=Params{item,test}(ppp,3); % Reduce noise near cardinal by this factor (1: off)
  138. makefig=0;
  139. [yourAccu(:,ppp) yourBias(:,ppp)]=squircleBehave2compB(s,A,C,behB,makefig);
  140. end
  141. counter=1;
  142. figure;
  143. subplot(1,2,counter)
  144. quickplotcompBerrors(bb',(yourBias),(oi),['bias - object - ' num2str(item) ' test- ' num2str(test)],1);
  145. counter=counter+1,
  146. set(gca,'FontSize',12);
  147. subplot(1,2,counter)
  148. quickplotcompBerrors(bb',(yourAccu),(oiac),['accuracy - item- ' num2str(item) ' test- ' num2str(test)],0);
  149. counter=counter+1,
  150. set(gca,'FontSize',12);
  151. end
  152. end
  153. %%
  154. bCueor=cat(3,bCueo{1,1},bCueo{1,2},bCueo{2,1},bCueo{2,2});
  155. avg_bCueor=mean(bCueor,3);
  156. aCueor=cat(3,aCueo{1,1},aCueo{1,2},aCueo{2,1},aCueo{2,2});
  157. avg_aCueor=mean(aCueor,3);
  158. Paramsr=cat(3,Params{1,1},Params{1,2},Params{2,1},Params{2,2});
  159. avg_Paramsr=mean(Paramsr,3);
  160. %% and general polar plot of bias (averaged across items and tests)
  161. oi=avg_bCueor;
  162. oiac=avg_aCueor;
  163. yourBias=[];
  164. yourAccu=[];
  165. for ppp=1:size(oi,2)
  166. behB=oi(:,ppp)'; %Bevah Bias
  167. s=avg_Paramsr(ppp,1); % noise (in memory/decision-making)
  168. A=avg_Paramsr(ppp,2); % Key Parameter (squircle) 0: all circle; 1: all square
  169. C=avg_Paramsr(ppp,3); % Reduce noise near cardinal by this factor (1: off)
  170. makefig=0;
  171. [yourAccu(:,ppp) yourBias(:,ppp)]=squircleBehave2compB(s,A,C,behB,makefig);
  172. end
  173. counter=1;
  174. figure;
  175. quickplotcompBerrors(bb',(yourBias),(oi),['bias'],1);
  176. counter=counter+1,
  177. set(gca,'FontSize',12);
  178. % subplot(1,2,counter)
  179. %
  180. % quickplotcompBerrors(bb',(yourAccu),(oiac),['accuracy - item- ' num2str(item) ' test- ' num2str(test)],0);
  181. % counter=counter+1,
  182. %
  183. % set(gca,'FontSize',12);
  184. %%
  185. %% subfucntions
  186. function barplotbias(data,yl,tito,yla,beh)
  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).mu.Color = [0 0 0];
  195. ax(i).sd.Color = [0 0 0];
  196. end
  197. xticks([1:4])
  198. if beh
  199. xticklabels({'stim 1/test 1','stim 2/test 1','stim 1/test 2','stim 2/test 2'})
  200. else
  201. xticklabels({'stim 1/delay 1','stim 2/delay 1','stim 1/delay 2','stim 2/delay 2'})
  202. end
  203. xtickangle(45)
  204. ylim(yl)
  205. xlim([0.5 4.5])
  206. ylabel(yla)
  207. set(gca,'FontSize',20);
  208. title(tito)
  209. end