Bootstrapping using a random number generator?

In summary, the MATLAB function is using wavelet analysis and a bootstrap method to calculate mean, quantiles, and standard deviation of time-frequency wavelet coefficients for EEG data. It then uses these values to calculate a Z-score and create a mask to identify significant changes in power. It is a statistical tool for analyzing EEG data.
  • #1
Jamin2112
986
12
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:
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
 
Physics news on Phys.org
  • #2




Hi there,

From what I can tell, this MATLAB function is using wavelet analysis to analyze EEG data from patients. The function first calculates the time-frequency wavelet coefficients of the input data, and then uses a bootstrap method to calculate the mean, upper and lower quantiles, and standard deviation of these coefficients at different frequencies.

The function then uses these values to calculate a Z-score for each time point and frequency, and creates a mask based on the lower quantile to identify significant changes in power. This function seems to be a statistical tool for analyzing EEG data and identifying patterns or changes in power over time and at different frequencies.

I hope this helps, and if you have any other questions, please let me know. Best of luck with your research!
 
Back
Top