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_2wayANOVAn.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.0027,0.0092]; % ABR (peak 5 only)
  7. win2L = [0.005,0.0092]; % ABR (peak 5 only)
  8. % high
  9. % win1H = [0,0.0092]; % ABR (whole)
  10. % win2H = [0.004,0.0092]; % ABR (peak 5 only)
  11. win1H = [0.0027,0.0092]; % ABR (whole)
  12. win2H = [0.005,0.0092]; % ABR (peak 5 only)
  13. % name time windows
  14. winTxt = ["ABR","Wave V"];
  15. %% load and concatenate data
  16. % load and rename variables
  17. load("DD_avData_Oddball_25ms_SbD.mat")
  18. dataAv_25 = dataAv_cell{1};
  19. pts2begin_25 = pts2begin_cell{1}(1);
  20. fs_25 = fs_cell{1}(1);
  21. load("DD_avData_Oddball_30ms_SbD.mat")
  22. dataAv_30 = dataAv_cell{1};
  23. pts2begin_30 = pts2begin_cell{1}(1);
  24. fs_30 = fs_cell{1}(1);
  25. load("DD_avData_Oddball_50ms_SbD.mat")
  26. dataAv_50 = dataAv_cell{1};
  27. pts2begin_50 = pts2begin_cell{1}(1);
  28. fs_50 = fs_cell{1}(1);
  29. % concatenate variables
  30. data = cat(1,dataAv_25,dataAv_30,dataAv_50);
  31. pts2begin = cat(1,pts2begin_25,pts2begin_30,pts2begin_50);
  32. fs = cat(1,fs_25,fs_30,fs_50);
  33. % define some variables
  34. nStims = 2;
  35. nRepRate = size(data,1);
  36. nProb = size(data,2)/nStims;
  37. nFilt = size(data{1},3);
  38. nFiles = size(data{1},2);
  39. %% do some additional calculations
  40. % preallocate
  41. winAll = cell(nRepRate,1);
  42. for r = 1:nRepRate
  43. 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)
  44. winAll{r,2} = round([win1H;win2H]*fs(r))+pts2begin(r)+round(blcEnd(2)*fs(r)+1);
  45. end
  46. nWin = size(winAll{1},1); % number of windows per stimulus
  47. nStPa = 5; % number of statistical parameters
  48. %% calculate statistical parameters
  49. % preallocate
  50. stPa = zeros(nFiles,nRepRate,nStims,nProb,nFilt,nWin,nStPa);
  51. for r = 1:nRepRate % for each rep rate
  52. for s = 1:nStims % for each stimulus (A and B)
  53. for pr = 1:nProb % for each probability (dev and std)
  54. for ft = 1:nFilt % for each filter
  55. for w = 1:nWin % for each window
  56. for pa = 1:nStPa % for each stat param
  57. switch pa
  58. case 1 % peak 2 peak
  59. stPa(:,r,s,pr,ft,w,pa) = peak2peak(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft));
  60. case 2 % RMS
  61. stPa(:,r,s,pr,ft,w,pa) = rms(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft));
  62. case 3 % AUC
  63. stPa(:,r,s,pr,ft,w,pa) = trapz(abs(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),:,ft)));
  64. case {4,5} % peak latency & peak width
  65. pks = zeros(1,nFiles);
  66. loc = zeros(1,nFiles);
  67. wid = zeros(1,nFiles);
  68. for f = 1:nFiles
  69. [pksTemp,locTemp,widTemp,~] = findpeaks(data{r,(s-1)*nProb+pr}(winAll{r,s}(w,1):winAll{r,s}(w,2),f,ft),"WidthReference",'halfprom');
  70. [maxV,maxI] = max(pksTemp);
  71. pks(f) = pksTemp(maxI);
  72. loc(f) = locTemp(maxI);
  73. wid(f) = widTemp(maxI);
  74. end
  75. switch pa
  76. case 4
  77. stPa(:,r,s,pr,ft,w,pa) = (loc+(winAll{r,s}(w,1)-pts2begin(r)-round(blcEnd(s)*fs(r)+1)))/fs(r)*1000; % convert points to time
  78. case 5
  79. stPa(:,r,s,pr,ft,w,pa) = wid/fs(r)*1000; % convert points to time
  80. end
  81. end
  82. end
  83. end
  84. end
  85. end
  86. end
  87. end
  88. %% prepare variables for ANOVA
  89. % preallocate
  90. stPaAno = zeros((nFiles*nRepRate*nProb),nStims,nFilt,nWin,nStPa);
  91. faProb = strings((nFiles*nRepRate*nProb),nStims,nFilt,nWin,nStPa);
  92. faRepRate = strings((nFiles*nRepRate*nProb),nStims,nFilt,nWin,nStPa);
  93. count = 0;
  94. for r = 1:nRepRate % for each rep rate
  95. switch r
  96. case 1
  97. RepRateName = "25ms";
  98. case 2
  99. RepRateName = "30ms";
  100. case 3
  101. RepRateName = "50ms";
  102. end
  103. for pr = 1:nProb % for each probability (dev and std)
  104. switch pr
  105. case 1
  106. probName = "Dev";
  107. case 2
  108. probName = "Std";
  109. end
  110. count = count+1;
  111. for s = 1:nStims % for each stimulus
  112. for ft = 1:nFilt % for each filter
  113. for w = 1:nWin % for each window
  114. for pa = 1:nStPa % for each stat param
  115. stPaAno((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,pa) = stPa(:,r,s,pr,ft,w,pa); % reorganise stPa to have all conditions that should be tested in anova in one dimension
  116. % create factors for anova
  117. faProb((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,pa) = probName;
  118. faRepRate((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,pa) = RepRateName;
  119. end
  120. end
  121. end
  122. end
  123. end
  124. end
  125. %% run ANOVA & multiple comparison test (without correction)
  126. % preallocate
  127. anoP = cell(nStims,nFilt,nWin,nStPa);
  128. anoTbl = cell(nStims,nFilt,nWin,nStPa);
  129. anoStats = cell(nStims,nFilt,nWin,nStPa);
  130. anoTerms = cell(nStims,nFilt,nWin,nStPa);
  131. mcoC = cell(nStims,nFilt,nWin,nStPa);
  132. mcoM = cell(nStims,nFilt,nWin,nStPa);
  133. mcoH = cell(nStims,nFilt,nWin,nStPa);
  134. mcoGnames = cell(nStims,nFilt,nWin,nStPa);
  135. mcoTbl = cell(nStims,nFilt,nWin,nStPa);
  136. for s = 1:nStims % for each stimulus
  137. for ft = 1:nFilt % for each filter
  138. for w = 1:nWin % for each window
  139. for pa = 1:nStPa % for each stat param
  140. y = stPaAno(:,s,ft,w,pa); % data to be tested
  141. group = {faProb(:,s,ft,w,pa),faRepRate(:,s,ft,w,pa)}; % combine factors in group variable
  142. [anoP{s,ft,w,pa},anoTbl{s,ft,w,pa},anoStats{s,ft,w,pa},anoTerms{s,ft,w,pa}] = anovan(y,group,'model','interaction','varnames',{'faProb','faRepRate'},'display','off');
  143. [mcoC{s,ft,w,pa},mcoM{s,ft,w,pa},mcoH{s,ft,w,pa},mcoGnames{s,ft,w,pa}] = multcompare(anoStats{s,ft,w,pa},'Dimension',[1,2],"CriticalValueType","lsd",'display','off');
  144. mcoTbl{s,ft,w,pa} = array2table(mcoC{s,ft,w,pa},"VariableNames",["Group A","Group B","Lower Limit","AtoB","Upper Limit","Pvalue"]);
  145. mcoTbl{s,ft,w,pa}.("Group A") = mcoGnames{s,ft,w,pa}(mcoTbl{s,ft,w,pa}.("Group A"));
  146. mcoTbl{s,ft,w,pa}.("Group B") = mcoGnames{s,ft,w,pa}(mcoTbl{s,ft,w,pa}.("Group B"));
  147. end
  148. end
  149. end
  150. end
  151. %% calculate paird t-tests and effect size
  152. % preallocate
  153. effS = zeros(nRepRate,nStims,nFilt,nWin,nStPa);
  154. h = zeros(nRepRate,nStims,nFilt,nWin,nStPa);
  155. p = zeros(nRepRate,nStims,nFilt,nWin,nStPa);
  156. ci = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  157. stats = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  158. for r = 1:nRepRate
  159. for s = 1:nStims % for each stimulus
  160. for ft = 1:nFilt % for each filter
  161. for w = 1:nWin % for each window
  162. for pa = 1:nStPa % for each stat param
  163. [h(r,s,ft,w,pa),p(r,s,ft,w,pa),ci{r,s,ft,w,pa},stats{r,s,ft,w,pa}] = ttest(stPa(:,r,s,1,ft,w,pa),stPa(:,r,s,2,ft,w,pa)); % run t-test
  164. effS(r,s,ft,w,pa) = meanEffectSize(stPa(:,r,s,1,ft,w,pa),stPa(:,r,s,2,ft,w,pa),'Effect','cohen').Effect; % calculate effect size; dev vs. std
  165. end
  166. end
  167. end
  168. end
  169. end
  170. %% save data
  171. save('DD_2WanovanData','stPa','stPaAno','faProb','faRepRate','anoP',...
  172. 'anoTbl','anoStats','anoTerms','mcoC','mcoM','mcoH','mcoGnames',...
  173. 'mcoTbl','nRepRate','nStims','nProb','nFilt','nWin','nStPa','effS',...
  174. 'h','p','ci','stats','combName','winAll')