/* Filename: PCAvsCASeriation.sas */ /* Purpose: Generate 4 fake battle-shipshaped curves and perform a PCA then a CA */ /* Last Update: FDN 4.23.02 */ data seriation; step=.1; m1=2; m2=4 ; m3=6; m4=8; do i = 2 to 8 by step; t1= probnorm(i-(m1-step))-probnorm(i-m1) ; t2= probnorm(i-(m2-step))-probnorm(i-m2) ; t3= probnorm(i-(m3-step))-probnorm(i-m3) ; t4= probnorm(i-(m4-step))-probnorm(i-m4) ; output; end; keep i t1 t2 t3 t4; data seriationpct; set seriation; total= sum(of t1 t2 t3 t4); array pct {*} t1 t2 t3 t4; do j=1 to dim(pct); pct(j)= pct(j)/total; end; drop j total; proc gplot; plot t1*i t2*i t3*i t4*i/ overlay; run; proc g3d; scatter t1*t2 = t3; run; proc print; run; /* do the pca -- note we use the COV matrix */ proc princomp data =seriation out=pca outstat=eigenstructure covariance; var t1 t2 t3 t4; proc plot; plot prin2*prin1 '*' $ i ; run; /* plot the eigenvectors */ data eigenvectors; set eigenstructure; where _type_='SCORE'; proc transpose data = eigenvectors out=eigenvectors name=type; proc print data=eigenvectors; proc plot data=eigenvectors; plot prin2*prin1= '*' $ type; run; /* do a ca and compare the results */ proc corresp data=seriation out=ca; id i; var t1 t2 t3 t4; proc plot; where _type_= 'OBS'; plot dim2*dim1 = '*' $ i ; proc plot; where _type_= 'VAR'; plot dim2*dim1 = '*' $ i ; run;