* ADA2_03.sas ; * SAS code from Chapter 03 ; * Stat 428/528 Advanced Data Analysis II ; * ; * Prof. Erik Erhardt ; * University of New Mexico ; * Spring 2012 ; *******************************************************************************; * Indian systolic blood pressure example; * correlation, plots, regression, backwards selection, diagnostics; * set options; options ls=79 nodate nocenter; * read in data; data indian; infile "F:\Dropbox\UNM\teach\ADA2_stat528\sas\ADA2_02_indian.dat"; input n x1-x11; label x1='age in years' x2='years since migration' x3='weight in kilos' x4='height in mm' x5='chin skin fold in mm' x6='forearm skin fold in mm' x7='calf skin fold in mm' x8='pulse rate-beats/min' x9='systolic bp' x10='diastolic bp' x11='years since migration div by age' x12='cat weight'; y=x9; * response variable; label x9='systolic bp'; run; * correlation of y with each x; proc corr data=indian nosimple noprob; var y; with x3 x4 x5 x6 x7 x8 x11; * corr of y with these x variables; * (no xs with each other); run; * plot y with each x; * define v=symbol, c=color, and i=interpolation; symbol1 v=circle c=black i=none; proc gplot data=indian; plot y*(x3 x4 x5 x6 x7 x8 x11); run; * regression with backward selection; proc reg data=indian; model y = x3 x4 x5 x6 x7 x8 x11 /selection = backward; * backward selection; run; * final model with diagnostics; proc reg data=indian; model y = x3 x11 /p r partial; plot student.*predicted. nqq.*student. cookd.*obs.; * diagnostic plots; run; title ''; *******************************************************************************; * rat liver example; * set options; options ls=79 nodate nocenter; * read data; data ratliver; infile "F:\Dropbox\UNM\teach\ADA2_stat528\sas\ADA2_03_ratliver.dat"; input bodywt liverwt dose y; run; * correlation of y with each x; proc corr data=ratliver nosimple noprob; run; * plot y with each x; * define v=symbol, c=color, and i=interpolation; symbol1 v=circle c=black i=none; proc gplot data=ratliver; plot y*(bodywt liverwt dose); run; ** Two ways to get scatterplot matrices in SAS; * use the "output delivery system" in SAS v9.1+ ; * cite: http://www.ats.ucla.edu/stat/sas/faq/sas9_stat_plots.htm ; * scatterplot matrix; ods html style=journal; * turn on html output; ods graphics on; * turn on ods graphics; proc corr data=ratliver plots; var y bodywt liverwt dose; run; ods graphics off; ods html close; * sgscatter is in v9.2+ ; * cite: http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#a003155769.htm ; * scatterplot matrix; proc sgscatter data=ratliver; matrix y bodywt liverwt dose; run; * regression with backward selection; proc reg data=ratliver; model y = bodywt liverwt dose /selection = backward; * backward selection; run; * Diagnostic Analysis for Model Selected by Backward Elimination; proc reg data=ratliver; model y = bodywt dose /p r partial; run; * Redo model selection after holing out case 3; data ratliver2; set ratliver; if _N_ = 3 then delete; run; * regression with backward selection; proc reg data=ratliver2; model y = bodywt liverwt dose /selection = backward; * backward selection; run; *******************************************************************************;