DD_Stats.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. %% define some variables
  2. % define time windows to be analysed (in s); ATTENTION: compared to
  3. % previous paper, all values are -0.4 ms, since now a correction for sound
  4. % travelling delay has been performed (as opposed to before)
  5. % Eloc
  6. win1 = [0,0.001]; % ABR (i)
  7. win2 = [0.001,0.0022]; % ABR (ii/iii)
  8. win3 = [0.0022,0.0034]; % ABR (iv)
  9. win4 = [0,0.01]; % ABR (whole)
  10. win5 = [0.01,0.02]; % ABR (late)
  11. % DisNoAM
  12. win6 = [0,0.0013]; % ABR (i)
  13. win7 = [0.0013,0.0025]; % ABR (ii/iii)
  14. win8 = [0.0025,0.0041]; % ABR (iv)
  15. win9 = [0,0.01]; % ABR (whole)
  16. win10 = [0.01,0.024]; % ABR (late)
  17. winTxt = ["i","ii/iii","iv","ABR (whole)","ABR (late)"];
  18. inclCtrl = 3; % include control data? (0: no, 1: 50 %, 2: MR, 3: both controls)
  19. %% load datasets
  20. switch inclCtrl
  21. case {1,2} % load 50Per data and rename important variables
  22. switch inclCtrl
  23. case 1
  24. load('DD_avData_50Per.mat')
  25. case 2
  26. load('DD_avData_MR.mat')
  27. end
  28. dataAv_cell_ctrl = dataAv_cell; % rename
  29. fileI_Oddb_cell_ctrl = fileI_Oddb_cell; % rename
  30. fileI_Ctrl_cell_ctrl = fileI_Ctrl_cell; % rename
  31. dataTt_cell_ctrl = dataTt_cell; % rename
  32. case 3
  33. load('DD_avData_50Per.mat')
  34. dataAv_cell_50Per = dataAv_cell; % rename
  35. fileI_Oddb_cell_50Per = fileI_Oddb_cell; % rename
  36. fileI_Ctrl_cell_50Per = fileI_Ctrl_cell; % rename
  37. load('DD_avData_MR.mat')
  38. dataAv_cell_MR = dataAv_cell; % rename
  39. fileI_Oddb_cell_MR = fileI_Oddb_cell; % rename
  40. fileI_Ctrl_cell_MR = fileI_Ctrl_cell; % rename
  41. end
  42. % load oddball data
  43. load('DD_avData_Oddball.mat')
  44. %% do some additional calulations that are required
  45. fs = fsDwn_cell{1}(1);
  46. pts2begin = pts2begin_cell{1}(1);
  47. winAll = round([win1;win2;win3;win4;win5;win6;win7;win8;win9;win10]*fs); % combine time windows and convert them into points
  48. winAll = winAll+pts2begin; % correct for stim delay
  49. nWin = size(winAll,1);
  50. nStims = 2; % number of different stimuli per combination
  51. nFilt = nFilt_cell{1};
  52. switch inclCtrl % number of different stimulus condition (depends on whether MR is included or not)
  53. case 0
  54. filename = 'DD_statsData_noCtrl';
  55. nCond = 2; % 2 conditions: dev and std
  56. dataAv = dataAv_cell; % only oddball data
  57. case {1,2}
  58. switch inclCtrl
  59. case 1
  60. filename = 'DD_statsData_50Per';
  61. case 2
  62. filename = 'DD_statsData_MR';
  63. end
  64. nCond = 3; % 3 conditions: dev, std and control
  65. dataAv = cell(size(dataAv_cell)); % preallocate
  66. for c = 1:nComb % once for each stimulus combination
  67. for s = 1:nStims % once for each stimulus frequency
  68. for cn = 1:nCond % once for each stimulus condition (dev, std, ctrl)
  69. switch cn % change dataset depending on condition (Oddball vs. control)
  70. case {1,2} % if oddball
  71. dataAv{c}{(s-1)*nCond+cn} = dataAv_cell{c}{(s-1)*2+cn}; % concatenate oddball data of respective stimulus & condition (dev/std)
  72. case 3 % if control
  73. dataAv{c}{(s-1)*nCond+cn} = dataAv_cell_ctrl{c}{s}; % concatenate control data of respective stimulus
  74. end
  75. end
  76. end
  77. end
  78. case 3
  79. filename = 'DD_statsData_bothCtrl';
  80. nCond = 4; % 4 conditions: dev, std, 50Per and MR
  81. dataAv = cell(size(dataAv_cell)); % preallocate
  82. for c = 1:nComb % once for each stimulus combination
  83. for s = 1:nStims % once for each stimulus frequency
  84. for cn = 1:nCond % once for each stimulus condition (dev, std, ctrl)
  85. switch cn % change dataset depending on condition (Oddball vs. control)
  86. case {1,2} % if oddball
  87. dataAv{c}{(s-1)*nCond+cn} = dataAv_cell{c}{(s-1)*2+cn}; % concatenate oddball data of respective stimulus & condition (dev/std)
  88. case 3 % if control
  89. dataAv{c}{(s-1)*nCond+cn} = dataAv_cell_50Per{c}{s}; % concatenate control data of respective stimulus
  90. case 4
  91. dataAv{c}{(s-1)*nCond+cn} = dataAv_cell_MR{c}{s}; % concatenate control data of respective stimulus
  92. end
  93. end
  94. end
  95. end
  96. end
  97. %% calulate RMS values within defined time windows
  98. rmsV = cell(1,nComb); % preallocate
  99. rmsGrAv = cell(1,nComb); % preallocate
  100. for c = 1:nComb % once for each stimulus combination
  101. nFiles = nFiles_cell{c};
  102. rmsV{c} = zeros(nFiles,nStims,nCond,nFilt,nWin); % preallocate
  103. for s = 1:nStims % once for each stimulus frequency
  104. for cn = 1:nCond % once for each stimulus condition (dev, std, ctrl)
  105. for ft = 1:nFilt % once for each filter
  106. for w = 1:nWin % once for each time window
  107. rmsV{c}(:,s,cn,ft,w) = rms(dataAv{c}{(s-1)*nCond+cn}(winAll(w,1):winAll(w,2),:,ft)); % calculate rms
  108. rmsGrAv{c}(s,cn,ft,w) = mean(rmsV{c}(:,s,cn,ft,w),1); % grand average of RMS data
  109. end
  110. end
  111. end
  112. end
  113. end
  114. %% run t-test or ANOVA on each time window
  115. cohensD_V = zeros(nComb,nStims,nFilt,nWin,3); % preallocate
  116. hV = zeros(nComb,nStims,nFilt,nWin); % preallocate
  117. pV = zeros(nComb,nStims,nFilt,nWin); % preallocate
  118. ciV = zeros(nComb,nStims,nFilt,nWin,2); % preallocate
  119. statsV = cell(nComb,nStims,nFilt,nWin); % preallocate
  120. switch inclCtrl
  121. case {1,2}
  122. anovaV = cell(nComb,nStims,nFilt,nWin); % preallocate
  123. multcompV = cell(nComb,nStims,nFilt,nWin); % preallocate
  124. within = table([1,2,3]','VariableNames',{'stim_prob'}); % define within model
  125. case 3
  126. cohensD_V = zeros(nComb,nStims,nFilt,nWin,6); % preallocate
  127. anovaV = cell(nComb,nStims,nFilt,nWin); % preallocate
  128. multcompV = cell(nComb,nStims,nFilt,nWin); % preallocate
  129. within = table([1,2,3,4]','VariableNames',{'stim_prob'}); % define within model
  130. end
  131. for c = 1:nComb % once for each stimulus combination
  132. for s = 1:nStims % once for each stimulus frequency
  133. for ft = 1:nFilt % once for each filter
  134. for w = 1:nWin % once for each time window
  135. cohensD_V(c,s,ft,w,1) = CohensD(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,2,ft,w)); % calculate Cohens D; dev vs. std
  136. [hV(c,s,ft,w),pV(c,s,ft,w),ciV(c,s,ft,w,:),statsV{c,s,ft,w}] = ttest(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,2,ft,w)); % run t-test
  137. switch inclCtrl
  138. case {1,2} % with control data
  139. t = table(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,2,ft,w),rmsV{c}(:,s,3,ft,w),'VariableNames',{'dev','std','ctrl'}); % required for ANOVA
  140. rm = fitrm(t,'dev-ctrl~1','WithinDesign',within); % required for ANOVA
  141. anovaV{c,s,ft,w} = ranova(rm); % run ANOVA
  142. multcompV{c,s,ft,w} = multcompare(rm,'stim_prob','ComparisonType','bonferroni'); % run multiple comparison to find differences between responses
  143. cohensD_V(c,s,ft,w,2) = CohensD(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,3,ft,w)); % calculate Cohens D; dev vs. ctrl
  144. cohensD_V(c,s,ft,w,3) = CohensD(rmsV{c}(:,s,3,ft,w),rmsV{c}(:,s,2,ft,w)); % ctrl vs. std
  145. case 3
  146. t = table(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,2,ft,w),rmsV{c}(:,s,3,ft,w),rmsV{c}(:,s,4,ft,w),'VariableNames',{'dev','std','50Per','MR'}); % required for ANOVA
  147. rm = fitrm(t,'dev-MR~1','WithinDesign',within); % required for ANOVA
  148. anovaV{c,s,ft,w} = ranova(rm); % run ANOVA
  149. multcompV{c,s,ft,w} = multcompare(rm,'stim_prob','ComparisonType','bonferroni'); % run multiple comparison to find differences between responses
  150. cohensD_V(c,s,ft,w,2) = CohensD(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,3,ft,w)); % calculate Cohens D; dev vs. 50Per
  151. cohensD_V(c,s,ft,w,3) = CohensD(rmsV{c}(:,s,1,ft,w),rmsV{c}(:,s,4,ft,w)); % calculate Cohens D; dev vs. MR
  152. cohensD_V(c,s,ft,w,4) = CohensD(rmsV{c}(:,s,3,ft,w),rmsV{c}(:,s,2,ft,w)); % 50Per vs. std
  153. cohensD_V(c,s,ft,w,5) = CohensD(rmsV{c}(:,s,4,ft,w),rmsV{c}(:,s,2,ft,w)); % MR vs. std
  154. cohensD_V(c,s,ft,w,6) = CohensD(rmsV{c}(:,s,4,ft,w),rmsV{c}(:,s,3,ft,w)); % MR vs. 50Per
  155. end
  156. end
  157. end
  158. end
  159. end
  160. %% save data
  161. switch inclCtrl
  162. case 0
  163. save(filename,'winAll','winTxt','rmsV','rmsGrAv','hV','pV','ciV','statsV','cohensD_V')
  164. case {1,2,3}
  165. save(filename,'winAll','winTxt','rmsV','rmsGrAv','hV','pV','ciV','statsV','anovaV','multcompV','cohensD_V')
  166. end