Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

DD_2wayANOVA.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. %% define some variables
  2. clear
  3. % define time windows to be analysed (in s)
  4. % low
  5. win1L = [0.0027,0.0092]; % ABR (whole)
  6. % win2L = [0.005,0.009]; % ABR (peak 5 only)
  7. win2L = [0.005,0.0097]; % ABR (peak 5 only)
  8. % high
  9. win1H = [0.0027,0.0092]; % ABR (whole)
  10. % win2H = [0.0045,0.008]; % ABR (peak 5 only)
  11. win2H = [0.004,0.008]; % ABR (peak 5 only)
  12. % name time windows
  13. winTxt = ["ABR","Wave V"];
  14. %% load and concatenate data
  15. % load and rename variables
  16. load("DD_avData_Oddball_25ms_SbD.mat")
  17. dataAv_25 = dataAv_cell{1};
  18. pts2begin_25 = pts2begin_cell{1}(1);
  19. fs_25 = fs_cell{1}(1);
  20. load("DD_avData_Oddball_30ms_SbD.mat")
  21. dataAv_30 = dataAv_cell{1};
  22. pts2begin_30 = pts2begin_cell{1}(1);
  23. fs_30 = fs_cell{1}(1);
  24. load("DD_avData_Oddball_50ms_SbD.mat")
  25. dataAv_50 = dataAv_cell{1};
  26. pts2begin_50 = pts2begin_cell{1}(1);
  27. fs_50 = fs_cell{1}(1);
  28. % concatenate variables
  29. data = cat(1,dataAv_25,dataAv_30,dataAv_50);
  30. pts2begin = cat(1,pts2begin_25,pts2begin_30,pts2begin_50);
  31. fs = cat(1,fs_25,fs_30,fs_50);
  32. % define some variables
  33. nStims = 2;
  34. nRepRate = size(data,1);
  35. nProb = size(data,2)/nStims;
  36. nFilt = size(data{1},3);
  37. nFiles = size(data{1},2);
  38. %% do some additional calculations
  39. % preallocate
  40. winAll = cell(nRepRate,1);
  41. for r = 1:nRepRate
  42. winAll{r,1} = round([win1L;win2L]*fs(r))+pts2begin(r)+round(blcEnd(1)*fs(r)+1); % combine time windows, convert them into points and correct for stim delay (pts2begin) and baseline correction window (blcEnd = stimulus peak)
  43. winAll{r,2} = round([win1H;win2H]*fs(r))+pts2begin(r)+round(blcEnd(2)*fs(r)+1);
  44. end
  45. nWin = size(winAll{1},1); % number of windows per stimulus
  46. nStPa = 5; % number of statistical parameters
  47. %% calculate statistical parameters
  48. % preallocate
  49. stPa = zeros(nFiles,nRepRate,nStims,nProb,nFilt,nWin,nStPa);
  50. for r = 1:nRepRate % for each rep rate
  51. for s = 1:2 % for each stimulus (A and B)
  52. for pr = 1:nProb % for each probability (dev and std)
  53. for ft = 1:nFilt % for each filter
  54. for w = 1:nWin % for each window
  55. for p = 1:nStPa % for each stat param
  56. switch p
  57. case 1 % peak 2 peak
  58. stPa(:,r,s,pr,ft,w,p) = peak2peak(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft));
  59. case 2 % RMS
  60. stPa(:,r,s,pr,ft,w,p) = rms(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft));
  61. case 3 % AUC
  62. stPa(:,r,s,pr,ft,w,p) = trapz(abs(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft)));
  63. case {4,5} % peak latency & peak width
  64. pks = zeros(1,nFiles);
  65. loc = zeros(1,nFiles);
  66. wid = zeros(1,nFiles);
  67. for f = 1:nFiles
  68. [pksTemp,locTemp,widTemp,~] = findpeaks(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),f,ft));
  69. [maxV,maxI] = max(pksTemp);
  70. pks(f) = pksTemp(maxI);
  71. loc(f) = locTemp(maxI);
  72. wid(f) = widTemp(maxI);
  73. end
  74. switch p
  75. case 4
  76. stPa(:,r,s,pr,ft,w,p) = (loc+(winAll{r,s}(w,1)-pts2begin(r)-round(blcEnd(s)*fs(r)+1)))/fs(r)*1000; % convert points to time
  77. case 5
  78. stPa(:,r,s,pr,ft,w,p) = wid/fs(r)*1000; % convert points to time
  79. end
  80. end
  81. end
  82. end
  83. end
  84. end
  85. end
  86. end
  87. %% prepare variables for ANOVA
  88. % preallocate
  89. % stPaAno = zeros((nFiles*nRepRate*nProb),nStims,nFilt,nWin,nStPa);
  90. stPaAno = zeros((nFiles*nRepRate),nProb,nStims,nFilt,nWin,nStPa);
  91. count = 0;
  92. for r = 1:nRepRate % for each rep rate
  93. count = count+1;
  94. for pr = 1:nProb % for each probability (dev and std)
  95. for s = 1:nStims % for each stimulus
  96. for ft = 1:nFilt % for each filter
  97. for w = 1:nWin % for each window
  98. for p = 1:nStPa % for each stat param
  99. stPaAno((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,pr,s,ft,w,p) = stPa(:,r,s,pr,ft,w,p); % reorganise stPa to have all conditions that should be tested in anova in one dimension
  100. end
  101. end
  102. end
  103. end
  104. end
  105. end
  106. %% run ANOVA & post hoc multiple comparison test
  107. % preallocate
  108. anoP = cell(nStims,nFilt,nWin,nStPa);
  109. anoTbl = cell(nStims,nFilt,nWin,nStPa);
  110. anoStats = cell(nStims,nFilt,nWin,nStPa);
  111. mcoC = cell(nStims,nFilt,nWin,nStPa);
  112. mcoM = cell(nStims,nFilt,nWin,nStPa);
  113. mcoH = cell(nStims,nFilt,nWin,nStPa);
  114. mcoGnames = cell(nStims,nFilt,nWin,nStPa);
  115. mcoTbl = cell(nStims,nFilt,nWin,nStPa);
  116. for s = 1:nStims % for each stimulus
  117. for ft = 1:nFilt % for each filter
  118. for w = 1:nWin % for each window
  119. for p = 1:nStPa % for each stat param
  120. y = stPaAno(:,:,s,ft,w,p); % data to be tested
  121. reps = nFiles;
  122. [anoP{s,ft,w,p},anoTbl{s,ft,w,p},anoStats{s,ft,w,p}] = anova2(y,reps,'off');
  123. [mcoC{s,ft,w,p},mcoM{s,ft,w,p},mcoH{s,ft,w,p},mcoGnames{s,ft,w,p}] = multcompare(anoStats{s,ft,w,p},"CriticalValueType","bonferroni",'display','off');
  124. mcoTbl{s,ft,w,p} = array2table(mcoC{s,ft,w,p},"VariableNames",["Group A","Group B","Lower Limit","AtoB","Upper Limit","Pvalue"]);
  125. end
  126. end
  127. end
  128. end
  129. bla = 1;