BookmarkSubscribeRSS Feed
Dmonk
Calcite | Level 5

Hello out there,

I need advice on creating a scatter plot of my first two principal componants with confidence ellipses around each of the five species I am investigating, I know how to do this in SAS, but not the enterprise guide.  Here is the input I have been using to get the graph without ellipses:

PROC PRINCOMP DATA=PCA OUT=PCSCORES COVARIANCE;

VAR X1 X2 X3 X4 X5 X6 X7 X8 X9;

title 'PCAVCANMAND';

RUN;

proc gplot DATA=PCSORES;

plot prin2*prin1=Species

RUN;

Any advice on how to add confidence ellipses to the output graph would be appreciated.

4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12

you could just edit the code to look like what you do in regular SAS.

Doc Muhlbaier

Duke

Dmonk
Calcite | Level 5

...well yes...but what I normally would do in sas is get the output for the PCA, go up to solutions-->analysis-->interactive data analysis, get the PCS scores and then use analyze-->multivariate to get it to produce graphs with ellipses.  Those options don't exist in enterprise but I'm told that it's possible to do.

Doc_Duke
Rhodochrosite | Level 12

Sorry, I can't help further.  I haven't done a PCA in years.    If you are hand coding the entire thing, then PROC SGPLOT might be a good tool to bet your elipses.

Cynthia_sas
SAS Super FREQ

Hi:

  If you are running SAS 9.2 or higher, you can modify the PRINCOMP code directly to create an ellipse from your PRINCOMP procedure using the PLOTS= option.

  Otherwise, as Doc suggested, if you want to make a dataset and then plot the points yourself, I find SGPLOT to be the most straightforward -- you only need a SCATTER statement and an ELLIPSE statement. Of course, with the PRINCOMP "direct" approach, you only need the PLOTS= option.

  I believe that either one involves modifying the code a bit. The attached program makes some fake data then. shows both approaches.

cynthia


data testdata;

   input grpvar $3. (x1-x14) (1.);

return;

datalines;

s1 26838853879867

s2 74758876857667

s1 56757863775875

s2 67869777988997

s3 99997798878888

s3 89897899888799

s1 89999889899798

s2 87794798468886

s3 35652335143113

s1 89888879576867

s2 76557899446397

s3 97889998898989

s1 76766677598888

s2 99899899899899

s3 76656399567486

;

run;

         

ods _all_ close;

ods listing close;

ods html path='c:\temp' (url=none)

         file='something.html'  style=egdefault;

     

ods graphics on;

PROC PRINCOMP DATA=testdata OUT=PCSCORES COVARIANCE

             PLOTS(NCOMP=2)=(SCORE(ellipse));

title '1)PRINCOMP direct approach with ODS GRAPHICS';

VAR X1 X2 X3 X4 X5 X6 X7 X8 X9  ;

RUN;

     

ods graphics off;

   

proc sgplot data=pcscores;

  title '2) Use SGPLOT with SCATTER and ELLIPSE';

  scatter x=prin1 y=prin2/group=grpvar;

  ellipse x=prin1 y=prin2;

run;

     

ods  _all_  close;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2264 views
  • 0 likes
  • 3 in conversation