Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Bootstrapping using a random number generator?

  1. Mar 9, 2013 #1
    I've been using this MATLAB function a guy gave me to crunch numbers on some EEG data from patients. If you have any idea what it does, let me know. From what I can tell it's somehow using random numbers to calculate the probability of getting certain power values? He doesn't comment his code, which makes it harder for me to figure this out.


    Code (Text):

    function [map,up,low,Z,mask]=test_stat_wavelet(x,t,fw,nb,tbase,p)
    %function [map,up,low,Z,mask]=test_stat_wavelet(x,t,fw,nb,tbase,p)
    fs=1/diff(t(1:2));
    [C,CS,Call,C0]=time_frequency_wavelet(x,fw,fs,1,1,'CPU');
    map=zeros(length(t),length(fw));
    hh=waitbar(0,'testing');
    for i=1:length(fw)
        ax=squeeze(Call(:,i,:));
        stat=bootstrap_mean(ax,nb);
        map(:,i)=mean(stat,1)';
        up(:,i)=quantile(stat,1-p,1)';
        low(:,i)=quantile(stat,p,1)';
        waitbar(i/length(fw));
    end
    close(hh);
    mm=mean(map(t>tbase(1) & t<tbase(2),:),1);
    s=std(map(t>tbase(1) & t<tbase(2),:),0,1);
    Z=(map-ones(size(map,1),1)*mm)./(ones(size(map,1),1)*s);
    mask=zeros(size(Z));
    mask(low>ones(size(map,1),1)*mm)=1;

    function y=bootstrap_mean(x,n)
    y=zeros(n,size(x,1));fast=1;
    nt=size(x,2);
    yg=double(y);
    xg=double(x);
    ix=round(rand(n,nt)*nt);
    ix(ix<1)=1;ix(ix>nt)=nt;
    ix=single(ix);
    if(fast)
        xgb=zeros(n,size(x,1),size(x,2));
        for k=single(1:n)
            xgb(k,:,:)=x(:,ix(k,:));
        end
        y=mean(xgb,3);
    else
        for k=single(1:n)
            qx=ix(k,:);
            yg(k,:)=mean(xg(:,qx),2)';
        end
        y=double(yg);
    end
     
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Bootstrapping using a random number generator?
  1. Random Number generator? (Replies: 12)

Loading...