1
0

Figure_3_and_stats.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. clear all
  2. mainfolder='';
  3. addpath(genpath([mainfolder 'subfunctions/']))
  4. addpath(genpath('subfunctions/rm_anova2'))
  5. %% Uncomment to load the RSA data and perform the cluster perm
  6. % folder{1}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/single_trial_with_between_RSA_object_1_cued_cont_Pearson/']
  7. % folder{2}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/single_trial_with_between_RSA_object_1_uncued_cont_Pearson/']
  8. % folder{3}=[mainfolder, 'eyedata/results/mean_recentered_th100/euclideanmodels/single_trial_with_between_RSA_object_2_cued_cont_Pearson/']
  9. % folder{4}=[mainfolder, 'eyedata/results/mean_recentered_th100/euclideanmodels/single_trial_with_between_RSA_object_2_uncued_cont_Pearson/']
  10. %
  11. % % %2nd cue
  12. %
  13. % folder2{1}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_with_between_RSA_object_1_cued_cont_Pearson/']
  14. % folder2{2}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_with_between_RSA_object_1_uncued_cont_Pearson/']
  15. % folder2{3}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_with_between_RSA_object_2_cued_cont_Pearson/']
  16. % folder2{4}=[mainfolder, 'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_with_between_RSA_object_2_uncued_cont_Pearson/']
  17. %
  18. % load([mainfolder, 'good_partis.mat']) %list of participant with a good performance
  19. % %
  20. % partis=good_partis'
  21. %
  22. % %% Loading with the script
  23. % [RHO_id_group_1, time_1]=loadwithbet(folder, partis)
  24. % [RHO_id_group_2, time_2]=loadwithbet(folder2, partis)
  25. %
  26. % %% Ordering variables
  27. %
  28. % a1_1=[];
  29. % a2_1=[];
  30. % a3_1=[];
  31. %
  32. % a1_1{1}=RHO_id_group_1{1};
  33. % a1_1{2}=RHO_id_group_1{2};
  34. % a1_1{3}=RHO_id_group_1{4};
  35. % a1_1{4}=RHO_id_group_1{5};
  36. %
  37. % a2_1{1}=RHO_id_group_1{7};
  38. % a2_1{2}=RHO_id_group_1{8};
  39. % a2_1{3}=RHO_id_group_1{10};
  40. % a2_1{4}=RHO_id_group_1{11};
  41. %
  42. % a3_1{1}=RHO_id_group_1{3};
  43. % a3_1{2}=RHO_id_group_1{6};
  44. % a3_1{3}=RHO_id_group_1{9};
  45. % a3_1{4}=RHO_id_group_1{12};
  46. %
  47. % a1_2=[];
  48. % a2_2=[];
  49. % a3_2=[];
  50. %
  51. % a1_2{1}=RHO_id_group_2{1};
  52. % a1_2{2}=RHO_id_group_2{2};
  53. % a1_2{3}=RHO_id_group_2{4};
  54. % a1_2{4}=RHO_id_group_2{5};
  55. %
  56. % a2_2{1}=RHO_id_group_2{7};
  57. % a2_2{2}=RHO_id_group_2{8};
  58. % a2_2{3}=RHO_id_group_2{10};
  59. % a2_2{4}=RHO_id_group_2{11};
  60. %
  61. % a3_2{1}=RHO_id_group_2{3};
  62. % a3_2{2}=RHO_id_group_2{6};
  63. % a3_2{3}=RHO_id_group_2{9};
  64. % a3_2{4}=RHO_id_group_2{12};
  65. %
  66. % %% Cluster analysis of the difference within-between (delay 1)
  67. %
  68. % %Setting times (from -100 stim onset until the end of the delay period)
  69. % t1=find(time_1==-100)
  70. % t2=find(time_1==5850)
  71. % t1_2=find(time_1==900)
  72. % [timesignclust cluspval] = cluster_dif(a1_1,a2_1,time_1,t1,t2,t1_2)
  73. %
  74. % % mean([timesignclust(1,1) timesignclust(2,1)]) %average of "starting" points;
  75. %
  76. % % Creating 2 variables to use it for the plots and respect the colours
  77. % timesignclust_1 = nan(4,2);
  78. % timesignclust_2 = nan(4,2);
  79. % timesignclust_1([1 3],:)=timesignclust([1 3],:);
  80. % timesignclust_2([1 3],:)=timesignclust([2 4],:);
  81. %
  82. % %% Cluster analysis of the difference within-between (delay 2)
  83. %
  84. % %Setting times (from -100 stim onset until the end of the delay period)
  85. % t1=find(time_2==-100);
  86. % t2=find(time_2==2850);
  87. % t1_2=find(time_2==-100);
  88. % [timesignclust2 cluspva2] = cluster_dif(a1_2,a2_2,time_2,t1,t2,t1_2)
  89. %
  90. % % mean([timesignclust(1,1) timesignclust(2,1)]) %average of "starting" point;
  91. %
  92. % % Creating 2 variables to use it for the plots and respect the colours
  93. % timesignclust_1_2 = nan(4,2);
  94. % timesignclust_2_2 = nan(4,2);
  95. % timesignclust_1_2([1 3],:)=timesignclust2([1 3],:);
  96. % timesignclust_2_2([1 3],:)=timesignclust2([2 4],:);
  97. %% Optional -> Loading the data ready to be plotted
  98. load('data_for_plots/Figure_3/data_n41_2022.mat');
  99. %% And plot
  100. %Preparing colors
  101. colores1=(colormap((winter(4))));
  102. colores2=(colormap((cool(4))));
  103. colores=[colores2(4,:);colores2(3,:);colores1(4,:);colores1(3,:)];
  104. colores3=(colormap((winter(8))));
  105. colores4=(colormap((cool(8))));
  106. coloresclus=[colores4(7,:);colores4(7,:);colores3(7,:);colores3(7,:)];
  107. figure('Position',([200 800 750 700]))
  108. subplot(2,1,1)
  109. leng1='cued within'
  110. leng2='cued between'
  111. leng3='uncued within'
  112. leng4='uncued between'
  113. titu=''
  114. xl=[-500 5850];
  115. yl=[-0.05 0.17];
  116. plot4lines_errorback(time_1,a1_1,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,0,1,timesignclust_1,coloresclus)
  117. set(gca,'FontSize',22);
  118. subplot(2,1,2)
  119. titu=''
  120. plot4lines_errorback(time_1,a2_1,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,0,1,timesignclust_2,coloresclus)
  121. set(gca,'FontSize',22);
  122. %% Plotting the 2nd delay
  123. figure('Position',([200 800 420 700]))
  124. subplot(2,1,1)
  125. leng1='cued 1st within'
  126. leng2='cued 1st between'
  127. leng3='cued 2nd within'
  128. leng4='cued 2nd between'
  129. titu=''
  130. xl=[-300 2850];
  131. yl=[-0.05 0.17];
  132. plot4lines_2nd_errorback(time_2,a1_2,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,0,1,timesignclust_1_2,coloresclus)
  133. set(gca,'FontSize',22);
  134. subplot(2,1,2)
  135. titu=''
  136. plot4lines_2nd_errorback(time_2,a2_2,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,0,1,timesignclust_2_2,coloresclus)
  137. set(gca,'FontSize',22);
  138. %% STATS ANOVA
  139. % Encoding
  140. toi1ori1 = [0 1000];%time of interest for ori 1
  141. toi1ori2 = [1000 2000];%time of interest for ori 1
  142. % toi1 = [0 500];%time of interest for ori 1
  143. t1_1=find(time_1==toi1ori1(1));
  144. t2_1=find(time_1==toi1ori1(2));
  145. t1_1ori2=find(time_1==toi1ori2(1));
  146. t2_1ori2=find(time_1==toi1ori2(2));
  147. %ori1 cued
  148. av_a1cued1 =nanmean(a1_1{1}(t1_1:t2_1,:),1); % with 1
  149. av_a1cued2 =nanmean(a1_1{2}(t1_1:t2_1,:),1); % bet 1
  150. %ori2 cued
  151. av_a2cued1 =nanmean(a2_1{1}(t1_1ori2:t2_1ori2,:),1); % w 2
  152. av_a2cued2 =nanmean(a2_1{2}(t1_1ori2:t2_1ori2,:),1); % betwen 2
  153. % addpath(genpath(['/rm_anova2']))
  154. aa= cat(1,av_a1cued1,av_a1cued2,av_a2cued1,av_a2cued2)'
  155. p=size(av_a1cued1,2);
  156. S=[1:p,1:p,1:p,1:p];
  157. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  158. F2=[ones(p*2,1);ones(p*2,1)*2]'
  159. FACTNAMES={'between-within', 'item order'}
  160. stats = rm_anova2(aa,S,F1,F2,FACTNAMES)
  161. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  162. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  163. %% STATS ANOVA
  164. % 1st delay
  165. toi1 = [2350 5850];%time of interest for ori 1
  166. % toi1 = [0 500];%time of interest for ori 1
  167. % toi1 = [3350 5850];%time of interest for delay 1 1s_after_cueonset
  168. t1_1=find(time_1==toi1(1));
  169. t2_1=find(time_1==toi1(2));
  170. %ori1 cued
  171. av_a1cued1 =nanmean(a1_1{1}(t1_1:t2_1,:),1); % with 1
  172. av_a1cued2 =nanmean(a1_1{2}(t1_1:t2_1,:),1); % bet 1
  173. %ori2 cued
  174. av_a2cued1 =nanmean(a2_1{1}(t1_1:t2_1,:),1); % w 2
  175. av_a2cued2 =nanmean(a2_1{2}(t1_1:t2_1,:),1); % betwen 2
  176. addpath(genpath(['/rm_anova2']))
  177. aa= cat(1,av_a1cued1,av_a1cued2,av_a2cued1,av_a2cued2)'
  178. p=size(av_a1cued1,2);
  179. S=[1:p,1:p,1:p,1:p];
  180. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  181. F2=[ones(p*2,1);ones(p*2,1)*2]'
  182. FACTNAMES={'between-within', 'item order'}
  183. stats = rm_anova2(aa,S,F1,F2,FACTNAMES)
  184. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  185. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  186. %% T-test (delay1)
  187. [h,p,ci,stats]= ttest(av_a2cued1,av_a2cued2) % stim 2 cued - withing vs between
  188. [h,p,ci,stats]= ttest(av_a1cued1,av_a1cued2) % stim 2 cued - withing vs between
  189. %% 2nd delay
  190. % toi12 = [350 2850];%time of interest for ori 1
  191. toil2 = [1350 2850];%time of interest for delay 1 1s_after_cueonset
  192. t1_2=find(time_2==toi12(1));
  193. t2_2=find(time_2==toi12(2));
  194. %ori1 cued
  195. av_a1cued1 =nanmean(a1_2{3}(t1_2:t2_2,:),1); % with 1
  196. av_a1cued2 =nanmean(a1_2{4}(t1_2:t2_2,:),1); % bet 1
  197. %ori2 cued
  198. av_a2cued1 =nanmean(a2_2{3}(t1_2:t2_2,:),1); % w 2
  199. av_a2cued2 =nanmean(a2_2{4}(t1_2:t2_2,:),1); % betwen 2
  200. addpath(genpath(['/rm_anova2']))
  201. aa= cat(1,av_a1cued1,av_a1cued2,av_a2cued1,av_a2cued2)'
  202. p=size(av_a1cued1,2);
  203. S=[1:p,1:p,1:p,1:p];
  204. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  205. F2=[ones(p*2,1);ones(p*2,1)*2]'
  206. FACTNAMES={'between-within', 'item order'}
  207. stats = rm_anova2(aa,S,F1,F2,FACTNAMES)
  208. %%
  209. %% T-test (delay2)
  210. [h,p,ci,stats]= ttest(av_a2cued1,av_a2cued2) % stim 2 cued - withing vs between
  211. [h,p,ci,stats]= ttest(av_a1cued1,av_a1cued2) % stim 1 cued - withing vs between
  212. %% On the DIF
  213. toi11 = [2350 5850];%time of interest for delay 1 1s_after_cueonset
  214. t1_1=find(time_1==toi11(1));
  215. t2_1=find(time_1==toi11(2));
  216. toil2 = [350 2850];%time of interest for delay 1 1s_after_cueonset
  217. t1_2=find(time_2==toil2(1));
  218. t2_2=find(time_2==toil2(2));
  219. av_a1cued1=nanmean(a1_1{1}(t1_1:t2_1,:),1)-nanmean(a1_1{2}(t1_1:t2_1,:),1); %dif item 1, cue 1 b-w 1st delay
  220. av_a2cued1=nanmean(a2_1{1}(t1_1:t2_1,:),1)-nanmean(a2_1{2}(t1_1:t2_1,:),1); %dif item 2, cue 1 b-w 1st delay
  221. av_a1cued2=nanmean(a1_2{3}(t1_2:t2_2,:),1)-nanmean(a1_2{4}(t1_2:t2_2,:),1); %dif item 1, cue 1 b-w 1st delay
  222. av_a2cued2=nanmean(a2_2{3}(t1_2:t2_2,:),1)-nanmean(a2_2{4}(t1_2:t2_2,:),1); %dif item 2, cue 1 b-w 1st delay
  223. aa= cat(1,av_a1cued1,av_a1cued2,av_a2cued1,av_a2cued2)'
  224. p=size(av_a1cued1,2);
  225. S=[1:p,1:p,1:p,1:p];
  226. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  227. F2=[ones(p*2,1);ones(p*2,1)*2]'
  228. FACTNAMES={'delay 1st or 2nd', 'item order'}
  229. stats = rm_anova2(aa,S,F1,F2,FACTNAMES)
  230. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  231. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  232. %%
  233. eye.all{1}(:,1)=av_a1cued1
  234. eye.all{1}(:,2)=av_a2cued1
  235. eye.all{1}(:,3)=av_a1cued2
  236. eye.all{1}(:,4)=av_a2cued2
  237. %% eye plot
  238. labels={'stim 1/delay 1','stim 2/delay 1','stim 1/delay 2','stim 2/delay 2'};
  239. figure
  240. barplotbias(eye.all{1},[-.075,.2],' ','diff within - between',labels)
  241. %% Linear trend regarding distance
  242. %from closest to longest disntace
  243. distances(:,1)=av_a2cued1 %stim 2 cued 1st
  244. distances(:,2)=av_a1cued1 %stim 1 cued 1st
  245. distances(:,3)=av_a2cued2 %stim 2 cued 2nd
  246. distances(:,4)=av_a1cued2 %stim 1 cued 2nd
  247. %% Check linear trend
  248. ball=[];
  249. yfit=[];
  250. for ppp = 1:size(distances,1)
  251. tof=[];
  252. for c=1:size(distances,2);
  253. tof=[tof; distances(ppp,c)];
  254. end
  255. [b,dev,stats] = glmfit(1:size(distances,2),tof,'normal');
  256. yfit(ppp,:) = polyval([b(2,1),b(1,1)],[1,2,3,4]);
  257. ball(ppp) = b(2);
  258. end
  259. [h,p,ci,stats] = ttest(ball,0)
  260. [p,h,stats] = signrank(ball,0)
  261. %%
  262. all{1}= distances
  263. labels={'Stim 2','Stim 1','Stim 2','Stim 1'};
  264. figure
  265. plot(yfit','Color',[0 0 0 0.25],'LineWidth',1);hold on;
  266. plot(mean(yfit,1)','Color',[0 0 0],'LineWidth',4);hold on;
  267. barplotbias(all{1},[-.07,.19],' ','\Delta (rho) within - between',labels)
  268. %% subfuctions
  269. function barplotbias(data,yl,tito,yla,labels)
  270. ax=notBoxPlot(data,'style','sdline')
  271. line([0,5], [0,0], 'Color', 'k','LineStyle',':','LineWidth',2);hold on;
  272. line([2.5,2.5], [-10,10], 'Color', 'k','LineStyle','--','LineWidth',2);hold on;
  273. for i=1:4
  274. ax(i).semPtch.FaceColor = [0.75 0.75 0.75];
  275. ax(i).semPtch.EdgeColor = [0.75 0.75 0.75];
  276. % ax(i).semPtch.LineWidth = 10;
  277. ax(i).mu.LineWidth = 5;
  278. ax(i).data.MarkerSize = 8;
  279. ax(i).mu.Color = [0 0 0];
  280. ax(i).sd.Color = [0 0 0];
  281. end
  282. xticks([1:4])
  283. xticklabels(labels)
  284. % xtickangle(45)
  285. ylim(yl)
  286. ylabel(yla)
  287. xlim([0.5 4.5])
  288. sublabels{1}='Delay 1'
  289. sublabels{2}='Delay 2'
  290. xpos=0.15
  291. text(1.5,xpos,sublabels{1},'HorizontalAlignment','center','FontSize',25,'FontWeight','bold')
  292. text(3.5,xpos,sublabels{2},'HorizontalAlignment','center','FontSize',25,'FontWeight','bold')
  293. set(gca,'FontSize',25);
  294. title(tito)
  295. end
  296. function [timesignclust cluspv]=allclustperm2(RHO_all,time,az,pv_cluster)
  297. timesignclust=nan(size(RHO_all,2),2); % output variable (rows -> lines; columns -> start and end (ms))
  298. for r=1:size(RHO_all,2);
  299. [clusters, p_values, t_sums, permutation_distribution] =permutest(RHO_all{r},az{r},1,0.05,20000)
  300. if p_values(1)<pv_cluster
  301. timesignclust(r,1)=time{r}(clusters{1}(1))
  302. timesignclust(r,2)=time{r}(clusters{1}(end))
  303. end
  304. cluspv(r)=p_values(1);
  305. end
  306. end
  307. function [timesignclust cluspv] = cluster_dif(a1_1,a2_1,time_1,t1,t2,t1_2)
  308. %ori1 cued
  309. wi1 =a1_1{1}(t1:t2,:); % with 1
  310. bet1 =a1_1{2}(t1:t2,:); % bet 1
  311. %ori1 uncued
  312. wi1u =a1_1{3}(t1:t2,:); % with 1
  313. bet1u =a1_1{4}(t1:t2,:); % bet 1
  314. %ori2 cued
  315. wi2 =a2_1{1}(t1_2:t2,:); % w 2
  316. bet2 =a2_1{2}(t1_2:t2,:); % betwen 2
  317. %ori2 uncued
  318. wi2u =a2_1{3}(t1_2:t2,:); % w 2
  319. bet2u =a2_1{4}(t1_2:t2,:); % betwen 2
  320. RHOD_wi{1}=wi1();
  321. RHOD_wi{2}=wi2();
  322. RHOD_wi{3}=wi1u();
  323. RHOD_wi{4}=wi2u();
  324. RHOD_be{1}=bet1();
  325. RHOD_be{2}=bet2();
  326. RHOD_be{3}=bet1u();
  327. RHOD_be{4}=bet2u();
  328. pv_cluster=0.0125; % p-vals for clust perm test
  329. % az=zeros(size(RHOD_diff{1})); % matrix to be compare (in this case against 0);
  330. timesall{1}=time_1(t1:t2);
  331. timesall{2}=time_1(t1_2:t2);
  332. timesall{3}=time_1(t1:t2);
  333. timesall{4}=time_1(t1_2:t2);
  334. [timesignclust cluspv]=allclustperm2(RHOD_wi,timesall,RHOD_be,pv_cluster) % output variable (rows -> lines; columns -> start and end (ms))
  335. end