/*********************************************** SAS EXAMPLE 6 -- INTERACTION IN REGRESSION POLYNOMIAL REGRESSION FILENAME: REGRESS_INT.SAS ************************************************/ OPTIONS NODATE FORMDLIM=" " PAGENO=1; TITLE; /*IMPORT SPSS PORTABLE FILE INTO SAS*/ filename file1 "c:\kwelch\workshops\regression\data\htwt.por"; proc convert spss=file1 out=htwt; run; proc means; run; /*CREATE DUMMY VARIABLE AND INTERACTION*/ data htwt2; set htwt; female=(sex="f"); femage=female*age; run; /*REGRESSION PLOT FOR MALES AND FEMALES*/ goptions reset=all; goptions device=win target=winprtm; symbol1 color=black value=star interpol=rl line=1; symbol2 color=black value=dot interpol=rl line=3; proc gplot data=htwt2; where age <=20; plot height * age = sex; title "Regression Plot Males vs. Females"; run; quit; proc reg data=htwt2; model height = age female femage; run; quit; /*REGRESSION PLOT WITH EXTRAPOLATION TO ZERO*/ goptions reset=all; goptions device=win target=winprtm; symbol1 color=black value=star interpol=rl line=1; symbol2 color=black value=dot interpol=rl line=3; axis1 order=0 to 20 by 2; axis2 order= 10 to 80 by 10; proc gplot data=htwt2; where age <=20; plot height * age = sex / haxis=axis1 vaxis=axis2; title "Regression Plot Extrapolated to Zero"; run;quit; /*CENTER AGE TO FACILITATE INTERPRETATION OF MAIN EFFECT*/ data htwt2; set htwt2; centage = age-16.5; femcage = female*centage; run; proc reg data=htwt2; model height = centage female femcage; run; quit; /*********************************************************** POLYNOMIAL REGRESSION ***********************************************************/ /*POLYNOMIAL REGRESSION FOR MALES AND FEMALES*/ goptions reset=all; goptions device=win target=winprtm; symbol1 color=black value=star interpol=rq line=1; symbol2 color=black value=dot interpol=rq line=3; proc gplot data=htwt2; where age <=20; plot height * age = sex; title "Quadratic Regression Plot Males vs. Females"; run; quit; /*GENERATE POLYNOMIALS FOR AGE*/ data htwt2; set htwt2; centage2 = centage*centage; femcage2 = female*centage2; run; proc reg; model height = centage female femcage centage2 femcage2; run; quit; proc reg; model height = centage female femcage centage2 ; output out=preddat p=predict r=resid; run; quit; /*POLYNOMIAL REGRESSION FOR BOTH SEXES*/ goptions reset=all; goptions device=win target=winprtm; symbol1 color=black value=star ; symbol2 color=black interpol=join line=1; symbol3 color=black interpol=join line=3; axis1 order=13 to 20 by 1; axis2 order=50 to 80 by 10 ; proc sort data=preddat; by age; run; proc gplot data=preddat; where age <=20; plot height * age / haxis=axis1 vaxis=axis2; plot2 predict*age = sex / haxis=axis1 vaxis=axis2; title "Fitted Regression for Males vs. Females"; run; quit;