[FieldTrip] Some Questions on the resample design

Johanna Zumer johanna.zumer at donders.ru.nl
Tue May 7 14:53:40 CEST 2013


Dear Chao,

I'm not familiar with this piece of code, but I had a quick look.  Line
276, with the 'sort' command, is testing for the number of unique 'rows'
(line 278).  It then uses this information to modify the value of
cfg.numrandomization (line 283 which you have not displayed), which is
reduced if not enough unique information to do the requested number of
randomizations.   Then (I think) the actual randomization should be
occuring in subsequent lines of code (292-296).    Note also that this part
of code is only reached if max(design(cfg.uvar,:)) < 20.

Does that help?    Maybe someone else with more experience in this section
of code can comment as well?

Or if you still find that it indeed is not randomizing, you can file a bug
here (http://bugzilla.fcdonders.nl/), ideally with a small test script.

Cheers,
Johanna




2013/5/7 Chao Wang <chaowang0704 at gmail.com>

> I'm sorry to make a mistake just now. The previous message sent didn't
> fullfill my meaning.
>
> I carefully inspected the code in the function *resampledesign* but I was
> quite confused by the codes in the bootstrap section (For paired design,
> the design matrix should be like this, design(1,:)=[1:N 1:N], design(2,1:N)=1
> and design(2,N+1:2*N)=2 and N is for example the subject number; and
> cfg.uvar=2):
> 91     Nvar  = size(design,1);   % number of factors or regressors
> 92     Nrepl = size(design,2);   % number of replications
> ...
> ...
> 248   units = design(cfg.uvar,:);
> 249   for k = 1:length(unique(units))
> 250     sel = find(units==k);
> 251     indx(:,k) = sel;
> 252     Nrep(k)   = length(sel);
> 253   end
> 254   resample = zeros(cfg.numrandomization, Nrepl);
> ...
> ...
> 274   tmp = zeros(cfg.numrandomization*10, Nrepl/Nrep(1));
> 275   for i=1:cfg.numrandomization*10
> 276      tmp(i,:) = *sort*(randsample(1:Nrepl/Nrep(1), Nrepl/Nrep(1)));
> 277   end
>
> 278   tmp = unique(tmp, 'rows');
> 279   fprintf('found %d unique rows in bootstrap matrix of %d bootstraps',
> size(tmp,1), cfg.numrandomization*10);
> ...
> ...
> 292   for i=1:cfg.numrandomization
> 293      for k=1:size(indx,1)
> 294        resample(i,indx(k,:)) = indx(k,tmp(i,:));
> 295      end
> 296   end
>
> My question was on the code in 276 line. These code was to generate a
> number of rand numbers (about cfg.numrandomization lines) in the range of 1
> to Nrepl/Nrep(1), in which Nrepl is the number of replications in the
> design and Nrep is the number of repetition (Nrep(:)=2 for paired design).
> If the function '*sort*' is used, then every row of matrix tmp is the
> same, which will be 1,2,..., Nrepl/Nrep(1). And this will lead the 278 line
> to the result: temp=1:Nrepl/Nrep(1) (because of the function unique). This
> result is by no means what we want, I think. What we do want is several
> rows numbers with same range but with distinct orders. Only in this way,
> can we guarantee that each resample is not the same.
>
>
>
> On Tue, May 7, 2013 at 2:35 PM, Chao Wang <chaowang0704 at gmail.com> wrote:
>
>> I
>> have been using field-trip. Recently, I tried to use it for statistic
>> test by non-parametric method, e.g. bootstrap and permutation. As usual,
>> the two method involve resample original data with or without replacement.
>> I carefully inspected the code in the function *resampledesign* but I
>> was quite confused by the method in the bootstrap section:
>>
>> 254resample = zeros(cfg.numrandomization, Nrepl);
>>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20130507/851c4f05/attachment.html>


More information about the fieldtrip mailing list