------------------------------------------------------------------------------------------------- log: C:\MyDocs\MPH\Text\SecondEdition\WebDoFiles\3.25.2.SUPPORT.log log type: text opened on: 30 Dec 2007, 15:50:35 . * 3.25.2.SUPPORT.log . * . * Draw scatter plots of length-of-stay (LOS) by mean arterial . * pressure (MAP) and log LOS by MAP for the SUPPORT Study data. . * . use "C:\WDDtext\3.25.2.SUPPORT.dta" , replace . scatter los map, symbol(Oh) xlabel(25 (25) 175) xmtick(20 (5) 180) /// > ylabel(0(25)225, angle(0)) ymtick(5(5)240) . . more . scatter los map, symbol(Oh) xlabel(25 (25) 175) xmtick(20 (5) 180) /// > yscale(log) ylabel(4(2)10 20(20)100 200, angle(0)) /// > ymtick(3(1)9 30(10)90) . more . * . * Regress log LOS against MAP using RCS models with from 3 to . * 7 knots at their default locations. Overlay the expected . * log LOS from these models on a scatter plot of log LOS by MAP. . * . mkspline _Smap = map, cubic displayknots | knot1 knot2 knot3 knot4 knot5 -------------+------------------------------------------------------- map | 47 66 78 106 129 . summarize _Smap1 _Smap2 _Smap3 _Smap4 Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- _Smap1 | 996 85.31727 26.83566 20 180 _Smap2 | 996 20.06288 27.34701 0 185.6341 _Smap3 | 996 7.197497 11.96808 0 89.57169 _Smap4 | 996 3.121013 5.96452 0 48.20881 . generate log_los = log(los) . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 4, 991) = 24.70 Model | 60.9019393 4 15.2254848 Prob > F = 0.0000 Residual | 610.872879 991 .616420665 R-squared = 0.0907 -------------+------------------------------ Adj R-squared = 0.0870 Total | 671.774818 995 .675150571 Root MSE = .78512 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .0296009 .0059566 4.97 0.000 .017912 .0412899 _Smap2 | -.3317922 .0496932 -6.68 0.000 -.4293081 -.2342762 _Smap3 | 1.263893 .1942993 6.50 0.000 .8826076 1.645178 _Smap4 | -1.124065 .1890722 -5.95 0.000 -1.495092 -.7530367 _cons | 1.03603 .3250107 3.19 0.001 .3982422 1.673819 ------------------------------------------------------------------------------ . predict y_hat5, xb . drop _S* . mkspline _Smap = map, nknots(3) cubic . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 2, 993) = 18.24 Model | 23.8065057 2 11.9032528 Prob > F = 0.0000 Residual | 647.968313 993 .652536065 R-squared = 0.0354 -------------+------------------------------ Adj R-squared = 0.0335 Total | 671.774818 995 .675150571 Root MSE = .8078 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | -.0110138 .0027449 -4.01 0.000 -.0164002 -.0056274 _Smap2 | .0226496 .004248 5.33 0.000 .0143135 .0309858 _cons | 3.124095 .1827706 17.09 0.000 2.765435 3.482756 ------------------------------------------------------------------------------ . predict y_hat3, xb . drop _S* . mkspline _Smap = map, nknots(4) cubic . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 3, 992) = 21.40 Model | 40.8276008 3 13.6092003 Prob > F = 0.0000 Residual | 630.947217 992 .636035501 R-squared = 0.0608 -------------+------------------------------ Adj R-squared = 0.0579 Total | 671.774818 995 .675150571 Root MSE = .79752 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .0060744 .004387 1.38 0.166 -.0025343 .0146832 _Smap2 | -.0533119 .0155968 -3.42 0.001 -.0839184 -.0227054 _Smap3 | .1509453 .0342118 4.41 0.000 .0838095 .2180812 _cons | 2.180462 .2600792 8.38 0.000 1.670093 2.69083 ------------------------------------------------------------------------------ . predict y_hat4, xb . drop _S* . mkspline _Smap = map, nknots(6) cubic . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 5, 990) = 20.18 Model | 62.1303583 5 12.4260717 Prob > F = 0.0000 Residual | 609.64446 990 .615802485 R-squared = 0.0925 -------------+------------------------------ Adj R-squared = 0.0879 Total | 671.774818 995 .675150571 Root MSE = .78473 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .03099 .006904 4.49 0.000 .0174418 .0445382 _Smap2 | -.3837563 .0874071 -4.39 0.000 -.5552809 -.2122318 _Smap3 | 1.111961 .3834093 2.90 0.004 .3595729 1.864349 _Smap4 | -.5873248 .4457995 -1.32 0.188 -1.462145 .2874957 _Smap5 | -.4824613 .2991149 -1.61 0.107 -1.069433 .1045108 _cons | .9745223 .3623654 2.69 0.007 .2634297 1.685615 ------------------------------------------------------------------------------ . predict y_hat6, xb . drop _S* . mkspline _Smap = map, nknots(7) cubic displayknots | knot1 knot2 knot3 knot4 knot5 knot6 knot7 -------------+----------------------------------------------------------------------------- map | 41 60 69 78 101.3251 113 138.075 . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 6, 989) = 16.92 Model | 62.5237582 6 10.4206264 Prob > F = 0.0000 Residual | 609.25106 989 .616027361 R-squared = 0.0931 -------------+------------------------------ Adj R-squared = 0.0876 Total | 671.774818 995 .675150571 Root MSE = .78487 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .0389453 .0092924 4.19 0.000 .0207101 .0571804 _Smap2 | -.3778786 .12678 -2.98 0.003 -.6266673 -.12909 _Smap3 | .9316267 .8933099 1.04 0.297 -.8213739 2.684627 _Smap4 | .1269005 1.58931 0.08 0.936 -2.991907 3.245708 _Smap5 | -.7282771 1.034745 -0.70 0.482 -2.758824 1.30227 _Smap6 | -.3479716 .4841835 -0.72 0.473 -1.298117 .6021733 _cons | .6461153 .4496715 1.44 0.151 -.2363046 1.528535 ------------------------------------------------------------------------------ . predict y_hat7, xb . scatter log_los map, color(gray) symbol(Oh) /// > || line y_hat7 y_hat6 y_hat5 y_hat4 y_hat3 map /// > , xlabel(25 (25) 175) xmtick(20 (5) 180) /// > ylabel(1.39 "4" 1.79 "6" 2.08 "8" 2.3 "10" 3 "20" /// > 3.69 "40" 4.09 "60" 4.38 "80" 4.61 "100" 5.3 "200", angle(0)) /// > ymtick(1.1 1.39 1.61 1.79 1.95 2.08 2.2 3.4 3.91 4.25 4.5) /// > ytitle(Length of Stay (days)) /// > legend(ring(1) position(3) cols(1) /// > subtitle("Number" "of Knots") /// > order( 6 "3" 5 "4" 4 "5" 3 "6" 2 "7")) scale(0.9) . more . * . * Plot expected LOS for 7 knot model together with 95% . * confidence bands. Use the default knot locations. . * . predict se, stdp . generate lb = y_hat7 - invttail(_N-7, 0.025)*se . generate ub = y_hat7 + invttail(_N-7, 0.025)*se . twoway rarea lb ub map , color(yellow) /// > || scatter log_los map, color(gray) symbol(Oh) /// > || line y_hat7 map, lpattern(solid) /// > || line lb ub map , lwidth(vvthin vvthin) color(yellow yellow) /// > , xlabel(25 (25) 175) xmtick(20 (5) 180) /// > ylabel(1.39 "4" 1.79 "6" 2.08 "8" 2.3 "10" 3 "20" /// > 3.69 "40" 4.09 "60" 4.38 "80" 4.61 "100" 5.3 "200", angle(0)) /// > ymtick(1.1 1.39 1.61 1.79 1.95 2.08 2.2 3.4 3.91 4.25 4.5) /// > xline(41 60 69 78 101.3 113 138.1) /// > ytitle(Length of Stay (days)) /// > subtitle("Default" "Knot" "Values" /// > , ring(0) position(10)) legend(off) . more . * . * Replot 7 knot model with evenly spaced knots. . * . drop _S* se lb ub . mkspline _Smap = map, knots(39 56 73 90 107 124 141) /// > cubic displayknots | knot1 knot2 knot3 knot4 knot5 knot6 knot7 -------------+----------------------------------------------------------------------------- map | 39 56 73 90 107 124 141 . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 6, 989) = 17.21 Model | 63.4919415 6 10.5819903 Prob > F = 0.0000 Residual | 608.282877 989 .615048409 R-squared = 0.0945 -------------+------------------------------ Adj R-squared = 0.0890 Total | 671.774818 995 .675150571 Root MSE = .78425 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .0433266 .0096585 4.49 0.000 .0243731 .0622801 _Smap2 | -.4291243 .1170325 -3.67 0.000 -.6587848 -.1994638 _Smap3 | .8290495 .3632572 2.28 0.023 .1162061 1.541893 _Smap4 | .0320967 .540272 0.06 0.953 -1.028114 1.092308 _Smap5 | -.8939894 .6093778 -1.47 0.143 -2.089811 .3018326 _Smap6 | .4509367 .562592 0.80 0.423 -.6530744 1.554948 _cons | .4732522 .4628208 1.02 0.307 -.4349714 1.381476 ------------------------------------------------------------------------------ . predict y_hat, xb . predict se, stdp . generate lb = y_hat - invttail(_N-7, 0.025)*se . generate ub = y_hat + invttail(_N-7, 0.025)*se . twoway rarea lb ub map , color(yellow) /// > || scatter log_los map, color(gray) symbol(Oh) /// > || line y_hat map, lpattern(solid) /// > || line lb ub map , lwidth(vvthin vvthin) color(yellow yellow) /// > , xlabel(25 (25) 175) xmtick(20 (5) 180) /// > xline(39(17)141) /// > ylabel(1.39 "4" 1.79 "6" 2.08 "8" 2.3 "10" 3 "20" /// > 3.69 "40" 4.09 "60" 4.38 "80" 4.61 "100" 5.3 "200", angle(0)) /// > ymtick(1.1 1.39 1.61 1.79 1.95 2.08 2.2 3.4 3.91 4.25 4.5) /// > subtitle("Evenly" "Spaced" "Knots", ring(0) position(10)) /// > ytitle(Length of Stay (days)) legend(off) . more . * . * Regenerate seven-knot model with default knot values. . * . drop _S* y_hat se lb ub . mkspline _Smap = map, nknots(7) cubic . regress log_los _S* Source | SS df MS Number of obs = 996 -------------+------------------------------ F( 6, 989) = 16.92 Model | 62.5237582 6 10.4206264 Prob > F = 0.0000 Residual | 609.25106 989 .616027361 R-squared = 0.0931 -------------+------------------------------ Adj R-squared = 0.0876 Total | 671.774818 995 .675150571 Root MSE = .78487 ------------------------------------------------------------------------------ log_los | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .0389453 .0092924 4.19 0.000 .0207101 .0571804 _Smap2 | -.3778786 .12678 -2.98 0.003 -.6266673 -.12909 _Smap3 | .9316267 .8933099 1.04 0.297 -.8213739 2.684627 _Smap4 | .1269005 1.58931 0.08 0.936 -2.991907 3.245708 _Smap5 | -.7282771 1.034745 -0.70 0.482 -2.758824 1.30227 _Smap6 | -.3479716 .4841835 -0.72 0.473 -1.298117 .6021733 _cons | .6461153 .4496715 1.44 0.151 -.2363046 1.528535 ------------------------------------------------------------------------------ . * . * Test for a non-linear association . * . test _Smap2 _Smap3 _Smap4 _Smap5 _Smap6 ( 1) _Smap2 = 0 ( 2) _Smap3 = 0 ( 3) _Smap4 = 0 ( 4) _Smap5 = 0 ( 5) _Smap6 = 0 F( 5, 989) = 18.59 Prob > F = 0.0000 . predict rstudent, rstudent . generate big = abs(rstudent)>2 . tabulate big big | Freq. Percent Cum. ------------+----------------------------------- 0 | 949 95.28 95.28 1 | 47 4.72 100.00 ------------+----------------------------------- Total | 996 100.00 . * . * Draw a scatter plot of the studentized residuals against MAP . * Overlay the associated lowess regression curve on this graph. . * . twoway scatter rstudent map, color(gray) symbol(Oh) /// > || lowess rstudent map, lwidth(thick) /// > , ytitle(Studentized Residual) yline(-2 0 2) legend(off) . more . * . * Plot expected LOS against MAP on a linear scale. . * Truncate LOS > 70. . * . predict y_hat, xb . predict se, stdp . generate lb = y_hat - invttail(_N-7, 0.025)*se . generate ub = y_hat + invttail(_N-7, 0.025)*se . generate e_los = exp(y_hat) . generate lb_los = exp(lb) . generate ub_los = exp(ub) . generate truncated_los = los . replace truncated_los = 80 if los > 70 (29 real changes made) . twoway rarea lb_los ub_los map , color(yellow) /// > || scatter truncated_los map ,color(gray) symbol(Oh) /// > || line e_los map, lpattern(solid) /// > || line lb_los ub_los map , lwidth(vvthin vvthin) /// > color(yellow yellow) /// > , xlabel(25 (25) 175) xmtick(30 (5) 170) /// > ylabel(0 (10) 70, angle(0)) ytitle(Length of Stay) /// > legend(order(3 "Expected MAP" /// > 1 "95% Confidence Interval") rows(1)) scale(.8) . more . log close log: C:\MyDocs\MPH\Text\SecondEdition\WebDoFiles\3.25.2.SUPPORT.log log type: text closed on: 30 Dec 2007, 15:51:33 -----------------------------------------------------------------------------------------------