clear all
close all


disp('Amanita Muscaria: Confidence Intervals for the Mean and Variance')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------

X = [...
    10 11 12  9 10 11 13 12 10 11 ...
    11 13   9 10  9 10  8   12 10 11 ...
    9 10   7 11  8   9  11  11 10 12 ...
    10   8   7 11 12 10  9  10  11 10 ...
    8 10 10 8 9 10 13 9 12 9 9 ];
 
%set confidence  level for CI for mean
 confidence = .95;
 alpha = 1 - confidence; %confidence is 1-alpha 
 n= length(X);
 
 LBt= mean(X) - tinv(1-alpha/2, n-1) * std(X)/sqrt(n);
 UBt= mean(X) + tinv(1-alpha/2, n-1) * std(X)/sqrt(n);
 [LBt  UBt] %9.6837   10.5124
 Ltint = UBt - LBt
 
 figure(1)
 plot( [LBt-Ltint, UBt+Ltint],[0,0],'r-')
 hold on
 plot( [LBt,UBt],[0,0],'b-','LineWidth',20 )
 text( LBt-0.2,0.15, '9.6837')
 text(UBt-0.2, 0.15, '10.5124')
 plot([mean(X),mean(X)], [0,0],'r.','MarkerSize',20)
%set confidence  level for CI for variance
 confidence = .90;
 alpha = 1 - confidence; %confidence is 1-alpha 
 
 s2 = var(X);

 LBs = s2 * (n-1)/chi2inv(1-alpha/2, n-1);
 UBs = s2 * (n-1)/chi2inv(alpha/2, n-1);
 [LBs UBs]  %  1.6074    3.1213
 Lvarint = UBs - LBs
 
 
 figure(2)
 plot( [LBs-Lvarint, UBs+Lvarint],[0,0],'r-')
 hold on
 plot( [LBs,UBs],[0,0],'b-','LineWidth',20 )
 plot([s2,s2], [0,0],'r.','MarkerSize',20)
 text( LBs-0.2,0.15, '1.6074')
 text(UBs-0.2, 0.15, '3.1213')