Home > NoiseTools > nt_bsmean_diff.m

# nt_bsmean_diff

## PURPOSE

[mn,sd]=nt_bsmean_diff(x1,x2,N) - calculate mean, estimate sd using bootstrap

## SYNOPSIS

function [mn,sd]=nt_bsmean_diff(x1,x2,N)

## DESCRIPTION

    [mn,sd]=nt_bsmean_diff(x1,x2,N) - calculate mean, estimate sd using bootstrap

      mn: mean of x over second dimension
      sd: standard deviation from mn of bootstrap trials

      x1: matrix of observations (time X repetitions)
      x2: matrix of observations (time X repetitions)
      N: number of bootstrap trials [default: 100]

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- nt_bsplot_diff nt_bsplot_diff(x,y,sds,style,abscissa,zeroflag,rmsflag) - plot average difference with bootstrap standard deviation

## SOURCE CODE

    0001 function [mn,sd]=nt_bsmean_diff(x1,x2,N)
    0002 %[mn,sd]=nt_bsmean_diff(x1,x2,N) - 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 %
    0007 %  x1: matrix of observations (time X repetitions)
    0008 %  x2: matrix of observations (time X repetitions)
    0009 %  N: number of bootstrap trials [default: 100]
    0010
    0011 if nargin <3; N=100; end
    0012 if nargin <2; error('!'); end
    0013
    0014 if ndims(x1)>2||ndims(x2)>2; error('data must be at most 2D'); end
    0015
    0016 [m1,n1]=size(x1);
    0017 [m2,n2]=size(x2);
    0018 if m1~=m2; error('x1 and x2 should have same nrows'); end
    0019
    0020 all=zeros(m1,N);
    0021 for k=1:N
    0022     idx1=ceil(n1*rand(1,n1));
    0023     idx2=ceil(n2*rand(1,n2));
    0024     all(:,k)=mean(x1(:,idx1),2)-mean(x2(:,idx2),2);
    0025 end
    0026
    0027 mn=mean(x1,2)-mean(x2,2);
    0028 sd=sqrt(mean((all-repmat(mn,1,N)).^2,2));
    0029
    0030