%Chung et al. 2010
%Appendix A


%CN-MCI

load Fl15

load unitsphere2562.mat   
left_average2=SPHARMaverage(Fl(1:18),sphere, 15,0);

n=15; 

for i=1:18

temp=SPHARMrepresent2(sphere,Fl(i),n,0);
leftsurf2(i,:,:)=temp.vertices;
end


avsurf.coord=left_average2.vertices;
avsurf.tri=left_average2.faces;

%g=[repmat(1,1,12) repmat(2,1,6) repmat(3,1,10)];
gruY=zeros(18,2);
gruY(1:12,1)=1;
gruY(13:18,2)=1;

term(gruY);

G=term(gruY);


e = SurfStatLinMod( leftsurf2, 1+G,avsurf);
e0 = SurfStatLinMod( leftsurf2, 1);
slm = SurfStatF(e,e0); 
figure_trimesh(left_average2,slm.t(1,:)); 
%figure_orgami(left_average2, slm.t)


pvalue = [0.001 0.005 0.01 0.05 0.1];
threshold=randomfield_threshold(slm, pvalue)

threshold =

  138.0769  106.1898   94.5683   69.1146   59.1712

%resels =  SurfStatResels(slm);
%stat_threshold(resels, length(slm.t), 1,slm.df, 0.01,[],[],[],slm.k)

sum( slm.t(1,:)>   69.1146)

ans =

     0
     
     max( slm.t(1,:))

ans =

   49.0183
   
   view(142.5,-30)
   lighting none
