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_ConSAnalysis.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. %% define some variables
  2. clear
  3. % general parameters
  4. fitI = 0; % should curve be fitted to datapoints?
  5. % define time windows to be analysed (in s)
  6. % low
  7. win1L = [0.0027,0.0092]; % ABR (whole)
  8. win2L = [0.005,0.0092]; % ABR (peak 5 only)
  9. % high
  10. win1H = [0.0027,0.0092]; % ABR (whole)
  11. win2H = [0.004,0.008]; % ABR (peak 5 only)
  12. % name time windows
  13. winTxt = ["ABR","Wave V"];
  14. % curve fitting parameters
  15. % fitTy = fittype('poly2'); % define model
  16. fitTy = fittype('V*exp(-t/tau)+b','independent','t'); % model for exponential decay
  17. %% load and concatenate data
  18. % load and rename variables
  19. load("DD_avData_Oddball_25ms_SbD.mat")
  20. dataAv_25 = conSAv;
  21. se_25 = conSSe;
  22. pts2begin_25 = pts2begin_cell{1}(1);
  23. fs_25 = fs_cell{1}(1);
  24. pSmpl_25 = pSmpl;
  25. stimDel_25 = stimDelay_cell{1}(1);
  26. load("DD_avData_Oddball_30ms_SbD.mat")
  27. dataAv_30 = conSAv;
  28. se_30 = conSSe;
  29. pts2begin_30 = pts2begin_cell{1}(1);
  30. fs_30 = fs_cell{1}(1);
  31. pSmpl_30 = pSmpl;
  32. stimDel_30 = stimDelay_cell{1}(1);
  33. load("DD_avData_Oddball_50ms_SbD.mat")
  34. dataAv_50 = conSAv;
  35. se_50 = conSSe;
  36. pts2begin_50 = pts2begin_cell{1}(1);
  37. fs_50 = fs_cell{1}(1);
  38. pSmpl_50 = pSmpl;
  39. stimDel_50 = stimDelay_cell{1}(1);
  40. % concatenate variables
  41. data = cat(1,dataAv_25,dataAv_30,dataAv_50);
  42. se = cat(1,se_25,se_30,se_50);
  43. pts2begin = cat(1,pts2begin_25,pts2begin_30,pts2begin_50);
  44. fs = cat(1,fs_25,fs_30,fs_50);
  45. pSmpl = cat(1,pSmpl_25,pSmpl_30,pSmpl_50);
  46. stimDel = cat(1,stimDel_25,stimDel_30,stimDel_50);
  47. % calculate some variables
  48. nStims = 2;
  49. nRepRate = size(data,1);
  50. nFilt = size(data{1},5);
  51. nFiles = size(data{1},3);
  52. if devConSI==1
  53. nConS = nConS+1;
  54. end
  55. %% do some additional calculations
  56. % preallocate
  57. winAll = cell(nRepRate,1);
  58. for r = 1:nRepRate
  59. 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)
  60. winAll{r,2} = round([win1H;win2H]*fs(r))+pts2begin(r)+round(blcEnd(2)*fs(r)+1);
  61. end
  62. nWin = size(winAll{1},1); % number of windows per stimulus
  63. nStPa = 5; % number of statistical parameters
  64. %% calculate statistical parameters
  65. % preallocate
  66. stPa = zeros(nFiles,nRepRate,nStims,nConS,nFilt,nWin,nStPa);
  67. for r = 1:nRepRate % for each rep rate
  68. for s = 1:nStims % for each stimulus (A and B)
  69. for cs = 1:nConS
  70. for ft = 1:nFilt % for each filter
  71. for w = 1:nWin % for each window
  72. for p = 1:nStPa % for each stat param
  73. switch p
  74. case 1 % peak 2 peak
  75. stPa(:,r,s,cs,ft,w,p) = peak2peak(data{r}(winAll{r,s}(w,1):winAll{r,s}(w,2),s,:,cs,ft));
  76. case 2 % RMS
  77. stPa(:,r,s,cs,ft,w,p) = rms(data{r}(winAll{r,s}(w,1):winAll{r,s}(w,2),s,:,cs,ft));
  78. case 3 % AUC
  79. stPa(:,r,s,cs,ft,w,p) = trapz(abs(data{r}(winAll{r,s}(w,1):winAll{r,s}(w,2),s,:,cs,ft)));
  80. case {4,5} % peak latency & peak width
  81. pks = zeros(1,nFiles);
  82. loc = zeros(1,nFiles);
  83. wid = zeros(1,nFiles);
  84. for f = 1:nFiles
  85. [pksTemp,locTemp,widTemp,~] = findpeaks(data{r}(winAll{r,s}(w,1):winAll{r,s}(w,2),s,f,cs,ft),"WidthReference",'halfprom');
  86. % if r==1&&s==1&&cs==4&&ft==2&&w==1&&p==4
  87. % figure; findpeaks(data{r}(winAll{r,s}(w,1):winAll{r,s}(w,2),s,f,cs,ft),"WidthReference",'halfprom')
  88. % end
  89. [maxV,maxI] = max(pksTemp);
  90. pks(f) = pksTemp(maxI);
  91. loc(f) = locTemp(maxI);
  92. wid(f) = widTemp(maxI);
  93. end
  94. switch p
  95. case 4
  96. stPa(:,r,s,cs,ft,w,p) = (loc+(winAll{r,s}(w,1)-pts2begin(r)-round(blcEnd(s)*fs(r)+1)))/fs(r)*1000; % convert points to time
  97. case 5
  98. stPa(:,r,s,cs,ft,w,p) = wid/fs(r)*1000; % convert points to time
  99. end
  100. end
  101. end
  102. end
  103. end
  104. end
  105. end
  106. end
  107. %% test plotting
  108. % A = mean(stPa,1);
  109. % B = reshape(A(1,3,1,:,3,2,4),1,nConS);
  110. % figure; plot(B,'o','Linewidth',2,'Color','k')
  111. %% fit curve to data
  112. % preallocate
  113. ci1st = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  114. flexFit = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  115. flexGof = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  116. linFit = cell(nRepRate,nStims,nFilt,nWin,nStPa);
  117. if fitI==1
  118. x = (1:nConS)';
  119. for r = 1:nRepRate % for each rep rate
  120. for s = 1:nStims % for each stimulus (A and B)
  121. for cs = 1:nConS % for each standard in the cluster
  122. for ft = 1:nFilt % for each filter
  123. for w = 1:nWin % for each window
  124. for p = 1:nStPa % for each stat param
  125. pd = fitdist(stPa(:,r,s,1,ft,w,p),'Normal'); % Fit a normal distribution object to the data of the first response
  126. ci1st{r,s,ft,w,p} = paramci(pd); % calculate confidence intervals for the data of the first response
  127. y = reshape(mean(stPa(:,r,s,:,ft,w,p),1),nConS,1); % prepare data for curve fitting
  128. [flexFit{r,s,ft,w,p},flexGof{r,s,ft,w,p}] = fit(x,y,fitTy,'StartPoint',[1,1,1],'Upper',[10000,10000,10000],'Lower',[0,0,0]); % fit model to data (fexible model)
  129. linFit{r,s,ft,w,p} = fitlm(x,y); % fit model to data (linear regression model)
  130. end
  131. end
  132. end
  133. end
  134. end
  135. end
  136. end
  137. %% prepare variables for ANOVA
  138. % preallocate
  139. stPaAno = zeros((nFiles*nRepRate*nConS),nStims,nFilt,nWin,nStPa);
  140. faRole = strings((nFiles*nRepRate*nConS),nStims,nFilt,nWin,nStPa);
  141. faRepRate = strings((nFiles*nRepRate*nConS),nStims,nFilt,nWin,nStPa);
  142. count = 0;
  143. for r = 1:nRepRate % for each rep rate
  144. switch r
  145. case 1
  146. RepRateName = "25ms";
  147. case 2
  148. RepRateName = "30ms";
  149. case 3
  150. RepRateName = "50ms";
  151. end
  152. for ro = 1:nConS % for each role (dev, std1, std2, std3)
  153. switch ro
  154. case 1
  155. roleName = "Dev";
  156. case 2
  157. roleName = "Std1";
  158. case 3
  159. roleName = "Std2";
  160. case 4
  161. roleName = "Std3";
  162. end
  163. count = count+1;
  164. for s = 1:nStims % for each stimulus
  165. for ft = 1:nFilt % for each filter
  166. for w = 1:nWin % for each window
  167. for p = 1:nStPa % for each stat param
  168. stPaAno((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,p) = stPa(:,r,s,ro,ft,w,p); % reorganise stPa to have all conditions that should be tested in anova in one dimension
  169. % create factors for anova
  170. faRole((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,p) = roleName;
  171. faRepRate((nFiles*(count-1))+1:(nFiles*(count-1))+nFiles,s,ft,w,p) = RepRateName;
  172. end
  173. end
  174. end
  175. end
  176. end
  177. end
  178. %% run ANOVA & multiple comparison test (without correction)
  179. % preallocate
  180. anoP = cell(nStims,nFilt,nWin,nStPa);
  181. anoTbl = cell(nStims,nFilt,nWin,nStPa);
  182. anoStats = cell(nStims,nFilt,nWin,nStPa);
  183. anoTerms = cell(nStims,nFilt,nWin,nStPa);
  184. mcoC = cell(nStims,nFilt,nWin,nStPa);
  185. mcoM = cell(nStims,nFilt,nWin,nStPa);
  186. mcoH = cell(nStims,nFilt,nWin,nStPa);
  187. mcoGnames = cell(nStims,nFilt,nWin,nStPa);
  188. mcoTbl = cell(nStims,nFilt,nWin,nStPa);
  189. for s = 1:nStims % for each stimulus
  190. for ft = 1:nFilt % for each filter
  191. for w = 1:nWin % for each window
  192. for p = 1:nStPa % for each stat param
  193. y = stPaAno(:,s,ft,w,p); % data to be tested
  194. group = {faRole(:,s,ft,w,p),faRepRate(:,s,ft,w,p)}; % combine factors in group variable
  195. [anoP{s,ft,w,p},anoTbl{s,ft,w,p},anoStats{s,ft,w,p},anoTerms{s,ft,w,p}] = anovan(y,group,'model','interaction','varnames',{'faRole','faRepRate'},'display','off');
  196. [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},'Dimension',[1,2],"CriticalValueType","lsd",'display','off');
  197. mcoTbl{s,ft,w,p} = array2table(mcoC{s,ft,w,p},"VariableNames",["Group A","Group B","Lower Limit","AtoB","Upper Limit","Pvalue"]); % not used. Paird t-tests are used instead (because data is paired for relevant post hoc comparisons)
  198. mcoTbl{s,ft,w,p}.("Group A") = mcoGnames{s,ft,w,p}(mcoTbl{s,ft,w,p}.("Group A"));
  199. mcoTbl{s,ft,w,p}.("Group B") = mcoGnames{s,ft,w,p}(mcoTbl{s,ft,w,p}.("Group B"));
  200. end
  201. end
  202. end
  203. end
  204. %% compare all responses to the first one with t-test
  205. % preallocate
  206. conSH = zeros(nRepRate,nStims,nConS-1,nFilt,nWin,nStPa);
  207. conSP = zeros(nRepRate,nStims,nConS-1,nFilt,nWin,nStPa);
  208. conSCi = cell(nRepRate,nStims,nConS-1,nFilt,nWin,nStPa);
  209. conSStats = cell(nRepRate,nStims,nConS-1,nFilt,nWin,nStPa);
  210. conSEffS = zeros(nRepRate,nStims,nConS-1,nFilt,nWin,nStPa);
  211. for r = 1:nRepRate % for each rep rate
  212. for s = 1:nStims % for each stimulus (A and B)
  213. for cs = 2:nConS % for each standard in the cluster (except for the first)
  214. for ft = 1:nFilt % for each filter
  215. for w = 1:nWin % for each window
  216. for p = 1:nStPa % for each stat param
  217. [conSH(r,s,cs-1,ft,w,p),conSP(r,s,cs-1,ft,w,p),conSCi{r,s,cs-1,ft,w,p},conSStats{r,s,cs-1,ft,w,p}] = ttest(stPa(:,r,s,1,ft,w,p),stPa(:,r,s,cs,ft,w,p)); % run t-test
  218. conSEffS(r,s,cs-1,ft,w,p) = meanEffectSize(stPa(:,r,s,1,ft,w,p),stPa(:,r,s,cs,ft,w,p),'Effect','cohen').Effect; % calculate effect size; dev vs. std
  219. end
  220. end
  221. end
  222. end
  223. end
  224. end
  225. %% save data
  226. save('DD_ConSData','fitTy','stPa','ci1st','flexFit','flexGof','linFit',...
  227. 'pts2begin','fs','pSmpl','stimDel','nStims','nRepRate','nFilt','nFiles','nConS',...
  228. 'nWin','nStPa','winAll','conSH','conSP','conSCi','conSStats',...
  229. 'conSEffS','combName','data','se','blcEnd','anoTbl','mcoTbl')