data sample;
input x1 x2 y;
datalines;
1 1 2
2 2 4
3 3 6
4 4 8
;
run;
My objective is to build a regression model for y against x1 and x2;
* For y versus x1, plot the regression model, prediction interval for individual response, and confidence interval for the mean response;
* For y versus x2, plot the regression model, prediction interval for individual response, and confidence interval for the mean response;
* Below, I attempted to plot prediction interval and confidence interval using PRED and CONF as defined/shown in the following links;
* https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_reg_sect017... ;
* https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_reg_sect036... ;
* However, PRED and CONF cannot handle multiple independent variables;
I am wondering if ODS could plot prediction intervals and confidence intervals for multiple independent variables;
proc reg data = sample;
title "Plot of Confidence Interval and Prediction Interval for Regression Model of Y Versus X";
model Y = X;
plot Y*X / CONF PRED;
run;
Something like this perhaps?
data sample; input x1 y x2; datalines; 1.2 1 2.2 2.3 2 3.8 2.8 3 5.9 3.9 4 8.3 ; run; proc sgplot data=sample; reg x=x1 y=y/ cli='X1 I' clm='X1 Mean' lineattrs=(color=red) ; reg x=x2 y=y/ cli='X2 I' clm='X2 Mean' lineattrs=(color=blue) ; run;
I used a different data set as your examples were 1) colinear and had insufficient variability to show any confidence limits and 2) plotted directly on top of each other.
Something like this perhaps?
data sample; input x1 y x2; datalines; 1.2 1 2.2 2.3 2 3.8 2.8 3 5.9 3.9 4 8.3 ; run; proc sgplot data=sample; reg x=x1 y=y/ cli='X1 I' clm='X1 Mean' lineattrs=(color=red) ; reg x=x2 y=y/ cli='X2 I' clm='X2 Mean' lineattrs=(color=blue) ; run;
I used a different data set as your examples were 1) colinear and had insufficient variability to show any confidence limits and 2) plotted directly on top of each other.
Thank you Sir @ballardw I'm afraid I beg your pardon to give a day to respond as I play with my team mate at my college lab tomorrow and take his opinion as well. I am basically writing to acknowledge the help. As always not the 1st or last of receiving your help, many thanks. 🙂
Sir @ballardw , Let us know how to thank you 🙂
One way to show a bivariate regression is to do panelling. For example, the relationship of Cholesterol with Age and Weight in the SASHELP.HEART dataset can be illustrated by showing the relationship of Cholesterol with Weight within separate Age groups:
data heart;
set sashelp.heart;
where ageAtStart between 30 and 59.99;
/* 10-year age groups for graph panels */
ageGrp = floor(AgeAtStart/10)*10 + 5;
/* Second order term for the regression */
ageWeight = ageAtStart*weight;
/* Real data */
data = "Heart";
output;
/* Add extra data for age group line drawing */
ageAtStart = ageGrp;
ageWeight = ageAtStart*weight;
call missing(cholesterol);
data = "Graph";
output;
label ageWeight = "Age*Weight";
keep weight height ageAtStart ageGrp cholesterol ageWeight data;
run;
proc reg data=heart plots=none;
model cholesterol = weight ageAtStart ageWeight / alpha=0.1;
output out=heartPred p=pred lcl=lcl ucl=ucl;
run;
/* Create separate columns for drawing regression lines */
data heartGraph;
set heartPred;
if data = "Graph" then do;
predValue = pred;
lclValue = lcl;
uclValue = ucl;
end;
run;
proc sort data=heartGraph; by AgeGrp weight;run;
proc format;
value ageGrp
35 = "30-39"
45 = "40-49"
55 = "50-59";
run;
ods graphics / width=20cm height=12cm antialiasmax=200000;
proc sgpanel data=heartGraph noautolegend;
format ageGrp ageGrp.;
panelby ageGrp / rows=1;
band x=weight upper=uclValue lower=lclValue;
series x=weight y=predValue / lineattrs=(color=red thickness=2);
scatter x=weight y=cholesterol;
run;
hth.
Good morning @PGStats, Thank you Sir. I have just made it to my lab and I couldn't acknowledge your post last nightas I slept off. I will work my mate and positively come back to the thread to let you know how we tried and our progress.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.