-
Notifications
You must be signed in to change notification settings - Fork 1
/
charybdis plot erpimages.txt
139 lines (97 loc) · 6.97 KB
/
charybdis plot erpimages.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
% "Charybdis"
% RT-Alignment of P600
% Jona Sassenhagen
% jona.sassenhagen@staff.uni-marburg.de
% Script for generating RT-sorted ERPimages for Experiment Charybdis
% This script visualises the RT-alignment of the late positivity after linguistic errors by collecting all participant's EEG and RT data, calculating (single violation trial minus mean of all control trials) difference waves, and plots them in a nifty way
% the actual plotting is done really hackish and with a lot of hardcoding
% You will probably need to modify all file locations
eeglab;
% clear old data and set appropriate, empty "container" variables
ALLEEG=[];EEG=[];
% EEG data containers for syntactic/semantic violation and control data
eegdat1=[];eegdat2=[];eegdat3=[];
% RT data containers for syntactic/semantic violation and control data
allvar1=[];allvar2=[];allvar3=[];
% set appropriate triggers for onset of control/violation words; these will be used to time-lock ERPimage sorting and aligning
control={'S 41', 'S 42', 'S 51', 'S 52'}
syn = {'S 71' 'S 80'}
sem = {'S 60' 'S 61'}
% what channel do you want to look at? 23 is PZ
channel = 23
% enter main loop
for S = 1:20
% set and load single-subject file name (compatible w/ output from preproc script
setname = [num2str((S),'%02i'),'_char_long.set'];
EEG = pop_loadset('filename',setname,'filepath','~/Desktop/charybdis/neufilt/');
% epoch data around syntactic violation NP onsets (1.25 s before to 2.5s after word onset)
EEG = pop_epoch( EEG, syn, [-1.25 2.5], 'epochinfo', 'yes');
% collect EEG data from electrode "channel" into temporary variable "dat" while removing the IC numbers in EEG.clusters.saccade and …blink; remove 'rmcomps' flag if you have not identified eye ICs
dat = squeeze(eeg_getdatact(EEG,'channel',channel,'rmcomps',[EEG.clusters.saccade EEG.clusters.blink]));
% collect RT data (latency from word onset to button press trigger S196) into temporary variable "var"
var = eeg_getepochevent( EEG,{'S196'},[],'latency');
% save EEG and RT data into container 1
allvar1 = [var,allvar1];
eegdat1=[dat,eegdat1];
% reload data file (since you've epoched out all the non-semantic ones
EEG = pop_loadset('filename',setname,'filepath','/home/jona/Desktop/charybdis/neufilt/');
%repeat procedure, but w/ semantic violations
EEG = pop_epoch( EEG, sem, [-1.25 2.5], 'epochinfo', 'yes');
dat = squeeze(eeg_getdatact(EEG,'channel',channel,'rmcomps',[EEG.clusters.saccade EEG.clusters.blink]));
var = eeg_getepochevent( EEG,{'S196'},[],'latency');
allvar3 = [var,allvar3];
eegdat3=[dat,eegdat3];
% repeat for control trials
EEG = pop_loadset('filename',setname,'filepath','/home/jona/Desktop/charybdis/neufilt/');
EEG = pop_epoch( EEG, control, [-1.25 2.5], 'epochinfo', 'yes');
dat = squeeze(eeg_getdatact(EEG,'channel',channel,'rmcomps',[EEG.clusters.saccade EEG.clusters.blink]));
var = eeg_getepochevent( EEG,{'S196'},[],'latency');
allvar2 = [var,allvar2];
eegdat2=[dat,eegdat2];
% end loop for data collection
end;
% all participants (correctly responded) trials are now collected into 6 container files
% allvar(1-3) has the RTs; eegdat(1-3) has the EEG data, with 1-3 being morphosyntactic, control and violation trials, respectively
% uncomment these values to see statistics about semantic and syntactic error RTs
%signalstat(allvar1,1,'Morphosyntactic violation RT',100);
%signalstat(allvar3,1,'Semantic violation RT',100);
% oh god ... very ugly scripting follows
% calculate mean ERP of all control trials
controlerp = mean(eegdat2,2);
% build syntax difference waves by 1. saving old syntax violation into var C
C = eegdat1;
% ... and subtracting the mean control ERP from all entries in C
for ii=1:length(C(1,:))
C(:,ii)=C(:,ii)-controlerp;
end
% do the same for semantic trials
D = eegdat3;
for ii=1:length(D(1,:))
D(:,ii)=D(:,ii)-controlerp;
end
% This plots the syntax difference waves in an ERPimage, sorted by RT, twice, once aligned to NP onset, once to RT
% covertly collect RT-sorted ERPimage data aligned to epoch centre (word onset); gaussian smoothing factor set to 30
% sorted EEG data is written into outdata5, RT into outvar5, and I think out trials5 doesn't actually do anything. Neither does the title.
[outdata5,outvar5,outtrials5] = erpimage(C, allvar1, linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 30, 1 , 'avg_type','Gaussian','NoShow','on');
% same, but this time, 'align','inf' means that data is aligned to "allvar", meaning, single-trial RT
[outdata6,outvar6,outtrials5] = erpimage(C, allvar1, linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 30, 1 ,'avg_type','Gaussian','NoShow','on','align',inf);
% plot the syntax ERPimage
% it will be a lot simpler to visualise the data first by plotting the above command with 'NoShow','off' to see what's actually in the data. What follows is needlessly only because it's surprisingly hard to make EEGLAB draw two ERPimages into one figure and draw the appropriate helper lines for sorter. Or maybe I'm just a bad programmer!
% all the crazy "zeros, length, …" stuff is just to draw the correct lines indicating RTs and onsets; still, you will have to delete one of them by hand
% data limits are set manually (to -3.5 to 7) to ensure they are identical between both plots!
% data is also filtered with a 30 hz low pass filter, though that doesn't really change much
% basically, length(outvar5) is the number of trials and therefore, where a horizontal line should be drawn, mean(outvar6) is the mean RT and therefore, ones(1,length(outvar6))*mean(outvar6) is the point where any straight vertical lines should be drawn
% the 'erp',2 flag makes sure two ERPs are drawn, one as the mean of all trials above, one below the (length(outvar5)) line
figure; erpimage([outdata5 outdata6], [zeros(1,length(outvar5)) ones(1,length(outvar6))*mean(outvar6)], linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 1, 1 , 'erp',2, 'cbar','on','nosort','on','auxvar',[outvar5 mean(outvar6)-outvar6], 'yerplabel','\muV','limits',[NaN NaN -4 8],'horz',[length(outvar5)],'cbar_title','\muV', 'filt',[0 30])
%select ERPimage manually
ylabel(gca,'Alignment')
set(gca,'YTick',[1000 2750])
set(gca,'YTickLabel',{'Onset','RT'})
% repeat for semantic violation trials; note gaussian smoothing factor is only 15 because there are less trials in this condition
[outdata7,outvar7,outtrials7] = erpimage(D, allvar3, linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 15, 1 ,'avg_type','Gaussian','NoShow','on');
[outdata8,outvar8,outtrials8] = erpimage(D, allvar3, linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 15, 1 ,'avg_type','Gaussian','NoShow','on','align',inf);
figure; erpimage([outdata7 outdata8], [zeros(1,length(outvar7)) ones(1,length(outvar8))*mean(outvar8)], linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts), '', 1, 1 , 'erp',2, 'cbar','on','horz',[length(outvar7)],'nosort','on','auxvar',[outvar7 mean(outvar8)-outvar8],'yerplabel','\muV','limits',[NaN NaN -4 8],'filt',[0 30],'cbar_title','\muV');
%select ERPimage manually
ylabel(gca,'Alignment')
set(gca,'YTick',[350 1000])
set(gca,'YTickLabel',{'Onset','RT'})