clear all
close all force
 load 'C:\STAT\Test\Testdat\bird.mat'
%  
%  This data set from Johnson and Wichern (2002) contains bivariate
%  measurements on n=45 female hook-billed kites.
%  The data set bird.dat contains three columns:
%  bird numner, tail length, and wing length.
%  
%  Johnson, R. A. and   Wichern,D. W. (2002).
%  Applied Mulivariate Statistical Analysis, 5th Edition
%   rentice Hall, NY.
  figure;
 x1 = bird(:,2); x2 = bird(:,3);
 plot(x1,x2,'o','MarkerEdgeColor','k',...
                       'MarkerFaceColor','m',...
                       'MarkerSize',12)
%
X=[x1 x2];
 
[n p]=size(X);
Xbar = mean(X)'; %[193.6222;  279.7778]
S = cov(X);
 % 120.6949  122.3460
 % 122.3460  208.5404
mu0 = [190; 275]    %;mu0=[192, 283];

T2 = n * (Xbar - mu0)'* inv(S) * (Xbar - mu0) %5.5431
F = (n-p)/(p*(n-1)) * T2  %2.7086
pval = 1-fcdf(F, p, n-p)   %0.078

%
t1 = (Xbar(1)-mu0(1))/sqrt(S(1,1)/n);  %2.2118
t2 = (Xbar(2)-mu0(2))/sqrt(S(2,2)/n)  %2.2194
p1 = 2*tcdf(-abs(t1), n-2)  %0.0323
p2 = 2*tcdf(-abs(t2), n-2)  %0.0318


%
 %plot(X(:,1), X(:,2),'.')
 %hold on
figure;
ConfidenceEllipse(X,0.95, 0, 2,[0.7 0.5 0.1])    

hold on
    
 i1 = [Xbar(1) - tinv(0.975, n-p)*sqrt(S(1,1)/n ), ...
          Xbar(1) + tinv(0.975, n-p)*sqrt(S(1,1)/n )] ;
 i2 = [Xbar(2) - tinv(0.975, n-p)*sqrt(S(2,2)/n ), ...
          Xbar(2) + tinv(0.975, n-p)*sqrt(S(2,2)/n )] ;  
    plot(    [i1(1) i1(2)],[i2(1) i2(1)],'b-','LineWidth',2)
    plot(    [i1(1) i1(2)],[i2(2) i2(2)],'b-','LineWidth',2)
    plot(    [i1(1) i1(1)],[i2(1) i2(2)],'b-','LineWidth',2)  
    plot(    [i1(2) i1(2)],[i2(1) i2(2)],'b-','LineWidth',2) 
    
    
    plot(190,275,'o','MarkerEdgeColor','k',...
                       'MarkerFaceColor','g',...
                       'MarkerSize',12)
    plot(191,283,'o','MarkerEdgeColor','k',...
                       'MarkerFaceColor','r',...
                       'MarkerSize',12)
         
    % print -depsc 'C:\STAT\Test\Testeps\bird.eps'
              
                   
         
    
    