NOTE: Copyright (c) 1999-2001 by SAS Institute Inc., Cary, NC, USA. NOTE: SAS (r) Proprietary Software Release 8.2 (TS2M0) Licensed to GEORGE WASHINGTON UNIVERSITY-CAMPUSWIDE-T/R, Site 0001180006. NOTE: This session is executing on the WIN_ME platform. NOTE: SAS initialization used: real time 19.23 seconds 1 *** sh_b from old ST210H; 2 3 options formdlim='-'; 4 5 filename sh_blst 'c:\sasjobs\stat210\jl2003\sh_blst.pdf'; 6 ods printer pdf file=sh_blst; NOTE: Writing ODS PRINTER output to DISK destination "c:\sasjobs\stat210\jl2003\sh_blst.pdf", printer "PDF". 7 8 %macro runloess (data=_last_,out=,x=,y=,f=0.5); 9 proc loess data=&data; 10 model &y = &x /smooth=&f; 11 ods output OutputStatistics=&out; 12 title2 "smoothed plot of &y versus &x with smooth &f"; 13 proc plot; by SmoothingParameter; 14 plot DepVar*&x='*' Pred*&x='+' / overlay; 15 run; 16 %mend; 17 18 %MACRO rsquare; 19 data; set end=eof; 20 retain lab n1 nT; 21 if _n_ = 1 then do; 22 lab=1; n1=0; nt=0; 23 end; 24 if oy=1 then n1 = n1+1; 25 if oy ge 0 then do; 26 nt=nt+1; 27 lab = lab * ( (p**oy) * ((1-p)**(1-oy)) ); 28 end; 29 if eof then do; 30 alpha = log( (n1/nt)/(1 - (n1/nt)) ); 31 pa = exp(alpha) / (1 + exp(alpha)); 32 la = (pa**n1) * ( ((1-pa)**(nt-n1)) ); 33 nullchi = -2*log(la); 34 abchi = -2*log(lab); 35 modchi = nullchi - abchi; 36 r2ent = modchi/nullchi; 37 r2chi = 1 - exp(-modchi/nt); 38 output; 39 end; 40 proc print; var n1 nt pa la lab nullchi abchi modchi r2ent r2chi; 41 title3 'cross validation r-square measures'; 42 43 %MEND; 44 RUN; 45 46 DATA FITNESS; 47 INPUT AGE WEIGHT OXY RUNTIME RSTPULSE RUNPULSE MAXPULSE NONSMOKE; 48 N=1; 49 Y=0; IF OXY > 47 THEN Y = 1; *****NONSMOKE=1=NONSMOKER; 50 ***** 0=SMOKER; 51 CARDS; NOTE: The data set WORK.FITNESS has 31 observations and 10 variables. NOTE: DATA statement used: real time 0.65 seconds 83 ; 84 85 PROC LOGISTIC DESCENDING DATA = FITNESS OUTEST=BETAS; 86 MODEL Y= AGE WEIGHT RUNTIME RUNPULSE NONSMOKE 87 / clodds=both lackfit rsquare CORRB INFLUENCE IPLOTS; 88 OUTPUT OUT=DUM1 XBETA=XB STDXBETA=SDXB L=L P=P U=U; 89 TITLE2 'LOGISTIC REGRESSION WITH ALL VARIABLES'; 90 NOTE: PROC LOGISTIC is modeling the probability that Y=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 31 observations read from the data set WORK.FITNESS. NOTE: The data set WORK.BETAS has 1 observations and 11 variables. NOTE: The data set WORK.DUM1 has 31 observations and 16 variables. NOTE: PROCEDURE LOGISTIC used: real time 3.19 seconds 91 PROC GENMOD DATA = FITNESS; 92 MODEL Y/N = AGE WEIGHT RUNTIME RUNPULSE NONSMOKE 93 / DIST=BIN LINK=LOGIT TYPE3; 94 TITLE2 'LOGISTIC REGRESSION THROUGH GENMOD'; 95 NOTE: Algorithm converged. NOTE: The scale parameter was held fixed. NOTE: PROCEDURE GENMOD used: real time 1.04 seconds 96 PROC PRINT DATA=DUM1; VAR AGE WEIGHT RUNTIME RUNPULSE NONSMOKE 97 Y XB SDXB L P U; 98 NOTE: There were 31 observations read from the data set WORK.DUM1. NOTE: PROCEDURE PRINT used: real time 0.04 seconds 99 DATA PARTIAL; 100 RETAIN B0 B1 B2 B3 B4 B5; 101 ARRAY B (5) B1-B5; 102 ARRAY X (5) 103 AGE WEIGHT RUNTIME RUNPULSE NONSMOKE; 104 ARRAY RES (5) RES1-RES5; 105 IF _N_=1 THEN SET BETAS 106 (RENAME = (INTERCEPt=B0 107 AGE=B1 WEIGHT=B2 RUNTIME=B3 RUNPULSE=B4 NONSMOKE=B5)); 108 SET FITNESS; 109 ETA=B0; 110 DO J = 1 TO 5; 111 ETA = ETA + (X(j)*B(j)); 112 END; 113 P = 1/(1+EXP(-ETA)); 114 DO J = 1 TO 5; 115 RES(J) = B(J)*X(J) + (Y-P)/(P*(1-P)); 116 END; 117 118 title2 'partial residual plots with lowess smother'; 119 TITLE3 'Scatter-plots of partial residuals for each covariate'; 120 %runloess (data=partial,out=smooth,x=age,y=res1,f=0.5); NOTE: There were 1 observations read from the data set WORK.BETAS. NOTE: There were 31 observations read from the data set WORK.FITNESS. NOTE: The data set WORK.PARTIAL has 31 observations and 29 variables. NOTE: DATA statement used: real time 0.22 seconds NOTE: The data set WORK.SMOOTH has 31 observations and 5 variables. NOTE: PROCEDURE LOESS used: real time 0.33 seconds 121 %runloess (data=partial,out=smooth,x=weight,y=res2,f=0.5); NOTE: There were 31 observations read from the data set WORK.SMOOTH. NOTE: PROCEDURE PLOT used: real time 0.11 seconds NOTE: The data set WORK.SMOOTH has 31 observations and 5 variables. NOTE: PROCEDURE LOESS used: real time 0.10 seconds 122 %runloess (data=partial,out=smooth,x=runtime,y=res3,f=0.5); NOTE: There were 31 observations read from the data set WORK.SMOOTH. NOTE: PROCEDURE PLOT used: real time 0.06 seconds NOTE: The data set WORK.SMOOTH has 31 observations and 5 variables. NOTE: PROCEDURE LOESS used: real time 0.26 seconds 123 %runloess (data=partial,out=smooth,x=runpulse,y=res4,f=0.5); NOTE: There were 31 observations read from the data set WORK.SMOOTH. NOTE: PROCEDURE PLOT used: real time 0.00 seconds NOTE: The data set WORK.SMOOTH has 31 observations and 5 variables. NOTE: PROCEDURE LOESS used: real time 0.17 seconds 124 NOTE: There were 31 observations read from the data set WORK.SMOOTH. NOTE: PROCEDURE PLOT used: real time 0.04 seconds 125 PROC LOGISTIC DESCENDING DATA = FITNESS; 126 MODEL Y= AGE WEIGHT RUNTIME RUNPULSE NONSMOKE 127 / SELECTION=B SLS=0.1 DETAILS; 128 TITLE2 'BACKWARDS ELIMINATION LOGISTIC REGRESSION WITH ALL VARIABLES'; 129 130 RUN; NOTE: PROC LOGISTIC is modeling the probability that Y=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied in Step 0. NOTE: Convergence criterion (GCONV=1E-8) satisfied in Step 1. NOTE: Convergence criterion (GCONV=1E-8) satisfied in Step 2. NOTE: Convergence criterion (GCONV=1E-8) satisfied in Step 3. NOTE: There were 31 observations read from the data set WORK.FITNESS. NOTE: PROCEDURE LOGISTIC used: real time 0.60 seconds 131 132 PROC LOGISTIC DESCENDING DATA=FITNESS; 133 MODEL Y=NONSMOKE RUNTIME / RL rsquare; 134 OUTPUT OUT=OUT1 XBETA=XB STDXBETA=SDXB L=L P=P U=U; 135 TITLE2 'LOGISTIC REGRESSION, REDUCED MODEL'; 136 NOTE: PROC LOGISTIC is modeling the probability that Y=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 31 observations read from the data set WORK.FITNESS. NOTE: The data set WORK.OUT1 has 31 observations and 16 variables. NOTE: PROCEDURE LOGISTIC used: real time 0.44 seconds 137 DATA SETA SETB SETAB; SET FITNESS; 138 UN=UNIFORM(44217); 139 BY=.; AY=.; 140 IF UN<=0.5 THEN DO; BY=Y; OUTPUT SETB; END; 141 IF UN> 0.5 THEN DO; AY=Y; OUTPUT SETA; END; 142 OUTPUT SETAB; 143 144 *** NOTE REDUCED MODEL WITH NONSMOKE AND RUNTIME ONLY USED FOR VALIDATION 145 DUE TO SMALL SAMPLE SIZES, OTHERWISE DEGENERATE LOGISTIC REGRESSIONS 146 RESULT; 147 NOTE: There were 31 observations read from the data set WORK.FITNESS. NOTE: The data set WORK.SETA has 19 observations and 13 variables. NOTE: The data set WORK.SETB has 12 observations and 13 variables. NOTE: The data set WORK.SETAB has 31 observations and 13 variables. NOTE: DATA statement used: real time 0.44 seconds 148 PROC LOGISTIC DESCENDING DATA=SETAB; 149 MODEL AY=NONSMOKE RUNTIME / RL rsquare; 150 OUTPUT OUT=C L=L P=P U=U; 151 TITLE2 ' LOGISTIC REGRESSION WITH TWO VARIABLES -- A SET'; 152 NOTE: PROC LOGISTIC is modeling the probability that AY=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 31 observations read from the data set WORK.SETAB. NOTE: The data set WORK.C has 31 observations and 17 variables. NOTE: PROCEDURE LOGISTIC used: real time 0.26 seconds 153 data; set; 154 oy=by; 155 156 *****; %RSQUARE; NOTE: There were 31 observations read from the data set WORK.C. NOTE: The data set WORK.DATA1 has 31 observations and 18 variables. NOTE: DATA statement used: real time 0.10 seconds NOTE: There were 31 observations read from the data set WORK.DATA1. NOTE: The data set WORK.DATA2 has 1 observations and 29 variables. NOTE: DATA statement used: real time 0.05 seconds 157 158 TITLE2 ' LOGISTIC REGRESSION MODEL VALIDATION -- A SET TO B SET'; 159 NOTE: There were 1 observations read from the data set WORK.DATA2. NOTE: PROCEDURE PRINT used: real time 0.10 seconds 160 PROC LOGISTIC DESCENDING DATA=SETAB; 161 MODEL BY=NONSMOKE RUNTIME / RL PPROB=.7 CTABLE; 162 OUTPUT OUT=D L=L P=P U=U; 163 TITLE2 ' LOGISTIC REGRESSION WITH TWO VARIABLES -- B SET'; 164 NOTE: PROC LOGISTIC is modeling the probability that BY=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 31 observations read from the data set WORK.SETAB. NOTE: The data set WORK.D has 31 observations and 17 variables. NOTE: PROCEDURE LOGISTIC used: real time 0.39 seconds 165 data; set; 166 oy=ay; 167 *****; %RSQUARE; NOTE: There were 31 observations read from the data set WORK.D. NOTE: The data set WORK.DATA3 has 31 observations and 18 variables. NOTE: DATA statement used: real time 0.15 seconds NOTE: There were 31 observations read from the data set WORK.DATA3. NOTE: The data set WORK.DATA4 has 1 observations and 29 variables. NOTE: DATA statement used: real time 0.00 seconds 168 169 TITLE2 ' LOGISTIC REGRESSION MODEL VALIDATION -- B SET TO A SET'; 170 171 RUN; NOTE: There were 1 observations read from the data set WORK.DATA4. NOTE: PROCEDURE PRINT used: real time 0.11 seconds 172 173 ods printer close; NOTE: ODS PRINTER printed 51 pages to c:\sasjobs\stat210\jl2003\sh_blst.pdf. 174 RUN;