Skip to content

Commit

Permalink
FIX - ensure that findcluster works robustly when called by tfcestat (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
schoffelen committed Apr 9, 2021
1 parent 144cdd7 commit 4ffa4a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion private/findcluster.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
labelmat = zeros(size(onoff));
numcluster = 0;

if ~(numel(siz)==1 && all(siz==1))
if ~(numel(siz)==1 && all(siz==1) && islogical(onoff))
for j = 1:spatdimlength
if numel(siz) <= 3 % if 2D or 3D data (without spatial dimension)
% use SPM for 2D/3D data instead of the MATLAB image processing toolbox
Expand Down
58 changes: 58 additions & 0 deletions test/test_clusterstat.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@
% WALLTIME 00:10:00
% DEPENDENCY findcluster clusterstat ft_statistics_montecarlo

%%%%%%%%5
% some code -> this relates to issue 1732
pattern = [...
1 1 1 1 0 1 1 1 1 1;...
1 0 0 0 0 0 0 1 0 0;...
1 1 1 0 0 0 0 1 0 0;...
1 0 0 0 0 0 0 1 0 0;...
1 0 0 0 0 0 0 1 0 0;...
]; % FT

%% 0D (per channel)
% make fake dataset
data = cell(1,10);
for idat = 1:10
data{idat}.label = {'ch1' 'ch2' 'ch3' 'ch4' 'ch5'}';
data{idat}.dimord = 'chan_freq';
data{idat}.parameter = rand(5,1);
if idat <= 5
data{idat}.parameter = data{idat}.parameter + 2*pattern(:,2);
end
end

% do stats - montecarlo
cfg = [];
cfg.method = 'montecarlo';
cfg.statistic = 'ft_statfun_depsamplesT';
cfg.alpha = 0.05;
cfg.numrandomization = 'all';
cfg.design = [ones(1,5) ones(1,5).*2; 1:5 1:5;];
cfg.ivar = 1;
cfg.uvar = 2;

% - data
cfg.parameter = 'parameter';
cfg.channel = data{1}.label;
cfg.connectivity = [...
false true false false false;...
true false false false false;...
false false false true false;...
false false true false false;...
false false false false false;...
]; % neighbours: ch1 - ch2, ch3 - ch4

cfg.dim = size(data{1}.(cfg.parameter));
cfg.dimord = data{1}.dimord;
dat = cell2mat(cellfun(@(x) x.(cfg.parameter)(:), data, 'UniformOutput', false));

% - run
cfg.correctm = 'cluster';
stat = ft_statistics_montecarlo(cfg,dat,cfg.design);
cfg.correctm = 'tfce';
stat = ft_statistics_montecarlo(cfg,dat,cfg.design);


%%%%%%%%%%%%%5
% some other code


pattern = [...
1 1 1 1 0 1 1 1 1 1;...
1 0 0 0 0 0 0 1 0 0;...
Expand Down

0 comments on commit 4ffa4a6

Please sign in to comment.