clear all
close all


 disp('WDBC: PCA')
 lw = 3; 
 set(0, 'DefaultAxesFontSize', 16);
 fs = 15;
 msize = 10;


load('C:\STAT\Descriptive\Descriptivedat\wdbc.mat')
close all force
%Take all non-invasive body measures
  
 Y = wdbc(:,1);
 X = wdbc(:,2:31);  

[n p]=size(X);

%
Z=zscore(X); % components of matrix X are on very different scales, so ZSCORE matrix is used.
% correlation  matrix
C=cov(Z)  % cov(Z) is the same as corr(X)

% MATLAB built in. Gives PC (coeffs), transformed data (scores), and
% variances (latent). When Z is used -- sum(variances)=p=14.
[coeffs1, scores1, latent1] = pca(Z);

 %Equivalent task using eig, eigs. Note that eigenvectors (columns of V) are PCs,
 % and variances are on the diagonal of D.
 % Scores are recovered as Z*V
[V D]=eigs(C,30);
coeffs2=V;
scores2=Z*V;
latent2=diag(D);
%

figure;
pareto(latent2)
xlabel('PC')
ylabel('Variance')
%print -depsc 'C:\Brani\Courses\isyestatu\Summer2014\HW1\wdbcpca1.eps'
figure;
plot(scores1(Y==0,1), scores1(Y==0,2),'b.')
hold on
plot(scores1(Y==1,1), scores1(Y==1,2),'r.')
legend('No cancer','Cancer',2)
xlabel('1st PC'); ylabel('2nd PC')
%print -depsc 'C:\Brani\Courses\isyestatu\Summer2014\HW1\wdbcpca2.eps'

