 disp('Checking Bivariate Normality by QQ plot')
 lw = 3; 
 set(0, 'DefaultAxesFontSize', 16);
 fs = 15;
 msize = 10;
% 
close all
%qqbivariatenormal.m
load 'C:\Springer\Reg\Regdat\pearson.dat'
S = cov(pearson)
[m n] = size(pearson)
mp = repmat(mean(pearson), m,1);
d2 = diag((pearson - mp) * inv(S)  * (pearson - mp)');

p = 0.5/m:1/m:1;
quanch2 = chi2inv(p,2);

figure(1)
loglog(quanch2, sort(d2),'o','Markersize',msize,...
    'MarkerEdgeColor','k', 'MarkerFaceColor','g')
hold on
loglog([0.0002 50],[0.0002 50],'r','linewidth',lw)
axis([10^-4, 100, 10^-4, 100])
xlabel('Quantiles of \chi^2_2 ')
ylabel('Sorted d^2 ')
%print -depsc 'C:\Springer\Goodness\Goodnesseps\qqbivariatenormal.eps'