from
unique mean and error of a vector with repetitions
by Omri Bahat Treidel
input: vec x with repetitions and F(x). return: mean and error of F(unique(x))
|
| unique_err_BS(x,Fx,bootFactor) |
function [y V errBS] = unique_err_BS(x,Fx,bootFactor)
% this function takes a vector x that contains repetitions and a function of x.
% This means that for every value of x there are multiple values of F(x)
% The function returens a vector y which is the values of x without the repetitions,
% a vector V that is the bootsrtap mean of Fx - V_i = mean(F(xi)) where all
% xi are the same, and a vector errBS with is the bootstrap error of the
% mean. The input 'bootFactor' determins the number of bootstrap samples:
% Nboot = bootFactor*(sample size)^2;
[y iy ix] = unique(x);
rep = histc(x,y); % this is the number of repetition of a given value in x
V = zeros(1,length(y));
errBS=V;
for ind=1:length(y)
range = iy(ind) - rep(ind)+1 : iy(ind); % the indices of a given value in x
x( range )
tmp = Fx(range); % the values of Fx for all the points of the same x
if(rep(ind) > 1)
Nboot = bootFactor*rep(ind)^2; % number of bootstrap samples
BS = bootstrp(Nboot,@mean,tmp(:) ); % resampling of n0
V(ind) = mean(BS); % this is the bootstrap mean
errBS(ind) = sqrt( sum((BS - mean(BS) ).^2)/(Nboot-1) ); % del_n0
else
V(ind) = mean(tmp);
errBS(ind) = NaN;
end
end
end
|
|
Contact us