%sample of TN (total nitrogen) loads (kg N/day) from a particular 
%Chesapeake Bay location, displayed here in increasing order.
fileID = fopen('exmp1-17.txt','r');
formatSpec = '%f';
x = fscanf(fileID,formatSpec);
fclose(fileID);
hist(x)

[n p] = size(x);
mhat = median(x);
%Ikke-parametrisk bootstrapping
B = 10000
msim = zeros(1,B);
for b=1:B
    xstar = randsample(x,n,true);
    msim(b) = median(xstar);
end
hist(msim)
%Forventningsskjevhet
bias = mean(msim) - mhat
%Varians
V = var(msim)
%Standardfeil
s = sqrt(V)
%95% konfidensinvervall
KI = [mhat-1.96*s mhat+1.96*s]
