# Problems with second level source statistics for multi plew subjects and firsty level stats - solved :-)

Jess R. Kerlin jrkerlin at UCDAVIS.EDU
Sat Dec 20 01:14:05 CET 2008

```Regarding  my previous email:

I got the tutorial code to move forward by editing source_wrapper. I
don't know if this is a bug or something else is wrong which will nail
me later.

Editing get_source_trial in source_wrapper  :

if isfield(varargin{1}, 'inside')
fprintf('only selecting voxels inside the brain for statistics
(%.1f%%)\n', 100*length(varargin{1}.inside)/prod(varargin{1}.dim));
%  for j=prod(dim(2:end)):-1:1 comment out; jk
%  dat((j-1).*dim(1) + varargin{1}.outside, :) = []; jk
dat(varargin{1}.outside, :) = 0; % replaced formula jk
% end comment out; jk
end

Cheers,
Jess

Jess R. Kerlin wrote:
> Dear FTrippers,
>
> I've been replicating the beamformer tutorial to the letter, and
> arrived at problem which may be related to the one described below.
>
> Running :
> stat = sourcestatistics(cfg, sourceSTAT);
>
> Gives the error:
>
> ???  Index of element to remove exceeds matrix dimensions.
>
> Error in ==>
> /home/jrkerlin/matlab/EEGLAB/fieldtrip-0.9.8/private/statistics_wrapper.m
> (get_source_trial)
> On line 443  ==>     dat((j-1).*dim(1) + varargin{1}.outside, :) = [];
>
> Error in ==>
> /home/jrkerlin/matlab/EEGLAB/fieldtrip-0.9.8/private/statistics_wrapper.m
> On line 179  ==>     [dat, cfg] = get_source_trial(cfg, varargin{:});
>
> Error in ==>
> /home/jrkerlin/matlab/EEGLAB/fieldtrip-0.9.8/sourcestatistics.m
> On line 127  ==>   stat = statistics_wrapper(cfg, varargin{:});
>
> My sourceSTAT.trial(1).pow is a 1 by 2652 double array (so the dim in
> get_source_trial is the same) , which may or may not be the proper
> dimensions for pow (sourceSTAT.dim = [17 13 12] ). If not, exactly
> how/where would I add the proper dim field?
>
> I've also tried running  freqanalysis and sourcestatistics  with a
> recent release (20081218), with the same results.
>
> Any advice would be greatly appreciated.
>
> Thanks,
> Jess
>
> Michael Wibral wrote:
>> Dear listusers,
>>
>> in several previous mails I have reported about problems occuring when:
>>
>> 1) doing single subjects source analysis using reverse-normalized
>> grids (thanks to Ingrid's tutorial), common filters for the two
>> conditions and generating single trial source data 2) then performing
>> single subject sourcestatistics (getting a sparse data representation
>> with a stat field)
>> 3) then doing second level sourcestatistics (which didn't work)
>>
>> I am happy to report these problems are solved :-). I actually just
>> overlooked a WARNING:... when doing single subject sourceanalysis and
>> sourcestatistics (1st level) is says that you yourself have to add a
>> dim field by hand, when trying to use
>> clusterrandanalysis/sourcestatistics later. I now simply added a dim
>> field to both, to the data and to the cfg for the second level source
>> statistics. The correct choice for this dim field are the dimension
>> of the original, orthogonal, regular grid in MNI space and everything
>> works now.
>>
>>  I just didn't realize that dim can't be all that easily generated
>> automatically by fieldtrip for sparse data and *warped* grids. This
>> is because the warping could - in principle - be such that dim
>> doesn't make any sense anymore, e.g. because points (almost) switch
>> places along a certain dimension (if they differ in the other
>> coordinates). So neighborhood relations are not well defined a priori
>> in sparse data. Hence, the need for a manual addition of dim in this
>> case (please correct me me if any of the above is wrong).
>>
>> The version I used and that I can confirm to work was 20081208.
>>
>> Many thanks for all your support,
>> 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
>> 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