init_unfold
Introduction
This basic tutorial starts with generating some EEG data with overlap. For the sake of having a backstory, we will simulate data of an experiment where we have two types of stimuli (face or car) with two types of colors (red and green) embedded in pink noise. Subjects are asked to count the number of objects irregardless of color.
We are interested what the influences of the stimulus-type and color is.
This tutorial only shows the minimally necessary functions. Have a look at the second tutorial for more extensive explanations and plotting functions.
% We will first simulate data based on the car/face, green/red design.
EEG = tutorial_simulate_data('2x2')
Defining the 2x2 factorial design
A 2x2 anova is equal to a linear model with two categorical predictors and the interaction. We adopt the widely popular 'formula'-style of model definition. In this case 'y ~ A + B + A:B' (equivalent: 'y ~ A*B') represents the whole model. A and B are our main effects, A:B the interaction. We should specify that we have two categorical factors and we have to specify on which event(s) we want to epoch our data and evaluate the model.
cfgDesign = [];
cfgDesign.eventtypes = {'fixation'};
cfgDesign.formula = 'y ~ 1+ cat(stimulusType)*cat(color)';
EEG = uf_designmat(EEG,cfgDesign);
Timeshift
In order to compensate for the inevitable linear overlap between ERPs, we want to use timeshifting / prepare the designmatrix for the deconvolution step. In this step we generate for each column of the designmatrix timeshifted (by t = 1, t=2, t=3 ...) and append them to the designmatrix.
cfgTimeexpand = [];
cfgTimeexpand.timelimits = [-.3,1.5];
EEG = uf_timeexpandDesignmat(EEG,cfgTimeexpand);
Fit the model
We solve the linear equation: (y=data, X= Designmatrix) for β at each point in time. These betas reflect our parameter estimates.
EEG= uf_glmfit(EEG);
Plot the results
We choose a single electrode and plot all effects.
ufresult= uf_condense(EEG);
cfg = [];
cfg.channel = 1;
ax = uf_plotParam(ufresult,cfg);
One can clearly see that we recover the intercept and the simulated effects. The intercept represents the response when both stimulusType = 'car' and color = 'green'. The second column is the component one needs to add to the intercept to gain the ERP for the color 'red'. The third column equally represents the difference (i.e. what to add) of face to car. The fourth column represents the interaction. Because we did not simulate an interaction, this ERP is flat. Note that with effects-coding the results would look quite different. Have a look at tutorial 2 where we go into more depth.