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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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