c3_taskPLS_novelty_posterior_alpha_LV1.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, 'c3_taskpls_alpha.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 multivariate topographies
  32. h = figure('units','centimeters','position',[0 0 10 10]);
  33. set(gcf,'renderer','Painters')
  34. cfg = [];
  35. cfg.layout = 'biosemi64.lay';
  36. cfg.parameter = 'powspctrm';
  37. cfg.comment = 'no';
  38. cfg.colormap = cBrew;
  39. cfg.colorbar = 'EastOutside';
  40. plotData = [];
  41. plotData.label = elec.label; % {1 x N}
  42. plotData.dimord = 'chan';
  43. cfg.zlim = [-2 2];
  44. cfg.figure = h;
  45. plotData.powspctrm = squeeze(nanmean(stat.mask(:,:,:).*...
  46. stat.prob(:,:,:),3));
  47. ft_topoplotER(cfg,plotData);
  48. cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Mean BSR');
  49. %% plot RainCloudPlot (within-subject centered)
  50. groupsizes=result.num_subj_lst;
  51. conditions=lv_evt_list;
  52. conds = {'old'; 'new'};
  53. condData = []; uData = [];
  54. for indGroup = 1
  55. if indGroup == 1
  56. relevantEntries = 1:groupsizes(1)*numel(conds);
  57. elseif indGroup == 2
  58. relevantEntries = groupsizes(1)*numel(conds)+1:...
  59. groupsizes(1)*numel(conds)+groupsizes(2)*numel(conds);
  60. end
  61. for indCond = 1:numel(conds)
  62. targetEntries = relevantEntries(conditions(relevantEntries)==indCond);
  63. condData{indGroup}(indCond,:) = result.vsc(targetEntries,indLV);
  64. uData{indGroup}(indCond,:) = result.usc(targetEntries,indLV);
  65. end
  66. end
  67. cBrew(1,:) = 2.*[.3 .1 .1];
  68. idx_outlier = cell(1); idx_standard = cell(1);
  69. for indGroup = 1
  70. dataToPlot = uData{indGroup}';
  71. % define outlier as lin. modulation that is more than three scaled median absolute deviations (MAD) away from the median
  72. X = [1 1; 1 2]; b=X\dataToPlot'; IndividualSlopes = b(2,:);
  73. outliers = isoutlier(IndividualSlopes, 'median');
  74. idx_outlier{indGroup} = find(outliers);
  75. idx_standard{indGroup} = find(outliers==0);
  76. end
  77. h = figure('units','centimeter','position',[0 0 10 10]);
  78. for indGroup = 1
  79. dataToPlot = uData{indGroup}';
  80. % read into cell array of the appropriate dimensions
  81. data = []; data_ws = [];
  82. for i = 1:2
  83. for j = 1:1
  84. data{i, j} = dataToPlot(:,i);
  85. % individually demean for within-subject visualization
  86. data_ws{i, j} = dataToPlot(:,i)-...
  87. nanmean(dataToPlot(:,:),2)+...
  88. repmat(nanmean(nanmean(dataToPlot(:,:),2),1),size(dataToPlot(:,:),1),1);
  89. data_nooutlier{i, j} = data{i, j};
  90. data_nooutlier{i, j}(idx_outlier{indGroup}) = [];
  91. data_ws_nooutlier{i, j} = data_ws{i, j};
  92. data_ws_nooutlier{i, j}(idx_outlier{indGroup}) = [];
  93. % sort outliers to back in original data for improved plot overlap
  94. data_ws{i, j} = [data_ws{i, j}(idx_standard{indGroup}); data_ws{i, j}(idx_outlier{indGroup})];
  95. end
  96. end
  97. % IMPORTANT: plot individually centered estimates, stats on uncentered estimates!
  98. set(gcf,'renderer','Painters')
  99. cla;
  100. cl = cBrew(indGroup,:);
  101. [~, dist] = rm_raincloud_fixedSpacing(data_ws, [.8 .8 .8],1);
  102. h_rc = rm_raincloud_fixedSpacing(data_ws_nooutlier, cl,1,[],[],[],dist);
  103. view([90 -90]);
  104. axis ij
  105. box(gca,'off')
  106. set(gca, 'YTickLabels', {'natural'; 'manmade'});
  107. yticks = get(gca, 'ytick'); ylim([yticks(1)-(yticks(2)-yticks(1))./2, yticks(2)+(yticks(2)-yticks(1))./1.5]);
  108. minmax = [min(min(cat(2,data_ws{:}))), max(max(cat(2,data_ws{:})))];
  109. xlim(minmax+[-0.2*diff(minmax), 0.2*diff(minmax)])
  110. ylabel('novelty'); xlabel({'Brainscore'; '[Individually centered]'})
  111. % test linear effect
  112. curData = [data_nooutlier{1, 1}, data_nooutlier{2, 1}];
  113. X = [1 1; 1 2]; b=X\curData'; IndividualSlopes = b(2,:);
  114. [~, p, ci, stats] = ttest(IndividualSlopes);
  115. title(['M:', num2str(round(mean(IndividualSlopes),3)), '; p=', num2str(round(p,3))])
  116. end