# Bootstrapping using a random number generator?

1. Mar 9, 2013

### Jamin2112

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):

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);

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