ods graphics on; title 'simple linear regression example'; data drinking; input country $ 1-12 alcohol cirrhosis; cards; France 24.7 46.1 Italy 15.2 23.6 W.Germany 12.3 23.7 Austria 10.9 7.0 Belgium 10.8 12.3 USA 9.9 14.2 Canada 8.3 7.4 E&W 7.2 3.0 Sweden 6.6 7.2 Japan 5.8 10.6 Netherlands 5.7 3.7 Ireland 5.6 3.4 Norway 4.2 4.3 Finland 3.9 3.6 Israel 3.1 5.4 ; run; proc sgplot data=drinking; scatter x=alcohol y=cirrhosis / datalabel=country; run; proc reg data=drinking; model cirrhosis=alcohol; run; ods graphics off; title 'multiple linear regression example'; data uscrime; infile '.\Dropbox\Teaching\1301-StatisticalPackages\datasets\uscrime.dat' expandtabs; input R Age S Ed Ex0 Ex1 LF M N NW U1 U2 W X; run; proc reg data=uscrime; model R= Age--X; run; delete S; print; run; delete Ex0--U1; print; run; reweight obs. eq 10 or cookd. >= 0.25; print; run; quit; title 'model diagnostic'; proc sgscatter data=uscrime; matrix R--X; run; proc corr data = uscrime; var R--X; run; proc reg data=uscrime; model R = Age--X / pcorr2 partial; run; ods graphics on; proc reg data=uscrime; model R = Age--X / influence; run; proc reg data=drinking; model cirrhosis=alcohol; output out = drinkingfit predicted = yhat residual = resid student = rstandard rstudent = rstudent h = leverage cookd = cooksd; run; proc print data = drinkingfit; run; title 'cirrhosis model building'; proc reg data=drinking; model cirrhosis=alcohol; where country ne 'France'; run; quit; data drinking; set drinking; alcohol2 = alcohol*alcohol; lx = log10(alcohol); lx2 = lx*lx; lcirrhosis = log10(cirrhosis); run; proc reg data=drinking; model cirrhosis=alcohol alcohol2; where country ne 'France'; run; quit; proc reg data=drinking; model cirrhosis = lx lx2 /partial; where country ne 'France'; output out = drinkingfit predicted = yhat ; run; quit; proc sgplot data=drinkingfit; scatter x= lx y=cirrhosis / datalabel=country; series x = lx y = yhat ; run; title 'US Crime model building'; proc reg data=uscrime; model R= Age--X / vif; run; proc reg data=uscrime; model R= Age--Ed Ex1--X / vif collin; run; proc reg data=uscrime plots=criteria outest=RegOut; model R= Age--Ed Ex1--X / selection=stepwise sle=.05 sls=.05; * model R= Age--Ed Ex1--X / selection=forward; * model R= Age--Ed Ex1--X / selection=backward; * model R= Age--Ed Ex1--X / selection=ADJRSQ; run; quit; title 'Prediction'; proc reg data=drinking outest=RegOut; model cirrhosis = lx lx2; where country ne 'France'; run; proc print data = RegOut; run; proc score data=drinking score=RegOut out=Prediction type=parms; var lx lx2; run; proc print data = Prediction; run; proc sgplot data = Prediction; scatter x= lx y= cirrhosis / datalabel=country; series x= lx y = model1; run; data new; input alcohol cirrhosis; lx = log10(alcohol); lx2 = lx*lx; new = 'new'; cards; 20.7 36.1 5.2 7.6 ; run; data combinded; set new drinking; run; proc score data=combinded score=RegOut out=Prediction type=parms; var lx lx2; run; proc sort data = Prediction; by lx; proc sgplot data = Prediction; scatter x= lx y= cirrhosis / datalabel=country group = new; series x= lx y = model1; run;