% Page 47, Problem 2.4 (Mushrooms)
% "...One of the keys to mushroom identification is 
% the spore deposit. Spores of
% Amanita phalloides are colorless, nearly spherical,
% and smooth. Measurements
% in microns of 28 spores (max diameter) are given below."
%
% Find the jackknife estimator of log(theta)
% where theta is the population mean.


mushrooms =[...
9.2 8.8 9.1 10.1 8.5 8.4 9.3 ...
8.7 9.7 9.9 8.4 8.6 8.0 9.5 ...
8.8 8.1 8.3 9.0 8.2 8.6 9.0 ...
8.7 9.1 9.2 7.9 8.6 9.0 9.1];
%the mean theta unknown,
%interested in estimating log(theta).
%The MLE is thetahat
thetahatmle= log(mean(mushrooms))
%
n=length(mushrooms);
pseudo=[];
for i = 1:n
    jknsa = minusith(mushrooms, i);
    pseudoobs = n * log(mean(mushrooms)) - ...
        (n-1)*log(mean(jknsa));
    pseudo =[pseudo pseudoobs];
end
thetahatJ = mean(pseudoobs)
stdthetahatJ = std(pseudo)/sqrt(n)
%CI
[thetahatJ - tinv(0.975, n-1)*stdthetahatJ,...
    thetahatJ + tinv(0.975, n-1)*stdthetahatJ]

% 
% thetahatmle =  2.1804
% thetahatJ = 2.2087
% stdthetahatJ = 0.0118
% ans = 2.1845    2.2328

