Back to the main page.

Bug 2479 - timelockstatistics lead to error when averaging across channels

Status CLOSED FIXED
Reported 2014-02-23 00:51:00 +0100
Modified 2019-08-10 12:29:01 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P5 normal
Assigned to: Eelke Spaak
URL:
Tags:
Depends on:
Blocks:
See also:

Ana Todorovic - 2014-02-23 00:51:29 +0100

I have found a possible bug in ft_timelockstatistics. I found a way around the issue, but I thought that you might want to know about it. I am getting the following error if I average over channels when running ft_timelockstatistics, but only if the cfg.correctm is set to 'cluster': Error using findcluster (line 56) invalid dimension of spatdimneighbstructmat It doesn't help to specify an empty neighhbourhood structure (I tried [] and {}). The error does not show up if cfg.correctm is set to 'max' or 'bonferoni'. I didn't check the remaining false alarm correction methods. The error also does not appear if I don't average over channels but keep cfg.correctm = 'cluster'. I am also doing ft_freqstatistics currently and the problem is not present there. I tried to follow the fieldtrip tutorial wiki on ft_timelockstatistics, and I get the same error if I set avgoverchan to 'yes' but keep all other configuration options unchanged.


Jan-Mathijs Schoffelen - 2014-03-06 15:44:28 +0100

Hi Ana, could you upload some data and a snippet of code for us to reproduce this? Thanks. How's Berkeley? JM


Jan-Mathijs Schoffelen - 2014-03-18 20:53:07 +0100

This is a gentle reminder to post some data, in order to move forward...


Ana Todorovic - 2014-03-18 21:24:37 +0100

(In reply to Jan-Mathijs Schoffelen from comment #2) Hey, sorry, for some reason I didn't get an e-mail notification of your first reply! I totally forgot about this (too much sun and wine :) (I'm lying, I'm mostly behind my computer...) I'll use the wiki tutorial as an example: http://fieldtrip.fcdonders.nl/tutorial/cluster_permutation_timelock You need the data from Subject1 to run it: ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/Subject01.zip Here is some code, all from the tutorial, with my changes at the end: clear all % preprocess and timelock condition 1 cfg = []; cfg.dataset = 'Subject01.ds'; cfg.trialdef.eventtype = 'backpanel trigger'; cfg.trialdef.prestim = 1; cfg.trialdef.poststim = 2; cfg.trialdef.eventvalue = 3; cfg = ft_definetrial(cfg); cfg.trl([15, 36, 39, 42, 43, 49, 50, 81, 82, 84],:) = []; cfg.channel = {'MEG', '-MLP31', '-MLO12'}; cfg.demean = 'yes'; cfg.baselinewindow = [-0.2 0]; cfg.lpfilter = 'yes'; cfg.lpfreq = 35; dataFIC_LP = ft_preprocessing(cfg); cfg = []; cfg.keeptrials = 'yes'; timelockFIC = ft_timelockanalysis(cfg, dataFIC_LP); %% % preprocess and timelock condition 2 cfg = []; cfg.dataset = 'Subject01.ds'; cfg.trialdef.eventtype = 'backpanel trigger'; cfg.trialdef.prestim = 1; cfg.trialdef.poststim = 2; cfg.trialdef.eventvalue = 9; cfg = ft_definetrial(cfg); cfg.trl([2, 3, 4, 30, 39, 40, 41, 45, 46, 47, 51, 53, 59, 77, 85],:) = []; cfg.channel = {'MEG', '-MLP31', '-MLO12'}; cfg.demean = 'yes'; cfg.baselinewindow = [-0.2 0]; cfg.lpfilter = 'yes'; cfg.lpfreq = 35; dataFC_LP = ft_preprocessing(cfg); cfg = []; cfg.keeptrials = 'yes'; timelockFC = ft_timelockanalysis(cfg, dataFC_LP); %% % prepare neighbours cfg_neighb = []; cfg_neighb.method = 'distance'; neighbours = ft_prepare_neighbours(cfg_neighb, dataFC_LP); %% stats cfg = []; cfg.neighbours = neighbours; cfg.channel = {'MEG'}; cfg.latency = [0 1]; cfg.method = 'montecarlo'; cfg.statistic = 'indepsamplesT'; cfg.correctm = 'cluster'; cfg.clusteralpha = 0.05; cfg.clusterstatistic = 'maxsum'; % cfg.minnbchan = 2; % I switched this off to be sure that it isn't % causing the problem cfg.tail = 0; cfg.clustertail = 0; cfg.alpha = 0.025; cfg.numrandomization = 100; design = zeros(1,size(timelockFIC.trial,1) + size(timelockFC.trial,1)); design(1,1:size(timelockFIC.trial,1)) = 1; design(1,(size(timelockFIC.trial,1)+1):(size(timelockFIC.trial,1) + size(timelockFC.trial,1)))= 2; cfg.design = design; cfg.ivar = 1; %% % this works [stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); % but this doesn't cfg.avgoverchan = 'yes'; [stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); % this doesn't help cfg.neighbours = []; [stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); % but this does cfg.correctm = 'bonferoni'; [stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); My own script had the design adapted to a dependent-samples t-test, and it behaved in the same way. I got around the issue by collapsing data over channels of interest and then feeding it in to FieldTrip as a single-channel dataset.


Eelke Spaak - 2014-06-10 15:50:50 +0200

*** Bug 2606 has been marked as a duplicate of this bug. ***


Eelke Spaak - 2014-06-10 15:54:21 +0200

In ft_statistics_montecarlo (lines 163-190), there is some if/elseing in which a proper cfg.connectivity is created based on the cfg-structure. I added the special case where avgoverchan=yes, such that connectivity is set to true(1), fixing the error. Also, I removed the requirement to specify neighbours from statistics_wrapper (lines 259-263) in case avgoverchan=yes (since we don't need neighbours if we're not clustering across channels). bash-4.1$ svn commit ft_statistics_montecarlo.m private/statistics_wrapper.m Sending ft_statistics_montecarlo.m Sending private/statistics_wrapper.m Transmitting file data .. Committed revision 9613.


Eelke Spaak - 2014-06-10 16:02:57 +0200

forgot to also add this one bash-4.1$ svn commit test/test_bug2606.m Adding test/test_bug2606.m Transmitting file data . Committed revision 9614.


Robert Oostenveld - 2019-08-10 12:29:01 +0200

This closes a whole series of bugs that have been resolved (either FIXED/WONTFIX/INVALID) for quite some time. If you disagree, please file a new issue describing the issue on https://github.com/fieldtrip/fieldtrip/issues.