BookmarkSubscribeRSS Feed
jsconte18
Fluorite | Level 6

Hi

 

I have a model that has three parameters: intercept, x1, and x2. 

 

x1's p value is 0.7730

x2's p value is less than 0.0001

 

But x1's residual plot looks really good and spread out

while x2's shows a quadratic U shape

 

I am wondering why this is and what all goes into it. Thank you!

 

SAS code

DATA groupD17;
INPUT Y X1 X2;
DATALINES;
. . . data goes here . . .
;
PROC REG DATA=groupD17;
MODEL Y = X1 X2;
RUN;

 
2 REPLIES 2
StatDave
SAS Super FREQ

You probably need to add a quadratic term for X2 in your model. Create a variable: x22=x2**2; and then include it in your MODEL statement.

KevinScott
SAS Employee

The relationship between y and x1 x2 in your data can be captured by using a regression between y and just the quadratic term.  Assuming X2 is X1*X1, try running.

 

PROC REG DATA=groupD17;
MODEL Y = X2;
RUN;

 

And compare the Rsquare with the original model.

 

 

Here is an example that will help you understand why a model with only a quadratic term and no linear term can fit well:

 

data examples(drop=i);
do i=1 to 1000;
x1=10*ranuni(213)-5;
x2=x1*x1;
/*y_only_quad is a difference of squares with no linear term
y_only_quad=x1^2-4 + N(0,1) error*/
y_only_quad=(x1+2)*(x1-2) + rannor(33);
/*y_lin_quad is a quadratic polynomial with a linear term
y_lin_quad=x1^2+4x+4 + N(0,1) error*/
y_lin_quad=(x1+2)*(x1+2) + rannor(89);
output;
end;
run;

ods graphics;
proc sgplot data=examples;
scatter x=x1 y=y_only_quad;
scatter x=x1 y=y_lin_quad;
refline 0 / axis=y;
refline 0 / axis=x;
run;

/*linear term will not be significant assuming alpha level 0.05
rsquare is 0.98*/
proc reg data=examples;
model y_only_quad= x1 x2;
run;
quit;

/*remove linear term rsquare is still 0.98*/
proc reg data=examples;
model y_only_quad= x2;
run;
quit;

/*run model where the linear term is required
the linear term is significant at alpha level 0.05*/
proc reg data=examples;
model y_lin_quad= x1 x2;
run;
quit;

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!

What is ANOVA?

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.

Discussion stats
  • 2 replies
  • 329 views
  • 2 likes
  • 3 in conversation