BookmarkSubscribeRSS Feed
Soula
Calcite | Level 5

I am trying to recreate an example in SAS from "Applied Multivariate STatistical Analysis" by Johnson and Wichern.  The example is 7.10, pg 400-401 of the 6th edition.   There are 2 predictors and 2 outcomes; we are predicitng a single point based on the fit of the regression model.  The problem comes when trying to actually plot the prediction and confidence ellipses centered about the specific predicted piont (therefore, we are not concrned with the overall ellipses for the means of the data, which SAS easily generates).

 

Does anyone have a any suggestions how to obtain such a plot?

 

Using SAS 9.3.

 

Thank you, 

 

 

3 REPLIES 3
Jay54
Meteorite | Level 14

If you have computed the center of the ellipse, the semi-major and semi-minor axis lengths with possibly the slope, then you can plot these using the GTL ELLIPSEPARM statement.  The parameters can come from a data set or values.  

 

Example attached.  Note use of LAYOUT OVERLAYEQUATED to keep x and y mapping uniform.  Also, the SCATTER is necessary, but if you don't want to see the origin points plotted, you can set their size to zero using the option MARKERATTRS=(SIZE=0).

 

data ellipse;
  input x y semimajor semiminor slope;
  datalines;
10 5 10 4 1
8 4 8 6 0
;
  run;

proc template;
  define statgraph ellipse;
    begingraph;
      entrytitle 'Parametric Ellipse';
      layout overlayequated;
        scatterplot x=x y=y;
        ellipseparm xorigin=x yorigin=y semimajor=semimajor semiminor=semiminor slope=slope;
      endlayout;
    endgraph;
  end;
run;


proc sgrender data=ellipse template=ellipse;
run;

Rick_SAS
SAS Super FREQ

I only have access to the 3rd edition, which uses different page numbers, but I think I found the example that you mention. The example is given in terms of covariance matrices and linear algebra, so I assume that you don't want to use the ELLIPSE statement in PROC SGPLOT but that you want to use the POLYGON statement to plot points that you have already computed.  Thus this really isn't a GRAPHICS question, but a question about computing an ellipse by hand.

 

I suggest you look at the article "Computing prediction ellipses from a covariance matrix", which shows how to generate points on an ellipse when you have the covariance matrix.  The example in the article is not your use-case, but it is releated. The blog example is for bivariate (X,Y) variables, and the prediction ellipse assumes a bivariate normal distribution.  That is similar to your use-case, since for multiple regression the two predicted values at X=Z_0 are beta`*Z_0 and that point estimate is distributed as N(beta`*Z_0,  Z_0`*inv(Z`Z)*Z_0*Sigma), as shown in the Johnson and Wichern text on the page before Example 7.10.

 

EV
Calcite | Level 5 EV
Calcite | Level 5

I've actually answered had to solve this recently and was looking for more ways to work on plots like these.  I have the same edition you do and ended up being able to use the code that is found in the PROC TEMPLATE for ellipses, (like an earlier contributor said) on the SAS site here.

 

If you make new a dataset with both measures of the width and legnth of the axies for each ellipse, to extend what the previous contributor did, then you can easily pull that into the PROC TEMPLATE code, and include it in a second ELLIPSEPARM statement in the PROC TEMPLATE step.  This will allow you to have both of the ellipses on the same graph, just like the book; I'm not sure what the correct slope should be though.  I used a slope of 1, and it looked ok.

 

Hope this helps.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1392 views
  • 0 likes
  • 4 in conversation