[FieldTrip] Error in source localisation statistics

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Thu Feb 21 16:10:18 CET 2019


Hi Xavier,

I see. Unfortunately you happened to end up in a corner of the code that is a bit shaky, and possibly not well tested (although once upon a time it may have worked). This may be due to the fact that you are trying to ‘fool’ fieldtrip into treating a multiple subject design as if it’s a single subject design with multiple trials (where each of the trials represents a single condition estimate for a subject), correct? (as a side note: you would want to use ‘depsamplesT’ rather than ‘indepsamplesT’ as your test statistic).

I think that you should not do this. First, as you have noticed this leads to downstream problems (specifically handcrafting combined data could easily lead to a user-error causing the data to deviate according to what FieldTrip can handle, but also using the cfg.rawtrial option of ft_sourceanalaysis historically and notoriously is a dysfunctional (or at least unpredictable in its behavior) option. (nominated to be removed once we find the time). Next to this, even though it seems your geometrical data (i.e. electrode positions, headmodel, sourcemodel) are shared across subjects, the covariance structure of the data will for sure be subject-specific, and I don’t think that it is a good idea to combine data across subjects before sourceanalysis.

This is what I would do:

for each subject do:

ft_timelockanalysis with the subject-specific data combined across conditions
ft_timelockanalysis with the subject-specific data for each of the conditions separately

ft_sourceanalysis with the subject-specific data combined across conditions AND cfg.lcmv.keepfilter = ‘yes’; (and don’t specify cfg.keeptrials or cfg.rawtrial)

input the source.avg.filter from the previous step into the cfg

for each condition (in each subject) do:
  ft_sourceanalysis


after this you should have a set of Nsubject times number of conditions source structures

then you should be able to use ft_sourcestatistics with cfg.statisti = ‘depsamplesT’:

ft_sourcestatistics(cfg, source{:}); % if in the previous for-loop you have stored the individual source-objects into a cell-array this syntax works (and is much cleaner than either ft_sourcestatistics(cfg, source1a, source2a ,…etc), and cleaner than going through ft_sourcegrandaverage).

ft_sourcedescriptives should not be needed in this recipe.

Good luck,
Jan-Mathijs


J.M.Schoffelen, MD PhD
Senior Researcher, VIDI-fellow - PI, language in interaction
Telephone: +31-24-3614793
Physical location: room 00.028
Donders Centre for Cognitive Neuroimaging, Nijmegen, The Netherlands



On 20 Feb 2019, at 21:32, Xavier Vrijdag <x.vrijdag at auckland.ac.nz<mailto:x.vrijdag at auckland.ac.nz>> wrote:

Hi Jan-Mathijs,

Thank you for your help. I went in to have a look at what is going on inside those loops and found that the error is occurring in iteration 6, when the field source.trial(1).label is concatenated. It uses the indexes for the big data cells (ori, mom & filter) which clearly doesn’t work on the small cell with the labels. This seems to me that this is a bug.

I added a piece of code in front of the loop that was giving the error (before line 177 and make the if and elseif.
      if isequal(fn{i}, 'label')
            for j=1:nrpt
                    source_new.label(:,j) = source.trial(j).label;
            end
      elseif iscell(dat)

This worked to circumvent the problem. However, I do get the warning that the dimord of “ori” and “df” could not be determined. When using this cleaned source struct in source statistics I get further errors.

It looks like an issue with how the source struct is built by the source analysis function with trials, and lateron needs to be restructured. SO I would like to know what is the needed structure for ft_sourcestatistics, so we can adjust the code correctly.

Regards,

Xavier


From: fieldtrip <fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>> on behalf of "Schoffelen, J.M. (Jan Mathijs)" <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>
Reply-To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Date: Wednesday, 20 February 2019 at 2:59 AM
To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Subject: Re: [FieldTrip] Error in source localisation statistics

Hi Xavier,

My recommendation here would be to use the matlab debugger and inspect the cause of the error. The ‘Index exceeds array bounds’ is quite a clear error message, and suggests that there is a mismatch between the number of elements in dat/val, and the numbers represented in indx(k).

Good luck,

Jan-Mathijs


On 18 Feb 2019, at 07:23, Xavier Vrijdag <x.vrijdag at auckland.ac.nz<mailto:x.vrijdag at auckland.ac.nz>> wrote:

Hello,

I have a dataset from an experiment where 12 participants were exposed to 3 levels of nitrous oxide, while I measured their EEG. I also have a baseline recording. I took for each exposure (and baseline) a 1 minute sample for further analysis. I want to do source localization to better understand  which parts of the brain are involved. I don’t have MRI scans of my participants, so I used the standard MRI and BEM. I would like to thanks the persons who made the various manuals and analysis examples on the website, as they helped me tremendously to do this analysis.

After cleaning and preprocessing, I combined the datasets into one for further analysis. I also chose to make 5 sec “trials” for further analysis. For this source analysis I loaded the data of 1 exposure and the baseline data, to compare them.

        %Calculate the channel covariance matric
        cfg = [];
        cfg.covariance = 'yes';
        cfg.covariancewindow = 'all';
        cfg.keeptrials  = 'yes';
        timelock = ft_timelockanalysis(cfg, data_filt);

        %Global filter
        cfg = [];
        cfg.headmodel = vol;
        cfg.elec = elec_aligned;
        cfg.grid = grid;
        cfg.method = 'lcmv';
        cfg.lcmv.projectnoise='yes'; %needed for neural activity index
        cfg.lcmv.fixedori = 'yes';  %Project onto largest variance orientation
        cfg.lcmv.keepfilter = 'yes'; %Keep the beamformer weights
        cfg.lcmv.lambda = '5%'; %Regularise a little
        cfg.rawtrial    = 'yes';      % project each single trial through the filter.
        cfg.keeptrials  = 'yes';
        source = ft_sourceanalysis(cfg, timelock);

        cfg = [];
        cfg.dim         = source.dim;
        cfg.method      = 'montecarlo';
        cfg.statistic   = 'ft_statfun_indepsamplesT';
        cfg.parameter   = 'pow';
        cfg.correctm    = 'cluster';
        cfg.numrandomization = 1000;
        cfg.alpha       = 0.05; % note that this only implies single-sided testing
        cfg.tail        = 0;
        cfg.design(1,:) = [1:nTrials 1:nTrials];
        cfg.design(2,:) = [ones(1,nTrials) ones(1,nTrials).*2];
        cfg.uvar        = 1; % row of design matrix that contains unit variable (in this case: trials)
        cfg.ivar        = 2; % row of design matrix that contains independent variable (the conditions)
        stat = ft_sourcestatistics(cfg, source);

After the source analysis the source statistics script calls the checkdata script and I get the following error:

Index exceeds array bounds.

Error in ft_datatype_source (line 183)
            val{indx(k)}(1,:,:,:) = dat{indx(k)};

Error in ft_checkdata (line 278)
  data = ft_datatype_source(data);

Error in ft_sourcestatistics (line 94)
  varargin{i} = ft_checkdata(varargin{i}, 'datatype', 'source', 'feedback', 'no');

Error in sourcelocalisation_N2O (line 114)
        stat = ft_sourcestatistics(cfg, source);

The source struct has the following content:
      time: [1×15360 double]
       dim: [24 31 25]
    inside: [18600×1 logical]
       pos: [18600×3 double]
    method: 'rawtrial'
     trial: [1×24 struct]
        df: 24
       cfg: [1×1 struct]

With source.trial:
  1×24 struct array with fields:
    ori
    pow
    mom
    noise
    filter
    label
    filterdimord

I would like your help to understand the error and how to fix it.

Regards,

Xavier Vrijdag

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20190221/f14fa3db/attachment-0002.html>
-------------- next part --------------
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202


More information about the fieldtrip mailing list