% eda09_01
% load 'rocks.txt'
% estimate covariance and etc of data
% types

D = load('rocks.txt');
% 1: SiO2
% 2: TiO2
% 3: Al203
% 4: FeO-total
% 5: MgO
% 6: CaO
% 7: Na2O
% 8: K2O

% note use of a cell string to create array of variable names
name = { 'SiO2', 'TiO2', 'Al203', 'FeO', 'MgO', 'CaO', 'Na2O', 'K2O' };

% determine size of data matrix
Ns = size(D);
N = Ns(1);
M = Ns(2);

dbar = mean(D); % mean
C = cov(D); % covariance
sigma = diag(D).^0.5; % stddev
R = corrcoef(D); % correlation coefficient

% plot results
eda_draw(abs(R));

% display results; also find most correlated data
for i = [1:M]
    disp(sprintf('%s mean=%f stddev=%f',char(name(i)),dbar(i),sigma(i)));
end
disp(' ');
icor=1;
jcor=2;
r=0;
for i = [1:M]
for j = [i+1:M-1]
    disp(sprintf('%s vs %s cov=%f R=%f',char(name(i)),char(name(j)),C(i,j),R(i,j)));
    if( abs(R(i,j)) > r )
        r = abs(R(i,j));
        icor=i;
        jcor=j;
    end
end
end

figure(2);
clf;
set(gca,'LineWidth',2);
plot(D(:,icor),D(:,jcor), 'ko', 'LineWidth', 2 );
xlabel(char(name(icor)));
ylabel(char(name(jcor)));
title(sprintf('R=%f',R(icor,jcor)));





    
