DD_ConSAnalysisPh.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. %% load ANOVA data
  2. load('DD_ConSData')
  3. %% define some variables
  4. stPaPh = [1,4]; % define variables that should be included in post hoc analysis (depending on anova results and research question)
  5. %% concatenate relevant p-values in new array
  6. nStPa = numel(stPaPh); % number of statistical parameters included in post hoc analysis
  7. % preallocate
  8. pVUc = zeros(nStims,nFilt,nStPa,nRepRate,nConS-1); % preallocate
  9. pV = zeros(nStims,nFilt,(nStPa*nRepRate*(nConS-1))); % preallocate
  10. pVSort = zeros(nStims,nFilt,(nStPa*nRepRate*(nConS-1))); % preallocate
  11. pVOrd = zeros(nStims,nFilt,(nStPa*nRepRate*(nConS-1))); % preallocate
  12. for s = 1:nStims % for each stimulus
  13. for ft = 1:nFilt % for each filter
  14. for pa = 1:nStPa % for each statistical parameter
  15. switch pa
  16. case 1 % P2P
  17. w = 1; % analysis window
  18. case 2 % latency
  19. w = 2;
  20. end
  21. pVUc(s,ft,pa,:,:) = conSP(:,s,:,ft,w,stPaPh(pa));
  22. end
  23. pV(s,ft,:) = reshape(pVUc(s,ft,:,:,:),1,(nStPa*nRepRate*(nConS-1)));
  24. [pVSort(s,ft,:),pVOrd(s,ft,:)] = sort(pV(s,ft,:));
  25. end
  26. end
  27. %% perform post hoc correction
  28. % preallocate
  29. pVCoTemp = zeros(nStims,nFilt,2,(nStPa*nRepRate*(nConS-1)));
  30. pVCo = zeros(nStims,nFilt,2,nStPa,nRepRate,nConS-1);
  31. for s = 1:nStims % for each stimulus
  32. for ft = 1:nFilt % for each filter
  33. nP = numel(pVSort(s,ft,:));
  34. for ph = 1:2 % for each post hoc test
  35. switch ph
  36. case 1 % Holm-Bonferroni
  37. for n = 1:nP
  38. cf = nP-(n-1); % correction factor
  39. pVCoTemp(s,ft,ph,n) = pVSort(s,ft,n)*cf; % correct p values
  40. if n>1
  41. if pVCoTemp(s,ft,ph,n)<pVCoTemp(s,ft,ph,n-1)
  42. pVCoTemp(s,ft,ph,n) = pVCoTemp(s,ft,ph,n-1); % make sure that p-values never decrease with increasing rank
  43. end
  44. end
  45. end
  46. case 2 % Benjamini-Hochberg
  47. for n = nP:-1:1
  48. cf = nP/n; % correction factor
  49. pVCoTemp(s,ft,ph,n) = pVSort(s,ft,n)*cf; % correct p values
  50. % if n<nP
  51. % if pVCoTemp(s,ft,ph,n)>pVCoTemp(s,ft,ph,n+1)
  52. % pVCoTemp(s,ft,ph,n) = pVCoTemp(s,ft,ph,n+1); % make sure that p-values never increase with decreasing rank
  53. % end
  54. % end
  55. end
  56. end
  57. pVCoTemp(s,ft,ph,pVOrd(s,ft,:)) = pVCoTemp(s,ft,ph,:); % restore original order of p-values
  58. pVCo(s,ft,ph,:,:,:) = reshape(pVCoTemp(s,ft,ph,:),nStPa,nRepRate,(nConS-1)); % restore original organisation of uncorrected p-values
  59. end
  60. end
  61. end
  62. %% save data
  63. save('DD_ConSPhData','pVUc','pVCo','stPaPh')