dm 'log;clear;output;clear;'; options ps=50 ls=70 pageno=1; goptions reset=global border ftext=swiss gunit=cm htext=0.3 htitle=0.5; goptions display noprompt; **********************************************************************; ** **; ** AUTHOR: Chris Bilder **; ** COURSE: STAT 4043 **; ** DATE: 9-10-00 **; ** UPDATE: **; ** PURPOSE: Generate data with a nonlinear relationship only **; ** so that there is still constant variance **; ** **; ** NOTES: The SAS code for this program is beyond what is needed for**; ** students to understand in this class. **; ** **; **********************************************************************; title1 'Chris Bilder, STAT 4043'; *Read in the data set from a text file into a SAS data set called set1; data set1; do X=1 to 100 by 2; epsilon = 5*normal(864573); *generate N(0,1)random variables; Y1 = 2 + 10*X + 5*epsilon; *add more variability here for epsilon; Y2 = 2 + 10*sqrt(X) + epsilon; output; end; run; title2 'The generated data set'; proc print data=set1; run; data set2; do X=0.01 to 1 by 0.01; epsilon = 5*normal(534641); *generate N(0,1)random variables; Y3 = 2 + 10*(1/X) + epsilon; output; end; run; title2 'The second generated data set'; proc print data=set2; run; %MACRO ANALYSIS(Y, X, set); title2 'PROC REG with the generated data'; proc reg data=&set; model &Y = &X / r p; output out=out_set1 r=residual p=predicted; symbol1 v=dot h=.1 cv=blue; plot residual.*&X / nostat vref=0 cvref=red; run; *Create scatter plot with estimated simple linear regression line; proc gplot data=&set; plot &Y*&X / vaxis=axis1 haxis=axis2 frame; title2 "&Y vs. &X"; axis1 label = (a=90 "&Y") length=10 ; axis2 label=("&X") length=10 ; symbol1 v=dot h=.1 cv=blue ci=red i=RL; run; %MEND ANALYSIS; %ANALYSIS(Y1,X, set1); %ANALYSIS(Y2,X, set1); data set_tran1; set set1; X_sqrt = sqrt(X); X_log10 = log10(X); run; title2 'Sqrt transfromation regression example'; proc reg data=set_tran1; model Y2 = X_sqrt / r p; symbol1 v=dot h=.1 cv=blue; plot residual.*X_sqrt / nostat vref=0 cvref=red; run; %ANALYSIS(Y3,X, set2); data set_tran2; set set2; X_inv = 1/X; X_negexp = exp(-X); run; title2 'Inverse transfromation regression example'; proc reg data=set_tran2; model Y3 = X_inv / r p; symbol1 v=dot h=.1 cv=blue; plot residual.*X_inv / nostat vref=0 cvref=red; model Y2 = X_negexp / r p; symbol1 v=dot h=.1 cv=blue; plot residual.*X_negexp / nostat vref=0 cvref=red; run; quit;