Dear SAS Users,
I am trying to reproduce a plot from a journal article and am in need of help for plotting the horizontal line showing deciles and tick marks of the concentration distribution. Is there an option within SAS Graphs that can achieve this? The plot was produced in S-Plus.
Thank you!
Yes, see the article "Decile calibration plots in SAS" for code and a discussion. In the article, the Y variable is the predicted probability (computed by using PROC LOGISTIC), but it looks like you want to use the predicted responses from a linear model instead.
Here is some sample code that shows the main idea. I didn't try to figure out what confidence limits the authors were using, so it might not match their plot, but it will demonstrate how to create the graph and you can replace the upper/lower limits with the correct estimates.
/* Simulate data */
%let N = 400; /* sample size */
data Have(keep= Y x);
call streaminit(1234); /* set the random number seed */
do i = 1 to &N; /* for each observation in the sample */
x = rand("lognormal", 0, 0.5);
y = -2.3 + 0.85*x + rand("Normal", 0, 2);
output;
end;
run;
proc reg data=Have plots=none;
model y = x;
output out=Fit Pred=Pred;
quit;
/* identify deciles */
proc rank data=Fit out=Decile groups=10;
var x;
ranks Decile;
run;
/* compute the mean and the empirical proportions (and CI) for each decile */
proc means data=Decile noprint alpha=0.1;
class Decile;
types Decile;
var Pred x;
output out=DecileOut mean=PredMean xMean
lclm=yLower uclm=yUpper; /* I'm not sure what CLs the authors are using */
run;
data All;
set Have DecileOut;
run;
title "Decile Plot";
proc sgplot data=All noautolegend;
reg x=x y=y / nomarkers CLM alpha=0.1;
scatter x=xMean y=PredMean / yerrorlower=yLower yerrorupper=yUpper;
fringe x;
run;
Yes, see the article "Decile calibration plots in SAS" for code and a discussion. In the article, the Y variable is the predicted probability (computed by using PROC LOGISTIC), but it looks like you want to use the predicted responses from a linear model instead.
Here is some sample code that shows the main idea. I didn't try to figure out what confidence limits the authors were using, so it might not match their plot, but it will demonstrate how to create the graph and you can replace the upper/lower limits with the correct estimates.
/* Simulate data */
%let N = 400; /* sample size */
data Have(keep= Y x);
call streaminit(1234); /* set the random number seed */
do i = 1 to &N; /* for each observation in the sample */
x = rand("lognormal", 0, 0.5);
y = -2.3 + 0.85*x + rand("Normal", 0, 2);
output;
end;
run;
proc reg data=Have plots=none;
model y = x;
output out=Fit Pred=Pred;
quit;
/* identify deciles */
proc rank data=Fit out=Decile groups=10;
var x;
ranks Decile;
run;
/* compute the mean and the empirical proportions (and CI) for each decile */
proc means data=Decile noprint alpha=0.1;
class Decile;
types Decile;
var Pred x;
output out=DecileOut mean=PredMean xMean
lclm=yLower uclm=yUpper; /* I'm not sure what CLs the authors are using */
run;
data All;
set Have DecileOut;
run;
title "Decile Plot";
proc sgplot data=All noautolegend;
reg x=x y=y / nomarkers CLM alpha=0.1;
scatter x=xMean y=PredMean / yerrorlower=yLower yerrorupper=yUpper;
fringe x;
run;
Thank you, Rick! I had seen the article you had referred to but I guess the keyword i was looking for was 'fringe'. I appreciate you explaining it with an example code.
For more information and examples, see "Decile plots in SAS".
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.