123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- % 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.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;
- %% invert solution
- % stat.mask = stat.mask;
- % stat.prob = stat.prob.*-1;
- % result.vsc = result.vsc.*-1;
- % result.usc = result.usc.*-1;
- h = figure('units','centimeter','position',[0 0 15 10]);
- set(gcf,'renderer','Painters')
- statsPlot = [];
- statsPlot = cat(1, statsPlot,squeeze(nanmax(abs(stat.prob(1:64,:,:)),[],1)));
- plot(stat.time,statsPlot, 'k')
- xlabel('Time [s from stim onset]'); ylabel('max abs BSR');
- title({'ERP changes'; ['p = ', num2str(round(result.perm_result.sprob(indLV),4))]})
- set(findall(gcf,'-property','FontSize'),'FontSize',18)
- figureName = ['b01_pls_traces'];
- saveas(h, fullfile(pn.figures, figureName), 'epsc');
- saveas(h, fullfile(pn.figures, figureName), 'png');
- h = figure('units','centimeter','position',[0 0 15 10]);
- set(gcf,'renderer','Painters')
- statsPlot = [];
- statsPlot = cat(1, statsPlot,squeeze(mean(stat.prob(1:64,:,:),1)));
- plot(stat.time,statsPlot, 'k')
- xlabel('Time [s from stim onset]'); ylabel('mean BSR');
- title({'ERP changes'; ['p = ', num2str(round(result.perm_result.sprob(indLV),4))]})
- set(findall(gcf,'-property','FontSize'),'FontSize',18)
- xlim([0 0.3])
- figureName = ['b01_pls_traces'];
- saveas(h, fullfile(pn.figures, figureName), 'epsc');
- saveas(h, fullfile(pn.figures, figureName), 'png');
- %% 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(nanmean(stat.mask(:,:,stat.time >0.08 & stat.time <0.12).*...
- stat.prob(:,:,stat.time >0.08 & stat.time <0.12),3));
- 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');
|