% 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 jackknife estimator of log(sigma2)
% where sigma2 is the population variance.


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 log(sigma^2) unknown,
%The MLE is 
logsigma2hatmle= log(var(mushrooms,1))
%
n=length(mushrooms);
pseudo=[];
for i = 1:n
    jknsa = minusith(mushrooms, i);
    pseudoobs = n * log(var(mushrooms,1)) - ...
        (n-1)*log(var(jknsa,1));
    pseudo =[pseudo pseudoobs];
end
logsigma2hatJ = mean(pseudoobs)
stdlogsigma2hatJ = std(pseudo)/sqrt(n)
%CI
[logsigma2hatJ - tinv(0.975, n-1)*stdlogsigma2hatJ,...
    logsigma2hatJ + tinv(0.975, n-1)*stdlogsigma2hatJ]

% logsigma2hatmle = -1.2293
% logsigma2hatJ =-1.9967
% stdlogsigma2hatJ = 0.2739
%  95% CI     [-2.5586   -1.4348]
