general_accuracy.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. clear all
  2. mainfolder=''
  3. addpath(genpath(['subfunctions/']))
  4. addpath(genpath(['subfunctions/rm_anova2']))
  5. load('good_partis.mat') %list of participant with a good performance
  6. partis_sub=good_partis'
  7. %% Empty variables
  8. accrot_cu_uncue_all{1,1}=nan(512,length(partis_sub));
  9. accrot_cu_uncue_all{1,2}=nan(512,length(partis_sub));
  10. accrot_cu_uncue_all{2,1}=nan(512,length(partis_sub));
  11. accrot_cu_uncue_all{2,2}=nan(512,length(partis_sub));
  12. %%
  13. for ppp=1:length(partis_sub) %Per participant
  14. % Loading dataset
  15. if strcmp( partis_sub{ppp,:},'p11')
  16. load([mainfolder 'logfiles/resultfile_p11_table_repaired.mat'])
  17. else
  18. subtable=[];
  19. sub = tdfread([mainfolder 'logfiles/resultfile_' partis_sub{ppp,:} '.txt'],'tab'); %Logfile for this participant
  20. subtable=struct2table(sub);
  21. end
  22. for item=1:2
  23. % Cue (first test)
  24. toi=subtable.retro_cue==item&subtable.type_of_task==1 ...
  25. &subtable.acc_trial_concrete_cued~=2&subtable.acc_trial_concrete_cued~=NaN;
  26. toi2=subtable.retro_cue==item&subtable.type_of_task==1 ...
  27. &subtable.acc_trial_concrete_cued~=2; %to keep all trials it is fine if the value is NaN
  28. accrot_cu_uncue{item,1}(ppp)= nanmean(subtable.acc_trial_concrete_cued(toi));
  29. accrot_cu_uncue_all{item,1}(toi2,ppp)= (subtable.acc_trial_concrete_cued(toi2));
  30. % Uncue (second test)
  31. toi=subtable.retro_cue_uncued==item&subtable.type_of_task==1 ...
  32. &subtable.acc_trial_concrete_uncued~=2&subtable.acc_trial_concrete_uncued~=NaN;
  33. toi2=subtable.retro_cue_uncued==item&subtable.type_of_task==1 ...
  34. &subtable.acc_trial_concrete_uncued~=2; %to keep all trials it is fine if the value is NaN
  35. accrot_cu_uncue{item,2}(ppp)= nanmean(subtable.acc_trial_concrete_uncued(toi));
  36. accrot_cu_uncue_all{item,2}(toi2,ppp)=(subtable.acc_trial_concrete_uncued(toi2));
  37. end
  38. end
  39. %% Plot
  40. all{1}= cat(2,accrot_cu_uncue{1,1}',accrot_cu_uncue{2,1}',accrot_cu_uncue{1,2}',accrot_cu_uncue{2,2}') %All data together
  41. avg=nanmean(all{1},1);
  42. sem=std(all{1})/sqrt(size(all{1},1));
  43. figure;
  44. er=errorbar([],avg,sem,sem,'o');
  45. er.Color = [0 0 0];
  46. er.LineStyle = 'none';
  47. ylim([0.475 0.8])
  48. xlim([0 5])
  49. line([0,5],[0.5 0.5], 'Color', 'k','LineStyle','--');hold on;
  50. xticks([1:4])
  51. xticklabels({'ori 1 1st test','ori 2 1st test','ori 1 2nd test','ori 2 2nd test'})
  52. ylabel('accuracy')
  53. title(['General accuracy'])
  54. %% Anova
  55. a1= cat(1,accrot_cu_uncue{1,1}',accrot_cu_uncue{2,1}',accrot_cu_uncue{1,2}',accrot_cu_uncue{2,2}')
  56. p=size(accrot_cu_uncue{1,1},2);
  57. S=[1:p,1:p,1:p,1:p];
  58. F1=[ones(p,1);ones(p,1)*2;ones(p,1);ones(p,1)*2]'
  59. F2=[ones(p*2,1);ones(p*2,1)*2]'
  60. FACTNAMES={'stim order', 'test order'}
  61. stats = rm_anova2(a1,S,F1,F2,FACTNAMES)
  62. totalSS=sum([stats{2,2},stats{3,2},stats{4,2},stats{5,2},stats{6,2},stats{7,2}]);
  63. etaS=[stats{2,2}/totalSS,stats{3,2}/totalSS,stats{4,2}/totalSS]
  64. %% Just to see means and sds
  65. testone= cat(1,accrot_cu_uncue{1,1}',accrot_cu_uncue{2,1}');
  66. testtwo= cat(1,accrot_cu_uncue{1,2}',accrot_cu_uncue{2,2}');
  67. itemone= cat(1,accrot_cu_uncue{1,1}',accrot_cu_uncue{1,2}');
  68. itemtwo= cat(1,accrot_cu_uncue{2,1}',accrot_cu_uncue{2,2}');
  69. mean(testone)
  70. std(testone)
  71. mean(testtwo)
  72. std(testtwo)
  73. mean(itemone)
  74. std(itemone)
  75. mean(itemtwo)
  76. std(itemtwo);
  77. %% Linear trend regarding distance
  78. %from closest to longest disntace
  79. distances(:,1)=all{1}(:,2) %stim 2 cued 1st
  80. distances(:,2)=all{1}(:,1) %stim 1 cued 1st
  81. distances(:,3)=all{1}(:,4)%stim 2 cued 2nd
  82. distances(:,4)=all{1}(:,3) %stim 1 cued 2nd
  83. %% Check linear trend
  84. ball=[];
  85. yfit = [];
  86. for ppp = 1:size(distances,1)
  87. tof=[];
  88. for c=1:size(distances,2);
  89. tof=[tof; distances(ppp,c)];
  90. end
  91. [b,dev,stats] = glmfit(1:size(distances,2),tof,'normal');
  92. yfit(ppp,:) = polyval([b(2,1),b(1,1)],[1,2,3,4]);
  93. ball(ppp) = b(2);
  94. end
  95. [h,p,ci,stats] = ttest(ball,0)
  96. [p,h,stats] = signrank(ball,0)
  97. %% Plotting accuracies + linear trends
  98. all{1}= distances;
  99. avg=nanmean(all{1},1);
  100. sem=std(all{1})/sqrt(size(all{1},1));
  101. figure;
  102. er=errorbar([],avg,sem,sem,'o');
  103. er.Color = [0 0 0];
  104. er.LineStyle = 'none';
  105. % ylim([0.475 0.8])
  106. xlim([0 5])
  107. line([0,5],[0.5 0.5], 'Color', 'k','LineStyle','--');hold on;
  108. xticks([1:4])
  109. xticklabels({'ori 2 1st test','ori 1 1st test','ori 2 2nd test','ori 1 2nd test'});
  110. hold on;
  111. plot(yfit')
  112. ylabel('accuracy')
  113. title(['General accuracy based on distance'])