
%Three groups


load Fl15


cxyz=[];



nrep=28;

%grupos: 1 control, 2 dcl, 3 enfermo
g=[repmat(1,1,12) repmat(2,1,6) repmat(3,1,10)];

grupo=g;



for i=1:nrep
    
    r=find(Fl(i).x); %son los distintos de cero
    s=find(Fl(i).y);
    t=find(Fl(i).z);
    cxyz=[cxyz; Fl(i).x(r)' Fl(i).y(s)' Fl(i).z(t)'];
    
end

xmi=cxyz;

ni=9;

lni=ni;

rand('state',1)

[icaxmi,A,W]=fastica(xmi,'lastEig', lni,'numOfIC', ni);

%calculo coeficientes c segun Ramsay
fi=icaxmi';

coicai=inv(fi'*fi)*fi'*xmi';


coica=[coicai'];


%save fi9i fi %

%dlmwrite('coica9i.txt',coica);

load fi9i
%discriminanteica.R

%%
%in R
%library(MASS)

%dd=read.table('coica9i.txt',sep=',')
%grupo=c(rep(1,12),rep(2,6),rep(3,10))
%
%
% z <- lda(grupo~as.matrix(dd))
%
%  puntd=as.matrix(as.matrix(dd) %*% as.matrix(z$scaling))
%#write.table(puntd, file = "puntdica9.txt",row.names=F,col.names=F)

 
%Matlab
%para 9 primera función discriminante,
%1st discriminant function, obtained with R
% SPSS can also be used
%DISCRIMINANT
%  /GROUPS=VAR00001(1 3)
%  /VARIABLES=V1 V2 V3 V4 V5 V6 V7 V8 V9
%  /ANALYSIS ALL
%  /PRIORS SIZE
%  /STATISTICS=RAW CROSSVALID
%  /CLASSIFY=NONMISSING POOLED.



ccd=[ 16.8724103   -4.8992685     8.2657615     2.9151285    -9.0159539  ...
 -10.6546102    8.9998544    0.4825338    5.4534761];
%coeficiente discriminantes, 89.29% varianza primera función discriminante


alfa=ccd*inv(fi'*fi)*fi';


%Figures (included Fig. 6 supplementaary material)

load unitsphere2562.mat
load Fl15

averagei=SPHARMaverage(Fl,sphere, 15,0);


 r=find(Fl(1).x); %donde colocar los no ceros

%media -2*alfa
f=-2;
 [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],1,alfa,r);


scale=10;
dibujopcavector(averagei,averagecompovf,sphere, 15,0,scale);


dibujopcacolor2(averagei,averagecompovf)



lighting none
 
 view(142.5,-30)
lighting none

%Figure 9 supplemenatry material


 p=load('puntdica9.txt'); %from R
    plot(p(1:12,1),p(1:12,2),'+'), hold on
     plot(p(13:18,1),p(13:18,2),'g*'),
    hold on
        plot(p(19:28,1),p(19:28,2),'ro'),
        
        %fpca
        
   p=load('puntdpca8.txt'); %from R in pcahipocampus.m
    plot(p(1:12,1),p(1:12,2),'+'), hold on
     plot(p(13:18,1),p(13:18,2),'g*'),
    hold on
   plot(p(19:28,1),p(19:28,2),'ro'),

   
   %%%%%%%%%%%
   % CN-MCI
   
   xmi=xmi(1:18,:);

ni=6;

lni=ni;

rand('state',1)

[icaxmi,A,W]=fastica(xmi,'lastEig', lni,'numOfIC', ni);

%calculo coeficientes c segun Ramsay
fi=icaxmi';

coicai=inv(fi'*fi)*fi'*xmi';

coica=[coicai'];

%save fi6i fi 

%dlmwrite('coica6i.txt',coica);


load fi6i
%in R
%#función discriminante
%library(MASS)
%
%dd=read.table('coica6i.txt',sep=',')
%grupo=c(rep(1,12),rep(2,6))
%
% z <- lda(grupo~as.matrix(dd))
 

%única función discriminante. The discriminant function

ccd=[ 16.104680  -3.119265 -16.729098  -15.575525   -5.364269  -1.377597];


alfa=ccd*inv(fi'*fi)*fi';

%Figures (included Fig. 4)

load unitsphere2562.mat
load Fl15

Fl=Fl(1:18,:);

averagei=SPHARMaverage(Fl,sphere, 15,0);


 r=find(Fl(1).x); %donde colocar los no ceros

%media -2*alfa
f=2;
 [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],1,alfa,r);


scale=3;
dibujopcavector(averagei,averagecompovf,sphere, 15,0,scale);
view(15,76)
%camlight;
%lighting gouraud

dibujopcacolor2(averagei,averagecompovf)

lighting none

dibujopcacolor2(averagei,averagecompovf)
view(134,-22)
lighting none



%%%%%%%%%%%%%
%CN-AD

load Fl15


cxyz=[];



nrep=28;

%grupos: 1 control, 2 dcl, 3 enfermo
g=[repmat(1,1,12) repmat(2,1,6) repmat(3,1,10)];

grupo=g;



for i=1:nrep
    
    r=find(Fl(i).x); %son los distintos de cero
    s=find(Fl(i).y);
    t=find(Fl(i).z);
    cxyz=[cxyz; Fl(i).x(r)' Fl(i).y(s)' Fl(i).z(t)'];
    
end

xmi=cxyz;
do=[1:12 19:28];

xmi=xmi(do,:);

grupo=g(do);

ni=2;

lni=ni;

rand('state',1)

[icaxmi,A,W]=fastica(xmi,'lastEig', lni,'numOfIC', ni);

%calculo coeficientes c segun Ramsay
fi=icaxmi';


coicai=inv(fi'*fi)*fi'*xmi';


coica=[coicai'];



%Figures (included fig. 5 supplementary material)

%save fi2i fi 

%dlmwrite('coica2i.txt',coica);


load fi2i

%in R
%
%#función discriminante
%library(MASS)
%
%dd=read.table('coica2i.txt',sep=',')
%grupo=c(rep(1,12),rep(3,10))
%
%
% z <- lda(grupo~as.matrix(dd))
 
%para 2 única función discriminante

ccd=[  -9.783158 20.681921];


alfa=ccd*inv(fi'*fi)*fi';

%Figures 
load unitsphere2562.mat
load Fl15

Fl=Fl(do,:);

averagei=SPHARMaverage(Fl,sphere, 15,0);


 r=find(Fl(1).x); %donde colocar los no ceros

%media -2*alfa
f=-2;
 [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],1,alfa,r);


scale=10;
dibujopcavector(averagei,averagecompovf,sphere, 15,0,scale);


dibujopcacolor2(averagei,averagecompovf)



lighting none

 

 dibujopcacolor2(averagei,averagecompovf)
 view(142.5,-30)
lighting none


%%%%%%%%%%%%
%MCI-AD

load Fl15


cxyz=[];



nrep=28;

%grupos: 1 control, 2 dcl, 3 enfermo
g=[repmat(2,1,6) repmat(3,1,10)];

grupo=g;



for i=1:nrep
    
    r=find(Fl(i).x); %son los distintos de cero
    s=find(Fl(i).y);
    t=find(Fl(i).z);
    cxyz=[cxyz; Fl(i).x(r)' Fl(i).y(s)' Fl(i).z(t)'];
    
end

xmi=cxyz;

        
        
        
xmi=xmi(13:28,:);

ni=4;

lni=ni;

rand('state',1)

[icaxmi,A,W]=fastica(xmi,'lastEig', lni,'numOfIC', ni);

%calculo coeficientes c segun Ramsay
fi=icaxmi';


coicai=inv(fi'*fi)*fi'*xmi';


coica=[coicai'];

%Figures (included Fig. 4 supplemental material)

%save fi4i fi 

%dlmwrite('coica4i.txt',coica);


load fi4i
%
%in R
%#función discriminante
%library(MASS)
%
%dd=read.table('coica4i.txt',sep=',')
%grupo=c(rep(2,6),rep(3,10))
%
%
% z <- lda(grupo~as.matrix(dd))
%
% puntd=as.matrix(as.matrix(dd) %*% as.matrix(z$scaling)

%para 4 única función discriminante

ccd=[ -12.137077  14.688040    3.084517   4.620477];


alfa=ccd*inv(fi'*fi)*fi';


load unitsphere2562.mat
load Fl15

Fl=Fl(13:28,:);

averagei=SPHARMaverage(Fl,sphere, 15,0);


 r=find(Fl(1).x); %donde colocar los no ceros

%media -2*alfa
f=-2;
 [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],1,alfa,r);

scale=10;
dibujopcavector(averagei,averagecompovf,sphere, 15,0,scale);


dibujopcacolor2(averagei,averagecompovf)



lighting none

 dibujopcacolor2(averagei,averagecompovf)
 view(142.5,-30)
lighting none

%Fig. 8 supplemental material

 h=2, j=4
         plot(coica(1:6,h),coica(1:6,j),'g*'),
    hold on
        plot(coica(7:16,h),coica(7:16,j),'ro'),


