BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hello everyone, I would like to know how I can plot a figure like this?

Screenshot 2021-08-23 163005.jpg

The explanation is:

Median (black line) and interquartile range
(blue area) are indicated. The green area indicates the ranges 10th–25th and 75th–90th percentiles, respectively.
The red area indicates the ranges 5th–10th percentiles and 90th–95th percentiles. Data were obtained by quantile
regression.

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If you need the PROC QUANTREG code, follow this example. An explanation of the program is in the link I posted earlier.

 

/* Program based on "How to score and graph a quantile regression model in SAS"
   https://blogs.sas.com/content/iml/2018/08/06/score-quantile-regression-sas.html
*/
data Orig;
   set sashelp.bweight(obs=5000 where=(MomWtGain<=40));
   keep MomAge Weight Boy;
run;

proc means  data=orig;run;

data Score;
Weight = .;
do Boy = 0 to 1;
   do MomAge = -9 to 17;
      output;
   end;
end;

data Combined;
set Orig                     /* original data */
    Score(in=_ScoreData);    /* scoring data  */
ScoreData = _ScoreData;      /* binary indicator variable. ScoreData=1 for scoring data */
run;
 
/* 3. Run the procedure on the combined (original + scoring) data */
ods select ModelInfo NObs;
proc quantreg data=Combined ci=none;
   class Boy;
   model Weight = MomAge Boy / quantile = 0.1 0.05 0.25 0.5 0.75 0.90 0.95;
   output out=QRegOut(where=(ScoreData=1)) /* output predicted values for the scoring data */
              P=Pred / columnwise;         /* COLUMWISE option supports multiple quantiles */
run;

proc sort data=QRegOut;
by Boy MomAge Quantile;
run;

Data Wide;
set QRegOut;
retain Pred05 Pred10 Pred25 Pred50 Pred75 Pred90 Pred95;
if      Quantile=0.05 then Pred05 = Pred;
else if Quantile=0.10 then Pred10 = Pred;
else if Quantile=0.25 then Pred25 = Pred;
else if Quantile=0.50 then Pred50 = Pred;
else if Quantile=0.75 then Pred75 = Pred;
else if Quantile=0.90 then Pred90 = Pred;
else if Quantile=0.95 then Pred95 = Pred;
if Quantile=0.95 then output;
drop Pred;
keep Boy MomAge Pred:;
run;

proc sgpanel data=Wide noautolegend;
   panelby Boy;
   band x=MomAge lower=Pred05 upper=Pred95 / fillattrs=(color=salmon); 
   band x=MomAge lower=Pred10 upper=Pred90 / fillattrs=(color=LightGreen); 
   band x=MomAge lower=Pred25 upper=Pred75 / fillattrs=(color=LightBlue); 
   series x=MomAge y=Pred50 / lineattrs=(color=Black); 
run;

View solution in original post

10 REPLIES 10
Rick_SAS
SAS Super FREQ

It sounds like you have used PROC QUANTREG to compute the 5th, 10th, 25th, 50th, 75th, 90th, and 95th estimates.  Have you already used the OUTPUT statement to write the predicted values to a SAS data set? Do you have the data in wide form (as opposed to long form)? If so, then use the BAND statement in PROC SGPLOT to get the plot:

 

/* for wide data */
proc sgplot data=Have;
   band x=X lower=Pred05 upper=Pred95; 
   band x=X lower=Pred10 upper=Pred90; 
   band x=X lower=Pred25 upper=Pred75; 
   series x=X y=Pred50; 
run;

For more information and an example, see "How to score and graph a quantile regression model in SAS."

 

If this doesn't answer your questions, please provide sample data so that we can see the form of your data.

mantubiradar19
Quartz | Level 8

Hi Rick, this is how my data looks like:

ID	eGFR	Gender	Age
110	55	Male	45
111	67	Female	60
112	87	Female	78
114	68	Male	65
115	90	Male	43
116	87	Female	56
117	34	Male	67
118	58	Male	78
119	70	Female	89
120	80	Male	76
Rick_SAS
SAS Super FREQ

That's your original data, but what does the data look like that you intend to plot?  Show us the PROC QUANTREG step you are using to get the regression quantiles.

Rick_SAS
SAS Super FREQ

If you need the PROC QUANTREG code, follow this example. An explanation of the program is in the link I posted earlier.

 

/* Program based on "How to score and graph a quantile regression model in SAS"
   https://blogs.sas.com/content/iml/2018/08/06/score-quantile-regression-sas.html
*/
data Orig;
   set sashelp.bweight(obs=5000 where=(MomWtGain<=40));
   keep MomAge Weight Boy;
run;

proc means  data=orig;run;

data Score;
Weight = .;
do Boy = 0 to 1;
   do MomAge = -9 to 17;
      output;
   end;
end;

data Combined;
set Orig                     /* original data */
    Score(in=_ScoreData);    /* scoring data  */
ScoreData = _ScoreData;      /* binary indicator variable. ScoreData=1 for scoring data */
run;
 
/* 3. Run the procedure on the combined (original + scoring) data */
ods select ModelInfo NObs;
proc quantreg data=Combined ci=none;
   class Boy;
   model Weight = MomAge Boy / quantile = 0.1 0.05 0.25 0.5 0.75 0.90 0.95;
   output out=QRegOut(where=(ScoreData=1)) /* output predicted values for the scoring data */
              P=Pred / columnwise;         /* COLUMWISE option supports multiple quantiles */
run;

proc sort data=QRegOut;
by Boy MomAge Quantile;
run;

Data Wide;
set QRegOut;
retain Pred05 Pred10 Pred25 Pred50 Pred75 Pred90 Pred95;
if      Quantile=0.05 then Pred05 = Pred;
else if Quantile=0.10 then Pred10 = Pred;
else if Quantile=0.25 then Pred25 = Pred;
else if Quantile=0.50 then Pred50 = Pred;
else if Quantile=0.75 then Pred75 = Pred;
else if Quantile=0.90 then Pred90 = Pred;
else if Quantile=0.95 then Pred95 = Pred;
if Quantile=0.95 then output;
drop Pred;
keep Boy MomAge Pred:;
run;

proc sgpanel data=Wide noautolegend;
   panelby Boy;
   band x=MomAge lower=Pred05 upper=Pred95 / fillattrs=(color=salmon); 
   band x=MomAge lower=Pred10 upper=Pred90 / fillattrs=(color=LightGreen); 
   band x=MomAge lower=Pred25 upper=Pred75 / fillattrs=(color=LightBlue); 
   series x=MomAge y=Pred50 / lineattrs=(color=Black); 
run;

mantubiradar19
Quartz | Level 8

Hi Rick, 

 

Thank you and I was able to obtain a similar-looking plot from quantile regression results. I would like to know how I can add the intervals of 5 units to the x and y axis? TIA

Rick_SAS
SAS Super FREQ

For the X axis, use the COLAXIS statement:

colaxis values=(35 to 70 by 5) valuesHint;

 

For the Y axis, use the ROWAXIS statement:

rowaxis values=(60 to 125 by 5) valuesHint;

 

 

mantubiradar19
Quartz | Level 8
Thanks Rick!
mantubiradar19
Quartz | Level 8

Hi Rick, 

 

I'm further interested in looking at the distribution of decline in variables over time. How can I tabulate the distribution of slopes of regression lines over individuals?

 

Thanks in advance

Rick_SAS
SAS Super FREQ

Since the data you posted does not include a Time variable nor repeated observations for individuals, I suggest you start a new thread. Include data that we can use and the PROC code that you are using to model the slopes as a function of time.

mantubiradar19
Quartz | Level 8

Thanks, Rick! will do 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 901 views
  • 7 likes
  • 2 in conversation