# Bootstrap a statistic

### Dimitri Shvorob (view profile)

15 Apr 2007 (Updated )

(Extension of BOOTSTRP)

bstats(res,varargin)
```function[m,varargout] = bstats(res,varargin)
% JKNIFE     Bootstrapped mean, variance and confidence interval
% INPUTS  :  res   - array or structure array output by BSTRAP
%            field - if res is a structure array, field storing statistic x
% OUTPUTS  : m     - average of x's bootstrap distribution
%            v     - (optional) variance of bootstrap distribution
%            cil   - (optional) 2.5%  percentile of bootstrap distribution
%            ciu   - (optional) 97.5% percentile of bootstrap distribution
% EXAMPLE  : See BSTRAPDEMO
% AUTHOR   : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 4/15/07

switch nargin
case 0
error('Input argument "res" is undefined')
case 1
if isstruct(res)
error('Input argument "field" must be provided if "res" is a structure')
else
x = res(:,:,2:end);
end
case 2
if ~isstruct(res)
error('Input argument "field" is provided, but "res" is not a structure')
else
try
field = char(varargin);
catch
error('Input argument "field" must be a string')
end
try
x = eval(['res(1).' field]);
catch
end
n = length(res);
x = repmat(x,[1 1 n-1]);
for m = 2:n
x(:,:,m-1) = eval(['[res(m).' field ']']);
end
end
end
m = mean(x,3);
if nargout > 1
varargout(1) = {var(x,1,3)};
end
if nargout > 2
varargout(2) = {prctile(x,2.5,3)};
end
if nargout > 3
varargout(3) = {prctile(x,97.5,3)};
end ```