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.

e2_taskPLS_memory_erf_LV1.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. % Create an overview plot featuring the results of the multivariate PLS
  2. % comparing spectral changes during the stimulus period under load
  3. clear all; cla; clc;
  4. currentFile = mfilename('fullpath');
  5. [pathstr,~,~] = fileparts(currentFile);
  6. cd(fullfile(pathstr,'..'))
  7. rootpath = pwd;
  8. pn.data = fullfile(rootpath, 'data', 'stats');
  9. pn.figures = fullfile(rootpath, 'figures');
  10. pn.tools = fullfile(rootpath, 'tools');
  11. addpath(genpath(fullfile(pn.tools, '[MEG]PLS', 'MEGPLS_PIPELINE_v2.02b')))
  12. addpath(fullfile(pn.tools, 'fieldtrip')); ft_defaults;
  13. addpath(genpath(fullfile(pn.tools, 'RainCloudPlots')));
  14. addpath(fullfile(pn.tools, 'BrewerMap'));
  15. addpath(fullfile(pn.tools, 'winsor'));
  16. % set custom colormap
  17. cBrew = brewermap(500,'RdBu');
  18. cBrew = flipud(cBrew);
  19. colormap(cBrew)
  20. load(fullfile(pn.data, 'e2_taskpls_erf.mat'),...
  21. 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time')
  22. load(fullfile(rootpath, 'data','erp', ['sub-001_erp.mat']));
  23. elec = erp.scene_category{1}.elec;
  24. result.perm_result.sprob
  25. indLV = 1;
  26. lvdat = reshape(result.boot_result.compare_u(:,indLV), num_chans, num_freqs, num_time);
  27. stat.prob = lvdat;
  28. stat.mask = lvdat > 3 | lvdat < -3;
  29. maskNaN = double(stat.mask);
  30. maskNaN(maskNaN==0) = NaN;
  31. %% plot BSR loadings
  32. h = figure('units','centimeter','position',[0 0 15 10]);
  33. set(gcf,'renderer','Painters')
  34. statsPlot = [];
  35. statsPlot = cat(1, statsPlot,squeeze(nanmean(stat.mask(1:64,:,:).*stat.prob(1:64,:,:),1)));
  36. range_plot = [-.5 0.25];
  37. imagesc(stat.time,[],statsPlot, range_plot);
  38. set(gca,'Ydir','Normal');
  39. % set custom colormap
  40. ncol = 2000; cBrew = brewermap(ncol,'RdBu'); cBrew = flipud(cBrew);
  41. % adjust for unequal range
  42. reldev = min(abs(range_plot))./max(abs(range_plot));
  43. if abs(range_plot(2))<max(abs(range_plot))
  44. nadjust = [1:ncol/2, ncol/2+round(linspace(1, ncol/2, reldev*(ncol/2)))];
  45. elseif abs(range_plot(1))<max(abs(range_plot))
  46. nadjust = [round(linspace(1, ncol/2, reldev*(ncol/2))),ncol/2:ncol];
  47. else
  48. nadjust = 1:ncol;
  49. end
  50. cBrew = cBrew(nadjust,:);
  51. colormap(cBrew); colorbar;
  52. xlabel('Time [s from stim onset]'); ylabel('Frequency (Hz)');
  53. title({'ERF changes'; ['p = ', num2str(round(result.perm_result.sprob(indLV),4))]})
  54. set(findall(gcf,'-property','FontSize'),'FontSize',18)
  55. set(gca, 'YTickLabels', round(stat.freq(get(gca, 'YTick')),0));
  56. figureName = ['e2_memory_erf_loadings'];
  57. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  58. saveas(h, fullfile(pn.figures, figureName), 'png');
  59. %% plot multivariate topographies
  60. % set custom colormap
  61. cBrew = brewermap(500,'RdBu');
  62. cBrew = flipud(cBrew);
  63. h = figure('units','centimeters','position',[0 0 10 10]);
  64. set(gcf,'renderer','Painters')
  65. cfg = [];
  66. cfg.layout = 'biosemi64.lay';
  67. cfg.parameter = 'powspctrm';
  68. cfg.comment = 'no';
  69. cfg.colormap = cBrew;
  70. cfg.colorbar = 'EastOutside';
  71. plotData = [];
  72. plotData.label = elec.label; % {1 x N}
  73. plotData.dimord = 'chan';
  74. cfg.zlim = [-2.5 2.5];
  75. cfg.figure = h;
  76. plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1).*...
  77. stat.prob(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1),3),2));
  78. [~, sortind] = sort(plotData.powspctrm, 'ascend');
  79. cfg.marker = 'off';
  80. cfg.highlight = 'yes';
  81. cfg.highlightchannel = plotData.label(sortind(1:6)); % 26, 32, 22, 31, 62, 59
  82. cfg.highlightcolor = [1 1 1];
  83. cfg.highlightsymbol = '.';
  84. cfg.highlightsize = 30;
  85. ft_topoplotER(cfg,plotData);
  86. cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Mean BSR');
  87. title('AlphaBeta')
  88. figureName = ['e2_memory_erf_topo_alpha'];
  89. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  90. saveas(h, fullfile(pn.figures, figureName), 'png');
  91. %% Theta
  92. h = figure('units','centimeters','position',[0 0 10 10]);
  93. set(gcf,'renderer','Painters')
  94. cfg = [];
  95. cfg.layout = 'biosemi64.lay';
  96. cfg.parameter = 'powspctrm';
  97. cfg.comment = 'no';
  98. cfg.colormap = cBrew;
  99. cfg.colorbar = 'EastOutside';
  100. plotData = [];
  101. plotData.label = elec.label; % {1 x N}
  102. plotData.dimord = 'chan';
  103. cfg.zlim = [-.5 .5];
  104. cfg.figure = h;
  105. plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1).*...
  106. stat.prob(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1),3),2));
  107. [~, sortind] = sort(plotData.powspctrm, 'descend');
  108. cfg.marker = 'off';
  109. cfg.highlight = 'yes';
  110. cfg.highlightchannel = plotData.label(sortind(1)); % 33
  111. cfg.highlightcolor = [1 1 1];
  112. cfg.highlightsymbol = '.';
  113. cfg.highlightsize = 30;
  114. ft_topoplotER(cfg,plotData);
  115. cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Mean BSR');
  116. title('Theta')
  117. figureName = ['e2_memory_erf_topo_theta'];
  118. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  119. saveas(h, fullfile(pn.figures, figureName), 'png');
  120. %% plot using raincloud plot
  121. groupsizes=result.num_subj_lst;
  122. conditions=lv_evt_list;
  123. conds = {'forgotten'; 'remembered'};
  124. condData = []; uData = [];
  125. for indGroup = 1
  126. if indGroup == 1
  127. relevantEntries = 1:groupsizes(1)*numel(conds);
  128. elseif indGroup == 2
  129. relevantEntries = groupsizes(1)*numel(conds)+1:...
  130. groupsizes(1)*numel(conds)+groupsizes(2)*numel(conds);
  131. end
  132. for indCond = 1:numel(conds)
  133. targetEntries = relevantEntries(conditions(relevantEntries)==indCond);
  134. condData{indGroup}(indCond,:) = result.vsc(targetEntries,indLV);
  135. uData{indGroup}(indCond,:) = result.usc(targetEntries,indLV);
  136. end
  137. end
  138. cBrew(1,:) = 2.*[.3 .1 .1];
  139. cBrew(2,:) = [.6 .6 .6];
  140. idx_outlier = cell(1); idx_standard = cell(1);
  141. for indGroup = 1
  142. dataToPlot = uData{indGroup}';
  143. % define outlier as lin. modulation that is more than three scaled median absolute deviations (MAD) away from the median
  144. X = [1 1; 1 2]; b=X\dataToPlot'; IndividualSlopes = b(2,:);
  145. outliers = isoutlier(IndividualSlopes, 'median');
  146. idx_outlier{indGroup} = find(outliers);
  147. idx_standard{indGroup} = find(outliers==0);
  148. end
  149. h = figure('units','centimeter','position',[0 0 10 10]);
  150. for indGroup = 1
  151. dataToPlot = uData{indGroup}';
  152. % read into cell array of the appropriate dimensions
  153. data = []; data_ws = [];
  154. for i = 1:2
  155. for j = 1:1
  156. data{i, j} = dataToPlot(:,i);
  157. % individually demean for within-subject visualization
  158. data_ws{i, j} = dataToPlot(:,i)-...
  159. nanmean(dataToPlot(:,:),2)+...
  160. repmat(nanmean(nanmean(dataToPlot(:,:),2),1),size(dataToPlot(:,:),1),1);
  161. data_nooutlier{i, j} = data{i, j};
  162. data_nooutlier{i, j}(idx_outlier{indGroup}) = [];
  163. data_ws_nooutlier{i, j} = data_ws{i, j};
  164. data_ws_nooutlier{i, j}(idx_outlier{indGroup}) = [];
  165. % sort outliers to back in original data for improved plot overlap
  166. data_ws{i, j} = [data_ws{i, j}(idx_standard{indGroup}); data_ws{i, j}(idx_outlier{indGroup})];
  167. end
  168. end
  169. % IMPORTANT: plot individually centered estimates, stats on uncentered estimates!
  170. set(gcf,'renderer','Painters')
  171. cla;
  172. cl = cBrew(indGroup,:);
  173. [~, dist] = rm_raincloud_fixedSpacing(data_ws, [.8 .8 .8],1);
  174. h_rc = rm_raincloud_fixedSpacing(data_ws_nooutlier, cl,1,[],[],[],dist);
  175. view([90 -90]);
  176. axis ij
  177. box(gca,'off')
  178. set(gca, 'YTickLabels', {conds{2}; conds{1}});
  179. yticks = get(gca, 'ytick'); ylim([yticks(1)-(yticks(2)-yticks(1))./2, yticks(2)+(yticks(2)-yticks(1))./1.5]);
  180. minmax = [min(min(cat(2,data_ws{:}))), max(max(cat(2,data_ws{:})))];
  181. xlim(minmax+[-0.2*diff(minmax), 0.2*diff(minmax)])
  182. ylabel('memory'); xlabel({'Brainscore'; '[Individually centered]'})
  183. % test linear effect
  184. curData = [data_nooutlier{1, 1}, data_nooutlier{2, 1}];
  185. X = [1 1; 1 2]; b=X\curData'; IndividualSlopes = b(2,:);
  186. [~, p, ci, stats] = ttest(IndividualSlopes);
  187. title(['M:', num2str(round(mean(IndividualSlopes),3)), '; p=', num2str(round(p,3))])
  188. end
  189. figureName = ['e2_memory_erf_rcp'];
  190. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  191. saveas(h, fullfile(pn.figures, figureName), 'png');