clear all

load T4-3.DAT

X=T4_3(:,1:4);

[n,p]=size(X);

X_mean=mean(X);

S=cov(X);

d=diag((X-ones(n,p)*diag(X_mean))*inv(S)*(X-ones(n,p)*diag(X_mean))');

d_sort=sort(d);

for i=1:n
    q(i)=chi2inv((i-1/2)/n,p);
end

scatter(q',d_sort);
title('A chi-square plot for the data in Example 3.14')
xlabel('q_{c,4}((j-1/2)/30)');
ylabel('d_{(j)}^2');