rsa_simul_paper.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. clear all
  2. mainfolder='';
  3. addpath(genpath(['subfunctions/']))
  4. %% Loading the data
  5. folder1=[mainfolder,'results/mean_recentered_th100/euclideanmodels/single_trial_RSA_first_check_object_1_Pearson/']
  6. folder2=[mainfolder,'results/mean_recentered_th100/euclideanmodels/single_trial_RSA_first_check_object_2_Pearson/']
  7. load([mainfolder 'good_partis.mat']) %list of participant with a good performance
  8. partis=good_partis'
  9. counter=1;
  10. for ppp=1:length(partis)
  11. toload=[folder1, partis{ppp,:},'.mat']
  12. load(toload)
  13. RHO1{counter}(:,:)=(RSA_obj_rot.rho);
  14. toload=[folder2, partis{ppp,:},'.mat']
  15. load(toload)
  16. RHO2{counter}(:,:)=(RSA_obj_rot.rho);
  17. counter=counter+1;
  18. end
  19. time=RSA_obj_rot.time;
  20. %% Select, cut and average time window of interest
  21. p1=1250; %start time
  22. p2=2000; %end time
  23. for ppp=1:size(RHO2,2)
  24. [rho1cut{ppp},timecut1]=selecttimewindow(RHO1{ppp},time,p1,p2);
  25. [rho2cut{ppp},timecut2]=selecttimewindow(RHO2{ppp},time,p1,p2);
  26. rho1cutavg{ppp}=nanmean(rho1cut{ppp},2);
  27. rho2cutavg{ppp}=nanmean(rho2cut{ppp},2);
  28. end
  29. %% Exploring the data
  30. colores=(colormap((parula(size(RHO2,2)))));
  31. gooddecoding=[]
  32. figure;
  33. for ppp=1:size(RHO2,2)
  34. subplot(2,1,1)
  35. title(['single trial ori decoding per parti - stim 1'])
  36. a=plot(timecut1,nanmean(rho1cut{ppp},1),'Color',colores(ppp,:),'LineWidth',2);hold on
  37. subplot(2,1,2)
  38. title(['single trial ori decoding per parti - stim 2'])
  39. b=plot(timecut1,nanmean(rho2cut{ppp},1),'Color',colores(ppp,:),'LineWidth',2);hold on
  40. if nanmean(nanmean(rho2cut{ppp},1))>= 0.02
  41. gooddecoding=[gooddecoding ppp];
  42. end
  43. end
  44. xlabel('time (ms)')
  45. ylabel('correlation with model')
  46. %% Calculating the simult
  47. nbins=9; %number of bins
  48. edges=[];
  49. rho1aveperbin=[];
  50. counter=1;
  51. for ppp= 1:size(RHO2,2)%gooddecoding %
  52. [N,edges(counter,:)] = histcounts(rho2cutavg{ppp},nbins);
  53. Y = discretize(rho2cutavg{ppp},edges(counter,:));
  54. for nb = 1:nbins
  55. rho2cutavg{counter}(Y==nb);
  56. rho1aveperbin(counter,nb)=nanmean(rho1cutavg{ppp}(Y==nb));
  57. end
  58. counter=counter+1;
  59. end
  60. %% Analysis and plot
  61. [h,p,ci,stats]=ttest(rho1aveperbin,0);
  62. corrected_p=double(p*(length(p))<0.05); % Bonfe correction and p<0.05
  63. foundp=find(corrected_p==1);
  64. mean_da=mean(rho1aveperbin,1)
  65. sem_da=nanstd(rho1aveperbin,0,1)/sqrt(sum(~isnan(rho1aveperbin(1,:))))
  66. meanedges=mean(edges,1)
  67. figure('Position',([200 800 380 360]))
  68. errorbar(meanedges(2:end),mean_da,sem_da,'-k','LineWidth', 2.5);hold on;
  69. line([1,-1], [0,0], 'Color', 'k','LineStyle',':','LineWidth', 3);hold on;
  70. scatter(meanedges(foundp+1),corrected_p(foundp)*0.15,65,'k*');hold on;
  71. xlim([-.7 0.8])
  72. ylim([-.05 .2])
  73. xlabel('Stimulus 2 (rho)')
  74. ylabel('Stimulus 1 (rho)')
  75. set(gca,'FontSize',22);
  76. [h,p,ci,stats]=ttest(rho1aveperbin,0)
  77. %% Check linear trend
  78. for ppp = 1:size(rho1aveperbin,1)
  79. tof=[];
  80. for c=1:size(rho1aveperbin,2);
  81. tof=[tof; rho1aveperbin(ppp,c)];
  82. end
  83. [b,dev,stats] = glmfit(1:size(rho1aveperbin,2),tof,'normal');
  84. ball(ppp) = b(2);
  85. end
  86. [h,p,ci,stats] = ttest(ball,0)
  87. [p,h,stats] = signrank(ball,0)