X=[8 98 7 2 12 8 7
7 107 4 3 9 5 3
7 103 4 3 5 6 3
10 88 5 2 8 15 4
6 91 4 2 8 10 3
8 90 5 2 12 12 4
9 84 7 4 12 15 5
5 72 6 4 21 14 4
7 82 5 1 11 11 3
8 64 5 2 13 9 4
6 71 5 4 10 3 3
6 91 4 2 12 7 3
7 72 7 4 18 10 3
10 70 4 2 11 7 3
10 72 4 1 8 10 3
9 77 4 1 9 10 3
8 76 4 1 7 7 3
8 71 5 3 16 4 4
9 67 4 2 13 2 3
9 69 3 3 9 5 3
10 62 5 3 14 4 4
9 88 4 2 7 6 3
8 80 4 2 13 11 4
5 30 3 3 5 2 3
6 83 5 1 10 23 4
8 84 3 2 7 6 3
6 78 4 2 11 11 3
8 79 2 1 7 10 3
6 62 4 3 9 8 3
10 37 3 1 7 2 3
8 71 4 1 10 7 3
7 52 4 1 12 8 4
5 48 6 5 8 4 3
6 75 4 1 10 24 3
10 35 4 1 6 9 2
8 85 4 1 9 10 2
5 86 3 1 6 12 2
5 86 7 2 13 18 2
7 79 7 4 9 25 3
7 79 5 2 8 6 2
6 68 6 2 11 14 3
8 40 4 3 6 5 2];
[n,p]=size(X);
I=eye(n);
j=ones(n,1);
XBAR=(1/n)*X'*j;
J=ones(size(I));
S=(1/(n-1))*X'*(I-(1/n)*J)*X;
R=inv(diag(sqrt(diag(S))))'*S*inv(diag(sqrt(diag(S))));
pause;
%Univariate Normality
[nq1,xq1]=qq_normal(X(:,1:1));
plot(nq1,xq1,'o'); grid
title('Q-Q Analysis of Wind')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted wind values x1');
pause;
[nq2,xq2]=qq_normal(X(:,2:2));
plot(nq2,xq2,'o'); grid
title('Q-Q Analysis of Solar radiation')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted solar radiation values x2');
pause;
[nq3,xq3]=qq_normal(X(:,3:3));
plot(nq3,xq3,'o'); grid
title('Q-Q Analysis of CO')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted CO values x3');
pause;
[nq4,xq4]=qq_normal(X(:,4:4));
 plot(nq4,xq4,'o'); grid
title('Q-Q Analysis of NO')
 xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted NO values times  x4');
pause;
[nq5,xq5]=qq_normal(X(:,5:5));
plot(nq5,xq5,'o'); grid
title('Q-Q Analysis of times N02')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted N02 values x5');
pause;
[nq6,xq6]=qq_normal(X(:,6:6));
plot(nq6,xq6,'o'); grid
title('Q-Q Analysis of times 03')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted 03 values  x6');
pause;
[nq7,xq7]=qq_normal(X(:,7:7));
plot(nq7,xq7,'o'); grid
title('Q-Q Analysis of HC')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted HC values x7');
pause;
corr1=corrcoef([nq1(:),xq1(:)])
corr2=corrcoef([nq2(:),xq2(:)])
corr3=corrcoef([nq3(:),xq3(:)])
corr4=corrcoef([nq4(:),xq4(:)])
corr5=corrcoef([nq5(:),xq5(:)])
corr6=corrcoef([nq6(:),xq6(:)])
corr7=corrcoef([nq7(:),xq7(:)])
%Bivariate Normality Checks
X56=[X(:,5:5) X(:,6:6)];XBAR56=[XBAR(5);XBAR(6)];S56=S(5:6,5:6); 
d56=zeros(n,1);
for i = 1:n
d56(i)=(X56(i:i,:)'-XBAR56)'*inv(S56)*(X56(i:i,:)'-XBAR56);
end
[nq56,xq56]=qq_normal(d56);
plot(nq56,xq56,'o'); grid
title('Q-Q Analysis of times Mahalanobis Distances')
xlabel('Theoretical Normal N(0,1) Quantile')
ylabel('Sorted Distances values D56');
pause;
