Figure_2_and_stats.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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_RSA_first_check_object_1_cued_Pearson/']
  7. % folder{2}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/single_trial_RSA_first_check_object_1_uncued_Pearson/']
  8. % folder{3}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/single_trial_RSA_first_check_object_2_cued_Pearson/']
  9. % folder{4}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/single_trial_RSA_first_check_object_2_uncued_Pearson/']
  10. %
  11. % load([mainfolder, 'good_partis.mat']) %list of participant with a good performance
  12. % partis=good_partis';
  13. %
  14. %
  15. % for fff=1:size(folder,2)
  16. %
  17. % counter=1;
  18. % RHO_id=[];
  19. %
  20. % for ppp=1:length(partis)
  21. %
  22. % toload=[folder{fff}, partis{ppp,:},'.mat']
  23. % load(toload)
  24. % RHO_id(:,counter)=nanmean(RSA_obj_rot.rho,1);
  25. % counter=counter+1;
  26. %
  27. % end
  28. % RHO_all{fff}=RHO_id
  29. % end
  30. %
  31. % time=RSA_obj_rot.time;
  32. %
  33. %
  34. % %% Cluster analysis for each line
  35. %
  36. % pv_cluster=0.0125; % p-vals for clust perm test
  37. % az=zeros(size(RHO_all{1})); % matrix to be compare (in this case against 0);
  38. %
  39. % timesignclust=allclustperm(RHO_all,time,az,pv_cluster) % output variable (rows -> lines; columns -> start and end (ms))
  40. %
  41. % mean([timesignclust(1,1) timesignclust(2,1) timesignclust(3,1)-1000 timesignclust(4,1)-1000]) %average of "starting" point;
  42. %
  43. %
  44. % %% Detecting peaks during encoding
  45. %
  46. % maxstim1cue=maxintime(RHO_all{1},time,0,1000)
  47. % maxstim1uncue=maxintime(RHO_all{2},time,0,1000)
  48. % maxstim2cue=maxintime(RHO_all{3},time,1000,2000)-1000
  49. % maxstim2uncue=maxintime(RHO_all{4},time,1000,2000)-1000
  50. %
  51. % mean([maxstim1cue maxstim1uncue maxstim2cue maxstim2uncue]) %returning average from all 4 lines
  52. %% Optional -> Loading the data ready to be plotted
  53. load('data_for_plots/Figure_2/delay1_data_n41_2022.mat');
  54. %% And plot
  55. colores1=(colormap(flip(autumn(7))));
  56. colores2=(colormap(flip(summer(7))));
  57. colores=[colores2(7,:);colores1(7,:);colores2(5,:);colores1(4,:)];
  58. figure('Position',([200 900 760 360])) %alt ([200 900 860 360]))
  59. leng1='cued 1st'
  60. leng2='uncued'
  61. leng3='cued 1st'
  62. leng4='uncued'
  63. titu=[];%'RSA - Correlation with continuos model - single trial'
  64. xl=[-500 5850];
  65. yl=[-0.05 0.17];
  66. aga=0;
  67. pval=0.01
  68. spa=-0.004
  69. data=[];
  70. data{1}=RHO_all{1};
  71. data{2}=RHO_all{2};
  72. data{3}=RHO_all{3};
  73. data{4}=RHO_all{4};
  74. % plot4lines_fdr(time,data,colores,xl,yl,leng1,leng2,leng3,leng4,titu,aga,pval,spa,1)
  75. plot4lines(time,data,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,1,1,timesignclust,colores)
  76. % fill([2000 2350 2000 2350],[20 20 0 0],'k','LineStyle','none','FaceAlpha',0.20);
  77. set(gca,'FontSize',22);
  78. %% 2nd delay
  79. clear all
  80. %% Uncomment to load the RSA data and perform the cluster perm
  81. %
  82. % folder{1}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_RSA_first_check_object_1_cued_Pearson/']
  83. % folder{2}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_RSA_first_check_object_1_uncued_Pearson/']
  84. % folder{3}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_RSA_first_check_object_2_cued_Pearson/']
  85. % folder{4}=[mainfolder,'results/mean_recentered_th100/euclideanmodels/2nd_cue/single_trial_RSA_first_check_object_2_uncued_Pearson/']
  86. %
  87. % load([mainfolder, 'good_partis.mat']) %list of participant with a good performance
  88. % partis=good_partis';
  89. %
  90. % for fff=1:size(folder,2)
  91. %
  92. % counter=1;
  93. % RHO_id=[];
  94. %
  95. % for ppp=1:length(partis)
  96. %
  97. % toload=[folder{fff}, partis{ppp,:},'.mat']
  98. % load(toload)
  99. % RHO_id(:,counter)=nanmean(RSA_obj_rot.rho,1);
  100. % counter=counter+1;
  101. %
  102. % end
  103. % RHO_all{fff}=RHO_id
  104. % end
  105. %
  106. % time=RSA_obj_rot.time;
  107. %
  108. % %% Cluster analysis for each line
  109. %
  110. % pv_cluster=0.0125; % p-vals for clust perm test
  111. % az=zeros(size(RHO_all{1})); % matrix to be compare (in this case against 0);
  112. %
  113. % timesignclust=allclustperm(RHO_all,time,az,pv_cluster) % output variable (rows -> lines; columns -> start and end (ms))
  114. %
  115. % % mean([timesignclust(1,1) timesignclust(2,1) timesignclust(3,1)-1000 timesignclust(4,1)-1000]) %average of "starting" point;
  116. %% And plot
  117. %% Optional -> Loading the data ready to be plotted
  118. load('data_for_plots/Figure_2/delay2_data_n41_2022.mat');
  119. %% mode 6
  120. colores1=(colormap(flip(autumn(7))));
  121. colores2=(colormap(flip(summer(7))));
  122. colores=[colores2(7,:);colores1(7,:);colores2(5,:);colores1(4,:)];
  123. figure('Position',([200 900 420 360])) % alt. [200 900 440 360]
  124. leng1='cued 1st'
  125. leng2='cued 2nd'
  126. leng3='cued 1st'
  127. leng4='cued 2nd'
  128. titu=[];%'RSA - Correlation with continuos model - single trial'
  129. xl=[-300 2850];
  130. yl=[-0.05 0.17];
  131. aga=0;
  132. pval=0.01
  133. spa=-0.004
  134. data=[];
  135. data{1}=RHO_all{1};
  136. data{2}=RHO_all{2};
  137. data{3}=RHO_all{3};
  138. data{4}=RHO_all{4};
  139. % plot4lines_fdr_2nd_2(time,data,colores,xl,yl,leng1,leng2,leng3,leng4,titu,aga,pval,spa,1)
  140. plot4lines_2nd(time,data,colores,xl,yl,leng1,leng2,leng3,leng4,titu,1,1,1,timesignclust,colores)
  141. set(gca,'FontSize',22);
  142. %% Subfunctions
  143. %Times for encoding of stimulus 1
  144. function output = maxintime(data,time,toi1,toi2)
  145. t1=find(time==toi1);
  146. t2=find(time==toi2);
  147. time2=time(t1:t2);
  148. [B I]=sort(mean(data(t1:t2,:),2),'descend');
  149. output=time2(I(1));
  150. end
  151. function timesignclust=allclustperm(RHO_all,time,az,pv_cluster)
  152. timesignclust=nan(4,2); % output variable (rows -> lines; columns -> start and end (ms))
  153. for r=1:4;
  154. [clusters, p_values, t_sums, permutation_distribution] =permutest(RHO_all{r},az,1,0.05,5000)
  155. if p_values(1)<pv_cluster
  156. timesignclust(r,1)=time(clusters{1}(1))
  157. timesignclust(r,2)=time(clusters{1}(end))
  158. end
  159. end
  160. end