** Surgery Survival (NKNW Section 8.2); OPTIONS LINESIZE=75 NOCENTER NONUMBER NODATE; * OPTIONS PAGESIZE = 20; /* for sizing output for LaTeX slides */ TITLE 'Missile - Splines'; PROC IMPORT DATAFILE = 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\SAS\missile.txt' DBMS = tab OUT = missile REPLACE; RUN; DATA missile2; SET missile; Time2 = Time * Time; Time3 = Time2 * Time; Time4 = Time3 * Time; FILENAME grafout 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\missile.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 4.5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL COLOR = 'red' VALUE = 'dot'; PROC GPLOT DATA = missile2; PLOT Voltage * Time / HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time'; RUN; FILENAME grafout2 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\cubicresid.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout2 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; SYMBOL COLOR = 'red' VALUE = 'dot'; PROC REG DATA = missile2; MODEL Voltage = Time Time2 Time3; PLOT r. * Time; TITLE 'Residuals from Cubic Model'; OUTPUT OUT = cubic PREDICTED = pred RESIDUAL = resid; RUN; FILENAME grafout5 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\cubicfit.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout5 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL1 COLOR = 'red' VALUE = dot; SYMBOL2 COLOR = 'blue' INTERPOL = line VALUE = none width=2; PROC GPLOT DATA = cubic; PLOT Voltage * Time pred * Time / OVERLAY HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time - Quartic Fit'; RUN; FILENAME grafout3 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\quadresid.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout3 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 4.5IN; SYMBOL COLOR = 'red' VALUE = 'dot'; PROC REG DATA = missile2; MODEL Voltage = Time Time2 Time3 Time4; PLOT r. * Time; TITLE 'Residuals from Quartic Model'; OUTPUT OUT = quartic PREDICTED = pred RESIDUAL = resid; RUN; FILENAME grafout6 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\quadfit.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout6 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL1 COLOR = 'red' VALUE = dot; SYMBOL2 COLOR = 'blue' INTERPOL = line VALUE = none width=2; PROC GPLOT DATA = quartic; PLOT Voltage * Time pred * Time / OVERLAY HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time - Quartic Fit'; RUN; PROC GAM DATA = missile2 ; MODEL Voltage = SPLINE(Time) / METHOD = GCV ; OUTPUT OUT = spline PREDICTED RESIDUAL; RUN; FILENAME grafout4 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\missile_spline.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout4 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL1 COLOR = 'red' VALUE = dot; SYMBOL2 COLOR = 'blue' INTERPOL = line VALUE = none width=2; PROC GPLOT DATA = spline; PLOT Voltage * Time P_Voltage * Time / OVERLAY HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time - Spline fit (lambda = 0.89 - GCV)'; RUN; PROC GAM DATA = missile2 ; MODEL Voltage = SPLINE(Time, DF=30) ; OUTPUT OUT = spline2 PREDICTED RESIDUAL; RUN; FILENAME grafout7 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\missile_spline30.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout7 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL1 COLOR = 'red' VALUE = dot; SYMBOL2 COLOR = 'blue' INTERPOL = line VALUE = none width=2; PROC GPLOT DATA = spline2; PLOT Voltage * Time P_Voltage * Time / OVERLAY HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time - Spline fit (lambda = 0.07 - DF=30)'; RUN; PROC GAM DATA = missile2 ; MODEL Voltage = LOESS(Time) / METHOD = GCV ; OUTPUT OUT = loess PREDICTED RESIDUAL; RUN; FILENAME grafout8 'C:\Documents and Settings\Mark Irwin\My Documents\Harvard\Courses\Stat 135\Autumn 2005\missile_loess.eps'; goptions RESET=ALL device=pslepsfc GSFNAME=grafout8 GSFMODE=REPLACE FTEXT=swissb HSIZE = 7IN VSIZE = 5IN; AXIS1 LABEL = ("Time (seconds)") MAJOR = (NUMBER = 5) MINOR = (NUMBER = 9); AXIS2 LABEL = ("Voltage Drop"); SYMBOL1 COLOR = 'red' VALUE = dot; SYMBOL2 COLOR = 'blue' INTERPOL = line VALUE = none width=2; PROC GPLOT DATA = loess; PLOT Voltage * Time P_Voltage * Time / OVERLAY HAXIS = axis1 VAXIS = axis2; TITLE 'Voltage Drop vs Time - Loess fit (GCV)'; RUN; QUIT;