Back to the main page.

Bug 2558 - ft_timelockstatistics crashes because of dimord

Status CLOSED FIXED
Reported 2014-05-02 13:14:00 +0200
Modified 2015-07-15 13:31:24 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P5 blocker
Assigned to: Jan-Mathijs Schoffelen
URL:
Tags:
Depends on:
Blocks:
See also:

Heidi - 2014-05-02 13:14:29 +0200

I run into problems when trying to run a cluster-based permutation test on my ERF data. I believe the problem arises because I don't have any frequency dimension, so the "dimord" variable becomes a problem. This is what I tried to run: gavg_erf{7} ans = individual: [23x274x1560 double] time: [1x1560 double] label: {274x1 cell} dimord: 'subj_chan_time' cfg: [1x1 struct] avg: [274x1560 double] % compare gavg_erf{7} and gavg_erf{8} (high vs low context) cfg = []; cfg.method = 'distance'; load('/home/predatt/heisol/3018012.05_heisol/meg/gavg/neighbours.mat'); cfg = []; cfg.channel = 'MEG'; cfg.latency = [0.4 0.7]; cfg.avgovertime = 'no'; cfg.avgoverchan = 'no'; %cfg.avgoverfreq = 'yes'; % <--- is this necessary? cfg.parameter = 'avg'; cfg.method = 'montecarlo'; cfg.correctm = 'cluster'; cfg.statistic = 'depsamplesT'; cfg.alpha = 0.05; cfg.clusteralpha = 0.05; cfg.neighbours = neighbours; cfg.correctm = 'no'; cfg.correcttail = 'prob'; cfg.numrandomization = 1000; Nsub = 23; cfg.design(1,1:2*Nsub) = [ones(1,Nsub) 2*ones(1,Nsub)]; cfg.design(2,1:2*Nsub) = [1:Nsub 1:Nsub]; cfg.ivar = 1; % the 1st row in cfg.design contains the independent variable cfg.uvar = 2; % the 2nd row in cfg.design contains the subject numbe stat = ft_timelockstatistics(cfg,gavg_erf{7},gavg_erf{8}); **** Error message from Matlab: Index exceeds matrix dimensions. Error in prepare_timefreq_data (line 349) dat(trialsel,:,:,:) = varargin{c}.dat(:, chansel, freqsel, timesel); Error in statistics_wrapper (line 235) [cfg, data] = prepare_timefreq_data(cfg, varargin{:}); Error in ft_timelockstatistics (line 108) [stat, cfg] = statistics_wrapper(cfg, varargin{:});


Eelke Spaak - 2014-05-02 13:21:05 +0200

Hi Heidi, Could you post the data you are using (gavg_erf{7} and {8}) somewhere? I suspect the file will be several MBs at least, in that case maybe put it on /home/common/temporary? Then I'll have a look.


Robert Oostenveld - 2014-05-02 13:48:41 +0200

(In reply to Eelke Spaak from comment #1) Hi Eelke, I just tried reproducing it with stimulated data: the following gives the same error. ------------------------------ nsubj = 23; nchan = 274; ntime = 1560; gavg_erf7.individual = randn(nsubj,nchan,ntime); gavg_erf7.time = (1:ntime)/1000; for i=1:nchan gavg_erf7.label{i} = num2str(i); end gavg_erf7.dimord = 'subj_chan_time'; gavg_erf7.avg = randn(nchan, ntime); gavg_erf7.cfg = []; gavg_erf8.individual = randn(nsubj,nchan,ntime); gavg_erf8.time = (1:ntime)/1000; for i=1:nchan gavg_erf8.label{i} = num2str(i); end gavg_erf8.dimord = 'subj_chan_time'; gavg_erf8.avg = randn(nchan, ntime); gavg_erf8.cfg = []; cfg = []; cfg.channel = 'all'; % modification w.r.t. original bug report cfg.latency = [0.4 0.7]; cfg.avgovertime = 'no'; cfg.avgoverchan = 'no'; %cfg.avgoverfreq = 'yes'; % <--- is this necessary? cfg.parameter = 'avg'; cfg.method = 'montecarlo'; cfg.correctm = 'cluster'; cfg.statistic = 'depsamplesT'; cfg.alpha = 0.05; cfg.clusteralpha = 0.05; cfg.neighbours = []; % modification w.r.t. original bug report cfg.correctm = 'no'; cfg.correcttail = 'prob'; cfg.numrandomization = 1000; cfg.design(1,1:2*nsubj) = [ones(1,nsubj) 2*ones(1,nsubj)]; cfg.design(2,1:2*nsubj) = [1:nsubj 1:nsubj]; cfg.ivar = 1; % the 1st row in cfg.design contains the independent variable cfg.uvar = 2; % the 2nd row in cfg.design contains the subject numbe stat = ft_timelockstatistics(cfg, gavg_erf7,gavg_erf8); selected 274 channels selected 301 time bins selected 1 frequency bins Index exceeds matrix dimensions. Error in prepare_timefreq_data (line 349) dat(trialsel,:,:,:) = varargin{c}.dat(:, chansel, freqsel, timesel); Error in statistics_wrapper (line 235) [cfg, data] = prepare_timefreq_data(cfg, varargin{:}); Error in ft_timelockstatistics (line 108) [stat, cfg] = statistics_wrapper(cfg, varargin{:}); Error in test_bug2558 (line 53) stat = ft_timelockstatistics(cfg, gavg_erf7,gavg_erf8); ------------------------------ I will add this as a test script.


Robert Oostenveld - 2014-05-02 13:55:40 +0200

mac011> svn commit private/statistics_wrapper.m test/test_bug2558.m Sending private/statistics_wrapper.m Adding test/test_bug2558.m Transmitting file data .. Committed revision 9466. The error is somewhere deep inside prepare_timefreq_data, which is a function that we should try to move away from, and replace it by ft_selectdata. I suggest for now that we find a workaround for Heidi.


Eelke Spaak - 2014-05-02 14:04:09 +0200

Heidi, for some time now it is no longer required to compute a grand-average (with keepindividual=yes) before doing statistics. Instead, you can also call ft_timelockstatistics like so: stat = ft_timelockstatistics(cfg, erfs7{:}, erfs8{:}); where erfs7 and erfs8 are cell-arrays with one element for each of your subjects. Each element corresponds to the output of ft_timelockanalysis for a single subject. Does this help you for now? As Robert indicates, the bug you encountered might take some more time to properly fix.


Eelke Spaak - 2014-05-02 14:04:38 +0200

(In reply to Eelke Spaak from comment #4) ...forgot to add: the above calling syntax does not result in a bug.


Heidi - 2014-05-07 18:36:55 +0200

Thanks Eelke, I was able to make it work using the following code: >> gavg_erf ans = Columns 1 through 5 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 6 through 10 [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] Columns 11 through 12 [1x1 struct] [1x1 struct] >> gavg_erf{1} ans = individual: [24x274x1560 double] time: [1x1560 double] label: {274x1 cell} dimord: 'subj_chan_time' cfg: [1x1 struct] avg: [274x1560 double] %% prepare data Nsub = 24; for cond=1:12 for sb=1:Nsub savg_erf{cond}{sb} = gavg_erf{1}; savg_erf{cond}{sb}.avg = squeeze(gavg_erf{cond}.individual(sb,:,:)); savg_erf{cond}{sb} = rmfield(savg_erf{cond}{sb},'individual'); savg_erf{cond}{sb}.dimord = 'chan_time'; end end clear gavg_erf; %% N400 % conditions: 7 = constr, 8 = unconstr cfg = []; cfg.channel = 'MEG'; cfg.latency = [0.3 0.8]; cfg.avgovertime = 'no'; cfg.avgoverchan = 'no'; cfg.parameter = 'avg'; cfg.method = 'montecarlo'; cfg.correctm = 'cluster'; % multiple-comparison correction cfg.statistic = 'depsamplesT'; cfg.tail = 0; % two-sided test cfg.alpha = 0.05; cfg.correcttail = 'alpha'; % bonferroni correction cfg.clusteralpha = 0.01; cfg.clusterstatistic = 'maxsum'; load('/home/predatt/heisol/3018012.05_heisol/meg/gavg/neighbours.mat'); cfg.neighbours = neighbours; % this was previously computed cfg.numrandomization = 1000; design = zeros(2,2*Nsub); for i = 1:Nsub design(1,i) = i; end for i = 1:Nsub design(1,Nsub+i) = i; end design(2,1:Nsub) = 1; design(2,Nsub+1:2*Nsub) = 2; cfg.design = design; cfg.uvar = 1; % "unit variable" (subject) cfg.ivar = 2; % independent variable (condition) contexteffect = ft_timelockstatistics(cfg,savg_erf{7}{:},savg_erf{8}{:}); % the {:} means "across all subjects" (In reply to Eelke Spaak from comment #4)


Jan-Mathijs Schoffelen - 2015-05-08 15:48:34 +0200

test function started to fail, due to the outdated definition of the grandaverage type timelock structures, on which the current code chokes (having both an 'individual' and 'avg' field). I'll update the test function


Jan-Mathijs Schoffelen - 2015-05-08 15:54:44 +0200

testfunction updated.