

load Fl15


cxyz=[];



nrep=28;

for i=1:nrep
    
    r=find(Fl(i).x); %different from zero
    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


 [co, sc, la] = princomp(cxyz) ;
   
 
    [cumsum(la)./sum(la)]'
    
    [cumsum(la(1:29))./sum(la)]'

ans =

  Columns 1 through 15

    0.2473    0.3888    0.4948    0.5664    0.6264    0.6779    0.7125    0.7458    0.7757    0.8036    0.8278    0.8485    0.8666    0.8839    0.8994

  Columns 16 through 29

    0.9127    0.9242    0.9347    0.9444    0.9535    0.9622    0.9696    0.9767    0.9830    0.9889    0.9945    1.0000    1.0000    1.0000

    
    [(la(1:29))./sum(la)]'

ans =

  Columns 1 through 15

    0.2473    0.1415    0.1060    0.0716    0.0600    0.0515    0.0346    0.0333    0.0298    0.0279    0.0242    0.0207    0.0181    0.0173    0.0155

  Columns 16 through 29

    0.0132    0.0116    0.0104    0.0097    0.0091    0.0087    0.0075    0.0071    0.0063    0.0059    0.0056    0.0055         0         0
    
 
%component j: contribution of each coordinate
j=1; %2, 3
 sum(co(:,j).^2)

 sum(co(1:256,j).^2)

 sum(co(257:512,j).^2)


sum(co(513:768,j).^2)


%Results

j=1

j =

     1



 sum(co(:,j).^2)

 sum(co(1:256,j).^2)

 sum(co(257:512,j).^2)


sum(co(513:768,j).^2)

ans =

    1.0000


ans =

    0.4525


ans =

    0.2717


ans =

    0.2758

j=2

j =

     2



 sum(co(:,j).^2)

 sum(co(1:256,j).^2)

 sum(co(257:512,j).^2)


sum(co(513:768,j).^2)

ans =

    1.0000


ans =

    0.4114


ans =

    0.2037


ans =

    0.3849

j=3

j =

     3



 sum(co(:,j).^2)

 sum(co(1:256,j).^2)

 sum(co(257:512,j).^2)


sum(co(513:768,j).^2)

ans =

    1.0000


ans =

    0.2351


ans =

    0.4181


ans =

    0.3467


   
    
    %Graphics
    
    load unitsphere2562.mat %from surfstats

averagei=SPHARMaverage(Fl,sphere, 15,0); %from surfstats

figure_wire(averagei,'yellow')
figure_patch(averagei,'yellow')

    
%Figure 3: first 3 components, with -2 to 2 sd 
ha = tight_subplot(3,5,[.01 .01],[.01 .01],[.01 .01]); %like subplot, but with less space between figures
k=1;
for j=1:3
    
    for f=-2:2
        
       % subplot(3,5,(k-1)*5+(f+3))
        
   axes(ha((k-1)*5+(f+3)));
   
  [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],sqrt(la(j)),co(:,j),r); %use functions from surfstats
    
    figure_patch3(averagecompovf,'black',1)
    axis([5 45 5 45 5 45])
    axis off 
    end
    k=k+1;
end



%Figures PCA in supplemental material




%Figure 1: supplemental material

f=2;
for j=1:3
      
      
   
  [averagecompo,averagecompovf]=dibujopca(Fl,sphere, 15,0, [f f f],sqrt(la(j)),co(:,j),r); %use functions from surfstats
  dibujopcacolor2(averagei,averagecompovf)
  lighting none
  view(-11,14)
  if j==1
    view(138,-32)
  end
    
end






%Fig. 9 supplementary material

 %dlmwrite('sciprincomp.txt',sc);
 
 % in R:
 %library(MASS)
%
%dd=read.table('sciprincomp.txt',sep=',')
 %grupo=c(rep(1,12),rep(2,6),rep(3,10))
%
%dd=dd[,1:8]
%
% z <- lda(grupo~as.matrix(dd))
%
%
%
%  puntd=as.matrix(as.matrix(dd) %*% as.matrix(z$scaling))
%
% #write.table(puntd, file = "puntdpca8.txt",row.names=F,col.names=F)
%
%
%
 
 p=load('puntdpca8.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'),
        
  %Figure 8 supplemantal material
  %MCI vs AD
  
cxyz=[];


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






for i=13:28
    
    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;

 [co, sc, la] = princomp(cxyz) ;

   h=1; 
    
    j=3;
    
   
    
    plot(sc(1:6,h),sc(1:6,j),'g*'),
    hold on
    plot(sc(7:16,h),sc(7:16,j),'ro'),
 
        