close all
clear all
load thymusglandweights.dat

literature_mean = 34.3;

x = thymusglandweights;
n = length(x);
y = x - mean(x) + literature_mean;

m = 2000;
me = zeros(m,1);
for i = 1:m
    me(i) = mean(y(randi(n,n,1)));
end

hist(me, 50);
hold on
mu = mean(x);
plot([mu,mu],[0,200],'--r','LineWidth',3);
xlabel('thymus gland weights [g]');
ylabel('frequency');
title('bootstrapped null distribution');
hold off

% 5% significance boundaries
low = quantile(me,0.025);
high =  quantile(me,0.975);
disp(['the 5% boundaries are: ', num2str(low), ' ', num2str(high)]);

hold on
plot([low,low],[0,200],'--g','LineWidth',3);
plot([high,high],[0,200],'--g','LineWidth',3);
hold off

pval = mean(abs(me-literature_mean) > abs(mu - literature_mean))

legend('Null distribution','measured mean','5% significance boundaries')
