Home > NoiseTools > nt_bsmean.m

nt_bsmean

PURPOSE ^

[mn,sd,all]=nt_bsmean(x,N,w) - calculate mean, estimate sd using bootstrap

SYNOPSIS ^

function [mn,sd,all]=nt_bsmean(x,N,w)

DESCRIPTION ^

[mn,sd,all]=nt_bsmean(x,N,w) - calculate mean, estimate sd using bootstrap

  mn: mean of x over second dimension
  sd: standard deviation from mn of bootstrap trials
  all: matrix of all bootstrap trials
  
  x: matrix of observations (time X repetitions)
  N: number of bootstrap trials [default: 100]
  w: weight matrix (time X repetitions)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mn,sd,all]=nt_bsmean(x,N,w)
0002 %[mn,sd,all]=nt_bsmean(x,N,w) - calculate mean, estimate sd using bootstrap
0003 %
0004 %  mn: mean of x over second dimension
0005 %  sd: standard deviation from mn of bootstrap trials
0006 %  all: matrix of all bootstrap trials
0007 %
0008 %  x: matrix of observations (time X repetitions)
0009 %  N: number of bootstrap trials [default: 100]
0010 %  w: weight matrix (time X repetitions)
0011 
0012 if nargin <2; N=100; end
0013 if nargin <3; w=[]; end
0014 
0015 if ndims(x)>2; 
0016     x=squeeze(x);
0017     if ndims(x)>2; 
0018         error('data must be at most 2D'); 
0019     end
0020 end
0021 if numel(N)>1; error('!'); end
0022 
0023 if isempty(w) % special case for speed
0024     [m,n]=size(x);
0025     all=zeros(m,N);
0026     for k=1:N
0027         idx=ceil(n*rand(1,n));
0028         all(:,k)=mean(x(:,idx),2);
0029     end
0030     mn=mean(x,2);
0031     sd=sqrt(mean((all-repmat(mn,1,N)).^2,2));
0032 else
0033     if size(w,2)==1; w=repmat(w,1,size(x,2)); end
0034     if size(w) ~= size(x); error('!'); end
0035     [m,n]=size(x);
0036     all=zeros(m,N);
0037     for k=1:N
0038         idx=ceil(n*rand(1,n));
0039         all(:,k)=nt_wmean(x(:,idx),w(:,idx),2);
0040     end
0041     mn=nt_wmean(x,w,2);
0042     sd=sqrt( mean((all-repmat(mn,1,N)).^2, 2));
0043 end
0044     
0045 
0046

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005