The EEGLAB News #9


How do you plot standard error shades on ERP?

Question: EEGLAB user
Answers: Cédric Cannard, Ph.D, Arnaud Delorme, Ph.D., and Cyril Pernet, Ph.D.

I’ve seen this posted a few times. Seems like it’s relatively standard now to include standard error “shades” in publications these days of ERP data. I’d like to do this on my grand averaged STUDY data but am having a few hard time figuring out how to do so in EEGLAB. Does anyone have tips/tricks for doing this in EEGLAB or other (preferably simple) methods?

Thanks!
(EEGLAB user)

Hi,

Below is an example of plotting one subject's epoched data. You should adapt the script to use the output of the STUDY function as input data for plotting.

data1 = squeeze(EEG.data(channel_number,:,:));
nEpochs = size(data1,2);
data1_mean = mean(data1,2)';
data1_se = std(data1 ./ sqrt(nEpochs),[],2)';
color1 = [0, 0.4470, 0.7410];
xAxis = 1:size(data1,1); %ADJUST WITH YOUR LAGS

plot(xAxis, data1_mean,'LineWidth',2,'Color',color1); hold on
fillhandle = fill([xAxis fliplr(xAxis)], [data1_mean-data1_se fliplr(data1_mean+data1_se)], color1);
set(fillhandle,'EdgeColor', color1,'FaceAlpha',0.2,'EdgeAlpha',0.8);
set(gca,'FontSize',12,'layer','top');
grid on; axis tight; box on;
ylabel('ERP amplitude','FontSize',12);
xlabel('Time','FontSize',12);
hPlots = flip(findall(gcf,'Type','Line'));
legend(hPlots, 'data1Name (SE)');

You may duplicate the lines containing data1 with data2 to superimpose another condition/group (i.e., data2).

Cedric Cannard

Hi,

You can also do that at the study level

https://eeglab.org/tutorials/11_Scripting/command_line_study_functions.html#plotting-measures

In scripts, the EEGLAB function “fillcurves" is also easy to use to create shaded areas.
See the function help message for more details.

figure; fillcurves(rand(1,100), rand(1,100)+1.5);

Arnaud Delorme

Hi,

Testing differences is well performed using a hierarchical linear model
accounting for within-subject (between trials), and between subjects
variances - a robust difference (yuen t-test) can be computed
companioned by ERP Highest-density Intervals; see e.g.
https://github.com/LIMO-EEG-Toolbox/limo_tools/wiki/Plotting-differences

Cyril Pernet