close all force
clear all
[sp, sex, index, FL, RW,  CL,  CW,  BD]  = textread('C:\STAT\ANOVA\ANOVAdat\crabs.dat','%s%s%f%f%f%f%f%f');

morph=[FL RW CL CW BD];
[coeff, score, latent, tsquared, explained] = pca(morph);

% score is PC transformation of the data matrix morph. First column
% corresponds to the 1st principal component (responsible for most of
% the variability.

crabs.sp=cell2mat(sp);
crabs.sex=cell2mat(sex);
crabs.FL=FL; 
crabs.RW=RW;
crabs.CL=CL;  
crabs.CW=CW;
crabs.BD=BD;
crabs.score=score(:,1);
save crabs.mat crabs -mat

clear all
load crabs
anovan(crabs.score,{crabs.sp, crabs.sex},'model','interaction',  'varnames',strvcat('sp', 'sex'))

%textread %s makes sp and sex to be cells. To assess the values
%the function  cell2mat is used.
%%
% Interaction present...need separate conditional ANOVAs
% conditioning on blue and Orange crabs.
     scoreB=crabs.score(crabs.sp=='B',1) 
     sexB = crabs.sex(crabs.sp == 'B')
     anova1(scoreB, sexB)

%%

%%
%flip this to scoreF, scoreM....
% Interaction present...need separate conditional ANOVAs
% conditioning on blue and Orange crabs.
     scoreO=crabs.score(crabs.sp=='O',1) 
     sexO = crabs.sex(crabs.sp == 'O')
     anova1(scoreO, sexO)

morph=[crabs.FL   crabs.RW   crabs.CL    crabs.CW    crabs.BD];


% 
% 
% %        1      Size of face
% %        2      Forehead/jaw relative arc length
% %        3      Shape of forehead
% %        4      Shape of jaw
% %        5      Width between eyes
% 
figure(3)
glyphplot([mean(morph(1:50,:)); ...
mean(morph(51:100,:));   mean(morph(101:150,:)) ; ...
mean(morph(151:200,:)) ] , 'glyph','face', ...
 'ObsLabels',{'BM','BF','OM','OF'}) 
% 
% 
% 
% figure(4)
% glyphplot([mean(crabs.score(1:50)); ...
% mean(crabs.score(51:100));   mean(score(101:150,:)) ; ...
% mean(score(151:200,:)) ] , 'glyph','face', ...
%  'ObsLabels',{'BM','BF','OM','OF'}) 

 