fieldtrip / fieldtrip

The MATLAB toolbox for MEG, EEG and iEEG analysis
http://www.fieldtriptoolbox.org
GNU General Public License v3.0
838 stars 716 forks source link

TFCE with zero-dimensional data (per channel) #1732

Closed tiborauer closed 3 years ago

tiborauer commented 3 years ago

Describe the bug TFCEstat fails for zero-dimensional (i.e. single value) data

To Reproduce Steps to reproduce the behavior (modified version of test_clusterstat):

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.correctm    = 'tfce'; 
cfg.numrandomization = 500;
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
stat = ft_statistics_montecarlo(cfg,dat,cfg.design);

Expected behavior Error:

Unable to perform assignment because the left and right sides have a different number of elements.

Error in findcluster (line 119)
  labelmat(onoff>0) = 1:sum(onoff(:));

Environment and versions (please complete the following information):

Additional context Add any other context about the problem here. The issue seems to be specific to zero-dimensional data, and does not occur when testing with 1-, 2-, or 3-dimensional data (per channel). However, I have noticed that TFCE seems to be less sensitive than 'cluster' in the current implementation (tested with test_clusterstat after changing line 75 to cfg.correctm = 'tfce';); but I cannot tell whether it is related to the issue or due to the inherent nature of the TFCE and 'cluster'.

schoffelen commented 3 years ago

if you have just a single sample, why on earth would you want to do a tfce for multiple comparison correction ?

tiborauer commented 3 years ago

A single sample (per channel) still means multiple samples (in case you have more than one channel), therefore, correction for multiple comparisons is still required. It is, in fact, the most common case for MRI.

schoffelen commented 3 years ago

oh, but then the data are '1-dimensional', right?

tiborauer commented 3 years ago

Right. Then what is the solution for the issue?

schoffelen commented 3 years ago

you tell me

tiborauer commented 3 years ago

If I could, then it would be a PR and not an issue. :)

tiborauer commented 3 years ago

I tried a few things, but then I broke the case for multi-dimensional (as originally framed in test_clusterstat.m) data.

tiborauer commented 3 years ago

'cluster', interestingly, works for 0D (per channel) data.

tiborauer commented 3 years ago

One difference, I have noticed that the input to findcluster is usually logical for 'cluster' but always double for 'tfce'. I can see how it can cause an issue in findcluster (line 119) (see the error above); however, when spacereshapeable, the input becomes double for 'cluster', too.

tiborauer commented 3 years ago

Thank you for the quick response!