% Create an overview plot featuring the results of the multivariate PLS % comparing spectral changes during the stimulus period under load clear all; cla; clc; currentFile = mfilename('fullpath'); [pathstr,~,~] = fileparts(currentFile); cd(fullfile(pathstr,'..')) rootpath = pwd; pn.data = fullfile(rootpath, 'data', 'stats'); pn.figures = fullfile(rootpath, 'figures'); pn.tools = fullfile(rootpath, 'tools'); addpath(genpath(fullfile(pn.tools, '[MEG]PLS', 'MEGPLS_PIPELINE_v2.02b'))) addpath(fullfile(pn.tools, 'fieldtrip')); ft_defaults; addpath(genpath(fullfile(pn.tools, 'RainCloudPlots'))); addpath(fullfile(pn.tools, 'BrewerMap')); addpath(fullfile(pn.tools, 'winsor')); % set custom colormap cBrew = brewermap(500,'RdBu'); cBrew = flipud(cBrew); colormap(cBrew) load(fullfile(pn.data, 'b01_taskpls_erp_avg.mat'),... 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time') load(fullfile(rootpath, 'data','erp', ['sub-001_erp.mat'])); elec = erp.scene_category{1}.elec; result.perm_result.sprob indLV = 1; lvdat = reshape(result.boot_result.compare_u(:,indLV), num_chans, num_freqs, num_time); stat.prob = lvdat; stat.mask = lvdat > 3 | lvdat < -3; % maskNaN = double(stat.mask); % maskNaN(maskNaN==0) = NaN; %% plot multivariate topographies h = figure('units','centimeters','position',[0 0 10 10]); set(gcf,'renderer','Painters') cfg = []; cfg.layout = 'biosemi64.lay'; cfg.parameter = 'powspctrm'; cfg.comment = 'no'; cfg.colormap = cBrew; cfg.colorbar = 'EastOutside'; plotData = []; plotData.label = elec.label; % {1 x N} plotData.dimord = 'chan'; cfg.zlim = [-6 6]; cfg.figure = h; plotData.powspctrm = squeeze(stat.mask.*stat.prob); ft_topoplotER(cfg,plotData); cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Mean BSR'); figureName = ['b01_lv1']; % saveas(h, fullfile(pn.figures, figureName), 'epsc'); % saveas(h, fullfile(pn.figures, figureName), 'png'); %% plot using raincloud plot groupsizes=result.num_subj_lst; conditions=lv_evt_list; conds = {'manmade'; 'natural'}; condData = []; uData = []; for indGroup = 1 if indGroup == 1 relevantEntries = 1:groupsizes(1)*numel(conds); elseif indGroup == 2 relevantEntries = groupsizes(1)*numel(conds)+1:... groupsizes(1)*numel(conds)+groupsizes(2)*numel(conds); end for indCond = 1:numel(conds) targetEntries = relevantEntries(conditions(relevantEntries)==indCond); condData{indGroup}(indCond,:) = result.vsc(targetEntries,indLV); uData{indGroup}(indCond,:) = result.usc(targetEntries,indLV); end end %% plot RainCloudPlot (within-subject centered) cBrew(1,:) = 2.*[.3 .1 .1]; cBrew(2,:) = [.6 .6 .6]; idx_outlier = cell(1); idx_standard = cell(1); for indGroup = 1 dataToPlot = uData{indGroup}'; % define outlier as lin. modulation that is more than three scaled median absolute deviations (MAD) away from the median X = [1 1; 1 2]; b=X\dataToPlot'; IndividualSlopes = b(2,:); outliers = isoutlier(IndividualSlopes, 'median'); idx_outlier{indGroup} = find(outliers); idx_standard{indGroup} = find(outliers==0); end h = figure('units','centimeter','position',[0 0 25 10]); for indGroup = 1 dataToPlot = uData{indGroup}'; % read into cell array of the appropriate dimensions data = []; data_ws = []; for i = 1:2 for j = 1:1 data{i, j} = dataToPlot(:,i); % individually demean for within-subject visualization data_ws{i, j} = dataToPlot(:,i)-... nanmean(dataToPlot(:,:),2)+... repmat(nanmean(nanmean(dataToPlot(:,:),2),1),size(dataToPlot(:,:),1),1); data_nooutlier{i, j} = data{i, j}; data_nooutlier{i, j}(idx_outlier{indGroup}) = []; data_ws_nooutlier{i, j} = data_ws{i, j}; data_ws_nooutlier{i, j}(idx_outlier{indGroup}) = []; % sort outliers to back in original data for improved plot overlap data_ws{i, j} = [data_ws{i, j}(idx_standard{indGroup}); data_ws{i, j}(idx_outlier{indGroup})]; end end % IMPORTANT: plot individually centered estimates, stats on uncentered estimates! subplot(1,2,indGroup); set(gcf,'renderer','Painters') cla; cl = cBrew(indGroup,:); [~, dist] = rm_raincloud_fixedSpacing(data_ws, [.8 .8 .8],1); h_rc = rm_raincloud_fixedSpacing(data_ws_nooutlier, cl,1,[],[],[],dist); view([90 -90]); axis ij box(gca,'off') set(gca, 'YTickLabels', {'natural'; 'manmade'}); yticks = get(gca, 'ytick'); ylim([yticks(1)-(yticks(2)-yticks(1))./2, yticks(2)+(yticks(2)-yticks(1))./1.5]); minmax = [min(min(cat(2,data_ws{:}))), max(max(cat(2,data_ws{:})))]; xlim(minmax+[-0.2*diff(minmax), 0.2*diff(minmax)]) ylabel('scene category'); xlabel({'Brainscore'; '[Individually centered]'}) % test linear effect curData = [data_nooutlier{1, 1}, data_nooutlier{2, 1}]; X = [1 1; 1 2]; b=X\curData'; IndividualSlopes = b(2,:); [~, p, ci, stats] = ttest(IndividualSlopes); title(['M:', num2str(round(mean(IndividualSlopes),3)), '; p=', num2str(round(p,3))]) end figureName = ['b01_rcp']; % saveas(h, fullfile(pn.figures, figureName), 'epsc'); % saveas(h, fullfile(pn.figures, figureName), 'png'); %% get channels to visualize positive = find(squeeze(stat.mask.*stat.prob)>0); negative = find(squeeze(stat.mask.*stat.prob)<0);