Principal Components Analysis (PCA) - SAS statistics code.
The basic objective of a PCA is to discover new variables called principal components, which are in decreasing order of importance, so that
1. They are uncorrelated.
2. The first principal component accounts for as much of the variability in the data as possible.
3. Each succeeding component accounts for as much of the remaining variability as possible.
Here is a SAS program for Principal Components Analysis (PCA). You can run the code with the given data below and interpret the results.
******
dm log 'clear';
dm output 'clear';
options nodate;
data PCA;
input X1 X2 X3 X4 X5 X6 X7 X8;
datalines;
6 7 2 5 8 7 8 8
9 10 5 8 10 9 9 10
7 8 3 6 9 8 9 7
5 6 8 5 6 5 9 2
6 8 8 8 4 4 9 5
7 7 7 6 8 7 10 5
9 9 8 8 8 8 8 8
9 9 9 8 9 9 8 8
9 9 7 8 8 8 8 5
4 7 10 2 10 10 7 10
4 7 10 0 10 8 3 9
4 7 10 4 10 10 7 8
6 9 8 10 5 4 9 4
8 9 8 9 6 3 8 2
4 8 8 7 5 4 10 2
6 9 5 7 8 9 8 9
8 7 7 7 9 5 8 6
6 8 8 4 8 8 6 4
6 7 8 4 7 8 5 4
4 8 7 8 8 9 10 5
;
PROC PRINCOMP DATA=PCA OUT=PCSCORES COVARIANCE;
VAR X1--X8;
title 'Principal Component Analysis';
RUN;
PROC FACTOR DATA=PCA scree;
VAR X1--X8;
TITLE2'Scree Plot of Eigenvalues';
RUN;
PROC PRINT DATA=PCSCORES;
VAR PRIN1 PRIN2 PRIN3;
TITLE2 'VALUES OF THE FIRST THREE PRINCIPAL COMPONENT SCORES';
RUN;
proc univariate data=pcscores plot;
var prin1 prin2;
TITLE2 'Univariate Analysis on the first two Principal Components';
run;
proc gplot DATA=PCSCORES;
plot prin2*prin1;
TITLE2 'A Scatter Plot of the First Two Principal Component Scores';
run;
quit;
*****
If you would like to have the SAS interpretation of PCA, please leave me a comment.
4 Comments:
I would like to understand how the PCA scores are calculated (in detail) for a correlation option.
August 26, 2008 10:53 AM
I'm wondering if you could/can answer this question regarding SAS coding.
I've done a principle components analysis (PROC PRINCOMP) and now want to get a factor score. I can't find any SAS code anywhere on how to do this? (Do I have to do proc factor and then proc score? Or can I just do a proc score after proc princomp? I'm doing something wrong because it isn't working. Thanks in advance.
November 09, 2008 11:24 AM
how do you store these prin values to use in proc logistic?
March 20, 2009 3:12 PM
I want to find out the climatological regions based on the rainfall data using principal component analysis (PCA) i have almost 71 meteorological stations for 30 years climatological records. So i would like to have the SAS interpretation of PCA.And also to know how its works.
St.Petersburg
April 25, 2009 7:32 PM
<< Home