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.
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).
input x y semimajor semiminor slope;
10 5 10 4 1
8 4 8 6 0
define statgraph ellipse;
entrytitle 'Parametric Ellipse';
scatterplot x=x y=y;
ellipseparm xorigin=x yorigin=y semimajor=semimajor semiminor=semiminor slope=slope;
proc sgrender data=ellipse template=ellipse;
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.