This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/bootstrap/exercises/bootstrapmean.m

18 lines
526 B
Matlab

function [bootsem, mu] = bootstrapmean(x, resample)
% computes standard error by bootstrapping the data
% x: vector with data
% resample: number of resamplings
% returns:
% bootsem: the standard error of the mean
% mu: the bootstrapped means as a vector
mu = zeros(resample, 1);
nsamples = length(x);
for i = 1:resample
% resample:
xr = x(randi(nsamples, nsamples, 1));
% compute statistics of resampled sample:
mu(i) = mean(xr);
end
bootsem = std(mu);
end