-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze_group.m
198 lines (154 loc) · 7.16 KB
/
analyze_group.m
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
outputprefix = '/Volumes/BIOMAG2016/biomag2016/processed';
warning off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% load the single subject averages
timelock_famous = {};
timelock_unfamiliar = {};
timelock_scrambled = {};
timelock_faces = {};
for subject=1:16
details = sprintf('details_sub%02d', subject)
eval(details);
tmp = load(fullfile(outputpath, 'timelock_famous'));
timelock_famous{subject} = tmp.timelock;
tmp = load(fullfile(outputpath, 'timelock_unfamiliar'));
timelock_unfamiliar{subject} = tmp.timelock;
tmp = load(fullfile(outputpath, 'timelock_scrambled'));
timelock_scrambled{subject} = tmp.timelock;
tmp = load(fullfile(outputpath, 'timelock_faces'));
timelock_faces{subject} = tmp.timelock;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% compute planar gradients
timelock_famous_cmb = {};
timelock_unfamiliar_cmb = {};
timelock_scrambled_cmb = {};
timelock_faces_cmb = {};
for i=1:16
disp(i)
cfg = [];
timelock_famous_cmb{i} = ft_combineplanar(cfg, timelock_famous{i});
timelock_unfamiliar_cmb{i} = ft_combineplanar(cfg, timelock_unfamiliar{i});
timelock_scrambled_cmb{i} = ft_combineplanar(cfg, timelock_scrambled{i});
timelock_faces_cmb{i} = ft_combineplanar(cfg, timelock_faces{i});
end
% this is a bit of a lengthy step, hence save the intermediate results
save(fullfile(outputprefix, 'timelock_famous_cmb'), 'timelock_famous_cmb');
save(fullfile(outputprefix, 'timelock_unfamiliar_cmb'), 'timelock_unfamiliar_cmb');
save(fullfile(outputprefix, 'timelock_scrambled_cmb'), 'timelock_scrambled_cmb');
save(fullfile(outputprefix, 'timelock_faces_cmb'), 'timelock_faces_cmb');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% compute grand averages
timelock_famous_cmb_ga = ft_timelockgrandaverage(cfg, timelock_famous_cmb{:});
timelock_unfamiliar_cmb_ga = ft_timelockgrandaverage(cfg, timelock_unfamiliar_cmb{:});
timelock_scrambled_cmb_ga = ft_timelockgrandaverage(cfg, timelock_scrambled_cmb{:});
timelock_faces_cmb_ga = ft_timelockgrandaverage(cfg, timelock_faces_cmb{:});
%% visualise the grand-averages
cfg = [];
cfg.layout = 'neuromag306cmb';
figure
ft_multiplotER(cfg, timelock_faces_cmb_ga, timelock_scrambled_cmb_ga);
figure
ft_multiplotER(cfg, timelock_famous_cmb_ga, timelock_unfamiliar_cmb_ga);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% do standard statistical comparison between conditions
cfg = [];
cfg.method = 'analytic';
cfg.statistic = 'depsamplesT';
cfg.correctm = 'fdr';
cfg.design = [
1:16 1:16
1*ones(1,16) 2*ones(1,16)
];
cfg.uvar = 1; % unit of observation, i.e. subject
cfg.ivar = 2; % independent variable, i.e. stimulus
stat_cmb_faces_vs_scrambled = ft_timelockstatistics(cfg, timelock_faces_cmb{:}, timelock_scrambled_cmb{:});
stat_cmb_famous_vs_unfamiliar = ft_timelockstatistics(cfg, timelock_famous_cmb{:}, timelock_unfamiliar_cmb{:});
% this is a bit of a lengthy step, hence save the results
save(fullfile(outputprefix, 'stat_cmb_faces_vs_scrambled'), 'stat_cmb_faces_vs_scrambled');
save(fullfile(outputprefix, 'stat_cmb_famous_vs_unfamiliar'), 'stat_cmb_famous_vs_unfamiliar');
% quick and dirty visualisation
figure;
subplot(2,1,1)
h = imagesc(-log10(stat_cmb_faces_vs_scrambled.prob)); colorbar
subplot(2,1,2)
h = imagesc(-log10(stat_cmb_faces_vs_scrambled.prob)); colorbar
set(h, 'AlphaData', stat_cmb_faces_vs_scrambled.mask);
print('-dpng', fullfile(outputprefix, 'stat_cmb_faces_vs_scrambled.png'));
%% compute the condition difference
cfg = [];
cfg.parameter = 'avg';
cfg.operation = 'x1-x2';
diff_cmb_faces_vs_scrambled = ft_math(cfg, timelock_faces_cmb_ga, timelock_scrambled_cmb_ga);
diff_cmb_famous_vs_unfamiliar = ft_math(cfg, timelock_famous_cmb_ga, timelock_unfamiliar_cmb_ga);
% save the results
save(fullfile(outputprefix, 'diff_cmb_faces_vs_scrambled'), 'diff_cmb_faces_vs_scrambled');
save(fullfile(outputprefix, 'diff_cmb_famous_vs_unfamiliar'), 'diff_cmb_famous_vs_unfamiliar');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% more detailled visualisation
% add the statistical mask to the data
diff_cmb_faces_vs_scrambled.mask = stat_cmb_faces_vs_scrambled.mask;
diff_cmb_famous_vs_unfamiliar.mask = stat_cmb_famous_vs_unfamiliar.mask;
cfg = [];
cfg.layout = 'neuromag306cmb';
cfg.parameter = 'avg';
cfg.maskparameter = 'mask';
figure
ft_multiplotER(cfg, diff_cmb_faces_vs_scrambled);
print('-dpng', fullfile(outputprefix, 'diff_cmb_faces_vs_scrambled_stat.png'));
figure
ft_multiplotER(cfg, diff_cmb_famous_vs_unfamiliar);
print('-dpng', fullfile(outputprefix, 'diff_cmb_famous_vs_unfamiliar_stat.png'));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% determine the neighbours that we consider to share evidence in favour of H1
cfg = [];
cfg.layout = 'neuromag306cmb';
cfg.method = 'distance';
cfg.neighbourdist = 0.15;
cfg.feedback = 'yes';
neighbours_cmb = ft_prepare_neighbours(cfg); % this is an example of a poor neighbourhood definition
print('-dpng', fullfile(outputprefix, 'neighbours_cmb_distance.png'));
cfg.layout = 'neuromag306cmb';
cfg.method = 'triangulation';
cfg.feedback = 'yes';
neighbours_cmb = ft_prepare_neighbours(cfg); % this one is better, but could use some manual adjustments
print('-dpng', fullfile(outputprefix, 'neighbours_cmb_triangulation.png'));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% do a more sensitive channel-level statistical analysis
cfg = [];
cfg.method = 'montecarlo';
cfg.numrandomization = 500;
cfg.statistic = 'depsamplesT';
cfg.correctm = 'cluster';
cfg.neighbours = neighbours_cmb;
cfg.design = [
1:16 1:16
1*ones(1,16) 2*ones(1,16)
];
cfg.uvar = 1; % unit of observation, i.e. subject
cfg.ivar = 2; % independent variable, i.e. stimulus
cluster_cmb_faces_vs_scrambled = ft_timelockstatistics(cfg, timelock_faces_cmb{:}, timelock_scrambled_cmb{:});
cluster_cmb_famous_vs_unfamiliar = ft_timelockstatistics(cfg, timelock_famous_cmb{:}, timelock_unfamiliar_cmb{:});
% this is a very lengthy step, hence save the results
save(fullfile(outputprefix, 'cluster_cmb_faces_vs_scrambled'), 'cluster_cmb_faces_vs_scrambled');
save(fullfile(outputprefix, 'cluster_cmb_famous_vs_unfamiliar'), 'cluster_cmb_famous_vs_unfamiliar');
%% visualisation
% add the statistical mask to the data
diff_cmb_faces_vs_scrambled_.mask = cluster_cmb_faces_vs_scrambled.mask;
diff_cmb_famous_vs_unfamiliar.mask = cluster_cmb_famous_vs_unfamiliar.mask;
cfg = [];
cfg.layout = 'neuromag306cmb';
cfg.parameter = 'avg';
cfg.maskparameter = 'mask';
figure
ft_multiplotER(cfg, diff_cmb_faces_vs_scrambled);
print('-dpng', fullfile(outputprefix, 'diff_cmb_faces_vs_scrambled_cluster.png'));
figure
ft_multiplotER(cfg, diff_cmb_famous_vs_unfamiliar);
print('-dpng', fullfile(outputprefix, 'diff_cmb_famous_vs_unfamiliar.png'));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% show full provenance of the final analysis
cfg = [];
cfg.filetype = 'html';
cfg.filename = fullfile(outputprefix, 'cluster_cmb_faces_vs_scrambled');
ft_analysispipeline(cfg, cluster_cmb_faces_vs_scrambled);