forked from fieldtrip/fieldtrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_conjunctionanalysis.m
242 lines (198 loc) · 8.68 KB
/
ft_conjunctionanalysis.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
function [conjunction] = ft_conjunctionanalysis(cfg, varargin)
% FT_CONJUNCTIONANALYSIS finds the minimum statistic common across two or
% more contrasts, i.e. data following ft_xxxstatistics. Furthermore, it
% finds the overlap of sensors/voxels that show statistically significant
% results (a logical AND on the mask fields).
%
% Alternatively, it finds minimalistic mean power values in the
% input datasets. Here, a type 'relative change' baselinecorrection
% prior to conjunction is advised.
%
% Use as
% [stat] = ft_conjunctionanalysis(cfg, stat1, stat2, .., statN)
%
% where the input data is the result from either FT_TIMELOCKSTATISTICS,
% FT_FREQSTATISTICS, or FT_SOURCESTATISTICS
%
% No configuration options are yet implemented.
%
% See also FT_TIMELOCKSTATISTICS, FT_FREQSTATISTICS, FT_SOURCESTATISTICS
% Copyright (C) 2010-2014, Arjen Stolk
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
% these are used by the ft_preamble/ft_postamble function and scripts
ft_revision = '$Id$';
ft_nargin = nargin;
ft_nargout = nargout;
% do the general setup of the function
ft_defaults
ft_preamble init
ft_preamble debug
ft_preamble loadvar varargin
ft_preamble provenance varargin
ft_preamble trackconfig
% the ft_abort variable is set to true or false in ft_preamble_init
if ft_abort
return
end
% input check
ndatasets = length(varargin);
if ndatasets<2
ft_error('not enough input arguments; there should be at least two');
end
% check if the input data is valid for this function
for i = 1:ndatasets
varargin{i} = ft_checkdata(varargin{i}, 'datatype', {'timelock', 'freq', 'source'}, 'feedback', 'yes');
end
fprintf('performing conjunction analysis on %d input datasets \n', ndatasets);
conjunction = [];
% determine datatype
isfreq = ft_datatype(varargin{1}, 'freq');
istimelock = ft_datatype(varargin{1}, 'timelock');
issource = ft_datatype(varargin{1}, 'source');
% conjunction loop, in case ndatasets > 2
for i = 1:ndatasets-1
% align input arguments for conjunction
if isempty(conjunction)
data1 = varargin{i};
data2 = varargin{i+1};
else
data1 = conjunction; % use already conjunct output
data2 = varargin{i+1};
end
%% SOURCE DATA
if issource
if isfield(data1, 'stat')
fprintf('minimum statistics on source level data \n');
% equal size input check
if ~isequal(size(data1.stat), size(data2.stat))
ft_error('the input arguments have different sizes');
end
% prepare the output data structure
conjunction = data1;
if isfield(data1, 'posclusters') % remove cluster details
fprintf('removing information about positive clusters\n');
conjunction = rmfield(conjunction, 'posclusters');
conjunction = rmfield(conjunction, 'posclusterslabelmat');
end
if isfield(data1, 'negclusters') % remove cluster details
fprintf('removing information about negative clusters\n');
conjunction = rmfield(conjunction, 'negclusters');
conjunction = rmfield(conjunction, 'negclusterslabelmat');
end
fprintf('minimum statistics on stat fields \n');
conjunction.stat = minimumstatistics(data1.stat, data2.stat);
if isfield(data1, 'prob') && isfield(data2, 'prob') % conjunction on probabilities
fprintf('minimum statistics on prob fields \n');
conjunction.prob = maximumprobabilities(data1.prob, data2.prob);
end
if isfield(data1, 'mask') && isfield(data2, 'mask') % conjunction on mask parameters
fprintf('logical AND on mask fields \n');
conjunction.mask = logicalAND(data1.mask, data2.mask);
end
elseif isfield(data1, 'avg') && isfield(data2, 'avg') % conjunction on mean power values
fprintf('minimum statistics on mean voxel power \n');
% equal size input check
if ~isequal(size(data1.avg.pow), size(data2.avg.pow))
ft_error('the input arguments have different sizes');
end
conjunction = data1;
conjunction.avg.pow = minimumstatistics(data1.avg.pow, data2.avg.pow);
elseif isfield(data1, 'trial')
fprintf('please first compute the averages with ft_sourcedescriptives \n');
else
fprintf('this source level data does not fit conjunction analysis \n');
end
end % end of source level conjunction
%% SENSOR DATA
if isfreq || istimelock
if isfield(data1, 'stat') % conjunction on t-values
fprintf('minimum statistics on sensor level data \n');
% equal size input check
if ~isequal(size(data1.stat), size(data2.stat))
ft_error('the input arguments have different sizes');
end
% prepare the output data structure
conjunction = data1;
if isfield(data1, 'posclusters') % remove cluster details
fprintf('removing information about positive clusters\n');
conjunction = rmfield(conjunction, 'posclusters');
conjunction = rmfield(conjunction, 'posclusterslabelmat');
end
if isfield(data1, 'negclusters') % remove cluster details
fprintf('removing information about negative clusters\n');
conjunction = rmfield(conjunction, 'negclusters');
conjunction = rmfield(conjunction, 'negclusterslabelmat');
end
fprintf('minimum statistics on stat fields \n');
conjunction.stat = minimumstatistics(data1.stat, data2.stat);
if isfield(data1, 'prob') && isfield(data2, 'prob') % conjunction on probabilities
fprintf('minimum statistics on prob fields \n');
conjunction.prob = maximumprobabilities(data1.prob, data2.prob);
end
if isfield(data1, 'mask') && isfield(data2, 'mask') % conjunction on mask parameters
fprintf('logical AND on mask fields \n');
conjunction.mask = logicalAND(data1.mask, data2.mask);
end
elseif isfield(data1, 'powspctrm') && isfield(data2, 'powspctrm') % conjunction on mean power values
fprintf('minimum statistics on mean sensor power \n');
% equal size input check
if ~isequal(size(data1.powspctrm), size(data2.powspctrm))
ft_error('the input arguments have different sizes');
end
conjunction = data1;
conjunction.powspctrm = minimumstatistics(data1.powspctrm, data2.powspctrm);
elseif isfield(data1, 'avg') && isfield(data2, 'avg') % conjunction on mean signal amplitudes
fprintf('minimum statistics on mean sensor amplitudes \n');
% equal size input check
if ~isequal(size(data1.avg), size(data2.avg))
ft_error('the input arguments have different sizes');
end
conjunction = data1;
conjunction.avg = minimumstatistics(data1.avg, data2.avg);
elseif isfield(data1, 'trial')
fprintf('please first compute the averages with ft_timelockdescriptives/ft_freqdescriptives \n');
else
fprintf('this sensor level data does not fit conjunction analysis \n');
end
end % end of sensor level conjunction
clear data1; clear data2;
end % end of conjunction loop
%% UNIDENTIFIED DATA
if istimelock == 0 && isfreq == 0 && issource == 0
fprintf('this data is not appropriate for conjunction analysis\n');
conjunction = [];
end
% do the general cleanup and bookkeeping at the end of the function
ft_postamble debug
ft_postamble trackconfig
ft_postamble previous varargin
ft_postamble provenance conjunction
ft_postamble history conjunction
ft_postamble savevar conjunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [minstat] = minimumstatistics(variable1, variable2)
minAbsT = min(abs(variable1), abs(variable2)); % minimum of the absolute values
equalSign = (sign(variable1) == sign(variable2)); % 1 is signs are equal, 0 otherwise
origSign = sign(variable1); % sign(varagin2) gives same result
minstat = minAbsT.*equalSign.*origSign;
function [maxprob] = maximumprobabilities(variable1, variable2)
maxprob = max(variable1, variable2); % maximum of the probabilities
function [logic] = logicalAND(variable1, variable2)
logic = (variable1 & variable2); % compute logical AND