Problem running source grand average a nd source statistics

jan-mathijs schoffelen j.schoffelen at PSY.GLA.AC.UK
Wed Nov 5 15:04:43 CET 2008


Hi Michael,

> stat: [3297x1 double]

This indicates that your singlesubjects are indeed sparsified, so  
that when you getsubfield this guy, you end up with fewer data-points  
than expected (which is Nvoxel==prod(dim)).

Does this give you enough guidelines to fix it?

JM


On Nov 5, 2008, at 1:50 PM, Michael Wibral wrote:

> Dear Ingrid, dear Jan-Mathijs
>
> I guess Ingrid is indeed correct, as all my datasets have the same  
> dimension of the stat field and of the inside/outside fields. I was  
> actually also supplying the dim field from the template to all  
> datasets, so the product of dims' should be the same everywhere,  
> but that hasn't really solved the problem. The length of the inside  
> field is 3297, the outside field is 3129, their sum is 6426 which  
> is identical to the product of dimensions of the template grid  
> which are 17 x 21 x 18 =6426. So I am really a bit puzzled here...
>
> Anyway, here's the code I use, maybe someone a really stupid error,  
> that I simply overlooked:
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> % FIRST I prepare a file with the data and the settings for the  
> statistics that is later read in again:
> % datapath = '/data/home1/ctillman/data/MooneyMEEGFieldtripAnalysis/ 
> DICSBeamformingMW200808/Stats/';
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> DesignData1 = {
>     'ABA04_Up_StatSources.mat'
>     'IFS20_Up_StatSources.mat';
>     'IKE28_Up_StatSources.mat';
>     'JHA07_Up_StatSources.mat';
>     'JPA05_Up_StatSources.mat';
>     'MKA21_Up_StatSources.mat';
>     'MMA07_Up_StatSources.mat';
>     'PSS16_Up_StatSources.mat';
>     'SNI05_Up_StatSources.mat';
>     'UWA31_Up_StatSources.mat';
>
>     };
>
> DesignData2 = {
>     'ABA04_In_StatSources.mat';
>     'IFS20_In_StatSources.mat';
>     'IKE28_In_StatSources.mat';
>     'JHA07_In_StatSources.mat';
>     'JPA05_In_StatSources.mat';
>     'MKA21_In_StatSources.mat';
>     'MMA07_In_StatSources.mat';
>     'PSS16_In_StatSources.mat';
>     'SNI05_In_StatSources.mat';
>     'UWA31_In_StatSources.mat';
>
>     };
>
> %  The statistics configuration
> cfg = [];
> nSubjects = min(length(DesignData1),length(DesignData2));
> a = [1:nSubjects];
> b = ones(1,nSubjects);
> cfg.design = [a a; b (2*b)];
> cfg.ivar = 2; % independent variable: condition
> cfg.uvar = 1; % subjects
> cfg.method = 'montecarlo';
> cfg.correctm = 'cluster';
> cfg.clusteralpha     = 0.01;
> cfg.alpha            = 0.05;
> cfg.clusterstatistic = 'maxsum';
> cfg.numrandomization = 500; %2000;
> cfg.threshold = 0.01;
> cfg.parameter = 'stat';
> cfg.statistic = 'depsamplesT';
>
> % create output file
> OutFileName = strcat(datapath,'DesignStat2008_11_04.mat');
> save(OutFileName, 'DesignData1', 'DesignData2', 'cfg', 'datapath');
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> % SECOND I read in this file and the template and try to perform  
> grandaveraging and sourcestatistics at the second level:
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> function [] = StatisticsDICS(DesignStatLCMVFile);
>
>
> template = load('/data/home1/ctillman/data/ 
> MooneyMEEGFieldtripAnalysis/DICSBeamformingMW200808/Grids/ 
> MNItemplate_231008_-1p5iws.mat');
> Nx = length(template.template_grid.xgrid)
> Ny = length(template.template_grid.ygrid)
> Nz = length(template.template_grid.zgrid)
>
> load(DesignStatLCMVFile); % contains datapath, DesignData1,  
> DesignData2, cfg
>
> % Load Data from DesignData1,2 automatically ensuring matching sizes
> % please ensure that data pairs are OK if using paired statistics !
>
>
> for i = 1:min(length(DesignData1),length(DesignData2))
>     m=strcat('loading dataset#:', num2str(2*i-1));
>     disp(m);
>     fullname1 = strcat(datapath,DesignData1{i,1});
>     Data1{i} = load(fullname1);
>     m=strcat('loading dataset#:', num2str(2*i));
>     disp(m);
>     fullname2 = strcat(datapath,DesignData2{i,1});
>     Data2{i} = load(fullname2);
> end
>
> % Fixing the structure properties
>
> for l = 1:size(Data1,2)
>
>    Data1{l}.SourceStat.xgrid = template.template_grid.xgrid;
>    Data1{l}.SourceStat.ygrid = template.template_grid.ygrid;
>    Data1{l}.SourceStat.zgrid = template.template_grid.zgrid;
>    Data1{l}.SourceStat.dim = [Nx Ny Nz];
>    Data1{l}.SourceStat.pos = template.template_grid.pos;
>    Data1{l}.SourceStat.inside = template.template_grid.inside;
>    Data1{l}.SourceStat.outside = template.template_grid.outside;
>    Data1{l} = Data1{l}.SourceStat;
>
>
>     Data2{l}.SourceStat.xgrid = template.template_grid.xgrid;
>     Data2{l}.SourceStat.ygrid = template.template_grid.ygrid;
>     Data2{l}.SourceStat.zgrid = template.template_grid.zgrid;
>     Data2{l}.SourceStat.dim = [Nx Ny Nz];
>     Data2{l}.SourceStat.pos = template.template_grid.pos;
>     Data2{l}.SourceStat.inside = template.template_grid.inside;
>     Data2{l}.SourceStat.outside = template.template_grid.outside;
>     Data2{l} = Data2{l}.SourceStat;
>
> end
>
> % prepare the statistics by computing the grandaverage with individual
> % subject data retained
> % Compute grand average for Condition 1 and 2
> cfgGA = [];
> cfgGA.keepindividual = 'yes';
> cfgGA.parameter='stat';
> % create command strings for the computaion:
> commandstr1 = strcat ('DataGA1', '=sourcegrandaverage(cfgGA');
> commandstr2 = strcat ('DataGA2',  '=sourcegrandaverage(cfgGA');
>
> for l = 1 : length(Data1)
>     commandstr1 = strcat(commandstr1, ',Data1{', num2str(l) , '}');
>     commandstr2 = strcat(commandstr2, ',Data2{', num2str(l) , '}');
> end
> % finalize command strings
> commandstr1=strcat(commandstr1,');')
> commandstr2=strcat(commandstr2,');')
> eval(commandstr1) % yields DataGA1;
> eval(commandstr2) % yields DataGA2;
>
> clear Data1; clear Data2; % no longer needed we now have DataGA1,2
>
> %SourceStatsitics cfg is known from the design file!
> sourceStat = sourcestatistics(cfg, DataGA1, DataGA2);
> OutFilename = ...
> strcat(datapath,  
> 'SourceStatisticsLCMV_denoisedDataAndNewGrids_1000rand_',DesignData1 
> {i,1}(7:end-4),'_calpha',num2str(cfg.clusteralpha),  
> '_alpha_',num2str(cfg.alpha),'.mat');
> save(OutFilename, 'sourceStat');
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
> %%%%%%%%%%%%%%%%%%%
>
>
> Here's the inforamtion from the datasets and the template:
>
> Information of a dataset after processing/preparing for  
> sourcegrandaverage:
>
>
> stat: [3297x1 double]
>          df: 134
>     critval: [-1.9778 1.9778]
>        prob: [3297x1 double]
>        mask: [3297x1 logical]
>         dim: [17 21 18]
>      inside: [1x3297 double]
>     outside: [1x3129 double]
>         pos: [6426x3 double]
>         cfg: [1x1 struct]
>       xgrid: [-80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60  
> 70 80]
>       ygrid: [-120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0  
> 10 20 30 40 50 60 70 80]
>       zgrid: [-80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60  
> 70 80 90]
>
> Information of the template:
> xgrid: [-80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80]
>       ygrid: [-120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0  
> 10 20 30 40 50 60 70 80]
>       zgrid: [-80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60  
> 70 80 90]
>         dim: [17 21 18]
>         pos: [6426x3 double]
>      inside: [1x3297 double]
>     outside: [1x3129 double]
>
> The onlz thing that I see varying fron dataset to dataset is the df  
> field.
>
> Any help appreciated,
> Michael
>
>
>> -----Ursprüngliche Nachricht-----
>> Von: "Ingrid Nieuwenhuis" <ingrid.nieuwenhuis at FCDONDERS.RU.NL>
>> Gesendet: 05.11.08 14:02:04
>> An: FIELDTRIP at NIC.SURFNET.NL
>> Betreff: Re: [FIELDTRIP] Problem running source grand average and  
>> source statistics
>
>
>> Dear Michael and Jan-Mathijs,
>>
>> If the same procedure is followed as on the wiki, the inside of  
>> the template
>> grid is copied to the single subjects, so by definition also the
>> 'sparsified' single subjects sources should all have the same  
>> amount of
>> (inside) voxels. So point 2 J-M raised can't be it, point 1 could  
>> well be:
>> Because in line 115 dat's size is defined as (Nvoxels, Nsubj) and  
>> Nvoxels is
>> the product of the dim.
>>
>> Best Ingrid
>>
>> -----Original Message-----
>> From: FieldTrip discussion list [mailto:FIELDTRIP at NIC.SURFNET.NL]  
>> On Behalf
>> Of jan-mathijs schoffelen
>> Sent: Wednesday, November 05, 2008 10:20 AM
>> To: FIELDTRIP at NIC.SURFNET.NL
>> Subject: Re: [FIELDTRIP] Problem running source grand average and  
>> source
>> statistics
>>
>> Dear Michael,
>>
>> I agree with you that a likely cause is that the Nvoxel (which is
>> based on the dimensionality of the first singlesubject-source in the
>> input) varies across subjects. However, this would be strange,
>> because you use the same dipole grid for all subjects. On the other
>> hand: could it be that you 'sparsified' the single subjects? Each
>> subject could have a slightly different number of 'inside' positions.
>> This obviously leads to problems:
>> 1 because the Nvoxel is incorrect in the first place (it's the
>> product of the dim, so the input is assumed to be full 3D, or a
>> linear array with all outside voxels present (either as nans or zeros
>> or whichever number you fancy).
>> 2 because the length of the array per subject varies.
>>
>> Hope this helps,
>>
>> Jan-M
>>
>>
>>
>> On Nov 4, 2008, at 5:35 PM, Michael Wibral wrote:
>>
>>> Dear list users,
>>>
>>> I am having a problem running, source grandaverage and source
>>> statistics (over multiple subjects) on the output of
>>> soucrestatistictics (from multiple trials in single subjects).
>>>
>>> I ran first sourceanalysis supplying the backwads warped grids (as
>>> described in the wiki) to compute filters. Then I ran source
>>> analysis again to extract the single trial source images and the
>>> ran sourcestatistitics on this to get the single subject
>>> statistical images - all this runs fine. I then supply the pos (and
>>> dim) data of the template grid to each structure, replacing the
>>> original pos data (that do not match and of course prohibit using
>>> sourceststatistics and sourcegrandaverage). When trying to do
>>> either a source grand average or a sourcestatistics at the
>>> multisubject level I get the same error:
>>>
>>> subscripted assignment dimension mismatch
>>>  dat(:,i) = tmp(:);
>>>
>>> Error in ==> sourcegrandaverage at 173
>>>
>>>
>>> The corresponding lines of code in sourcegrandaverage are:
>>>
>>> % get the source parameter from each input source reconstruction
>>> % get the inside parameter from each input source reconstruction
>>> for i=1:Nsubject
>>>   % TODO this function should use parameterselection
>>>     if issubfield(varargin{i}, ['avg.' cfg.parameter])
>>>         tmp = getsubfield(varargin{i}, ['avg.' cfg.parameter]);
>>>     else
>>> 	      tmp = getsubfield(varargin{i}, cfg.parameter);
>>>     end
>>>    dat(:,i) = tmp(:);
>>>     tmp = getsubfield(varargin{i}, 'inside');
>>>      inside(tmp,i) = 1;
>>>  end
>>>
>>> I get an identical error when using sourcestatistics at the
>>> multisubject level.
>>> The variable dat(:,i)  is created like this:
>>> dat = zeros(Nvoxel, Nsubject)
>>>
>>>
>>> I suspect that somehow trying to use the 'stat' instead of the
>>> power parameter is a problem (TODO?) or that Nvoxel somehow differs
>>> over the various subjects ??
>>>
>>> Any advice on what to try and test further would very much
>>> appreciated.
>>>
>>> Thanks in advance,
>>> Michael
>>>
>>>
>>> ----------------------------------
>>> The aim of this list is to facilitate the discussion between users
>>> of the FieldTrip  toolbox, to share experiences and to discuss new
>>> ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/
>>> archives/fieldtrip.html and http://www.ru.nl/fcdonders/
>>> fieldtrip.<Michael Wibral.vcf>
>>
>> ----------------------------------
>> The aim of this list is to facilitate the discussion between users  
>> of the
>> FieldTrip  toolbox, to share experiences and to discuss new ideas  
>> for MEG
>> and EEG analysis. See also
>> http://listserv.surfnet.nl/archives/fieldtrip.html and
>> http://www.ru.nl/fcdonders/fieldtrip.
>>
>> ----------------------------------
>> The aim of this list is to facilitate the discussion between users  
>> of the FieldTrip  toolbox, to share experiences and to discuss new  
>> ideas for MEG and EEG analysis. See also http:// 
>> listserv.surfnet.nl/archives/fieldtrip.html and http://www.ru.nl/ 
>> fcdonders/fieldtrip.
>>
>
>
>
> ----------------------------------
> The aim of this list is to facilitate the discussion between users  
> of the FieldTrip  toolbox, to share experiences and to discuss new  
> ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/ 
> archives/fieldtrip.html and http://www.ru.nl/fcdonders/ 
> fieldtrip.<Michael Wibral.vcf>

----------------------------------
The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/archives/fieldtrip.html and http://www.ru.nl/fcdonders/fieldtrip.



More information about the fieldtrip mailing list