--------------------------------------------------------------------------------------- name: log: C:\MyDocs\MPH\LectureNotes\ClassDoLogData\logistic regression\SUPPORTlogis > ticRCS.log log type: text opened on: 15 Jan 2010, 10:29:43 . * SUPPORTlogisticRC.log . * . * Regress mortal status at discharge against MAP . * in the SUPPORT data set . * . set more on . use 3.25.2.SUPPORT.dta , replace . * . * Calculate the proportion of patients who die in hospital . * stratified by MAP. . * . generate map_gr = round(map,5) . sort map_gr . label variable map_gr "Mean Arterial Pressure (mm Hg)" . by map_gr: egen proportion = mean(fate) . generate rate = 100*proportion . label variable rate "Observed In-Hospital Mortality Rate (%)" . generate deaths = map_gr if fate (747 missing values generated) . * . * Draw an exploratory graph showing the number of patients, . * the number of deaths and the mortality rate for each MAP. . * . twoway histogram map_gr, discrete frequency color(gs13) gap(20) /// > || histogram deaths, discrete frequency color(red) gap(20) /// > || scatter rate map_gr, yaxis(2) symbol(Oh) color(blue) /// > , xlabel(20 (20) 180) ylabel(0(10)100, angle(0)) /// > xmtick(25 (5) 175) ytitle(Number of Patients) /// > ylabel(0 (10) 100, angle(0) labcolor(blue) axis(2)) /// > ytitle(,color(blue) axis(2)) /// > legend(order(1 "Total" 2 "Deaths" 3 "Mortality Rate" ) /// > rows(1)) name(g1) . more . * . * Regress in-hospital mortality against MAP using simple . * logistic regression. . * . logistic fate map Logistic regression Number of obs = 996 LR chi2(1) = 29.66 Prob > chi2 = 0.0000 Log likelihood = -545.25721 Pseudo R2 = 0.0265 ------------------------------------------------------------------------------ fate | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- map | .9845924 .0028997 -5.27 0.000 .9789254 .9902922 ------------------------------------------------------------------------------ . estimates store simple . predict p,p . label variable p "Probabilty of In-Hospital Death" . line p map, ylabel(0(.1)1, angle(0)) xlabel(20(20)180) name(g2) . more . drop p . * . * Repeat the preceding model using restricted cubic splines . * with 5 knots at their default locations. . * . mkspline _Smap = map, cubic displayknots | knot1 knot2 knot3 knot4 knot5 -------------+------------------------------------------------------- map | 47 66 78 106 129 . logistic fate _S* Logistic regression Number of obs = 996 LR chi2(4) = 122.86 Prob > chi2 = 0.0000 Log likelihood = -498.65571 Pseudo R2 = 0.1097 ------------------------------------------------------------------------------ fate | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Smap1 | .8998261 .0182859 -5.19 0.000 .8646907 .9363892 _Smap2 | 1.17328 .2013998 0.93 0.352 .838086 1.642537 _Smap3 | 1.0781 .7263371 0.11 0.911 .2878645 4.037664 _Smap4 | .6236851 .4083056 -0.72 0.471 .1728672 2.250185 ------------------------------------------------------------------------------ . * . * Test null hypotheses that the logit of the probability of . * in-hospital death is a linear function of MAP. . * . lrtest simple . Likelihood-ratio test LR chi2(3) = 93.20 (Assumption: simple nested in .) Prob > chi2 = 0.0000 . display 2*(545.25721 -498.65571) 93.203 . * . * Plot the estimated probability of death against MAP together . * with the 95% confidence interval for this curve. Overlay . * the MAP-specific observed mortality rates. . * . predict p,p . predict logodds, xb . predict stderr, stdp . generate p2 = exp(logodds)/(1+exp(logodds)) . * . * The values of p and p2 are identical . * . scatter p p2 . generate lodds_lb = logodds - 1.96*stderr . generate lodds_ub = logodds + 1.96*stderr . generate ub_p= exp(lodds_ub)/(1+exp(lodds_ub)) . generate lb_p= exp(lodds_lb)/(1+exp(lodds_lb)) . twoway rarea lb_p ub_p map, color(yellow) /// > || line p map, lwidth(medthick) color(red) /// > || scatter proportion map_gr, symbol(Oh) color(blue) /// > , ylabel(0(.1)1, angle(0)) xlabel(20 (20) 180) /// > xmtick(25(5)175) ytitle(Probabilty of In-Hospital Death) /// > legend(order(3 "Observed" "Mortality" 2 "Expected" "Mortality" /// > 1 "95% Confidence" "Interval") rows(1)) name(g3) . more . * . * Determine the spline covariates at MAP = 90 . * . list _S* if map == 90 +-----------------------------------------+ | _Smap1 _Smap2 _Smap3 _Smap4 | |-----------------------------------------| 575. | 90 11.82436 2.055919 .2569899 | 576. | 90 11.82436 2.055919 .2569899 | 577. | 90 11.82436 2.055919 .2569899 | 578. | 90 11.82436 2.055919 .2569899 | 579. | 90 11.82436 2.055919 .2569899 | |-----------------------------------------| 580. | 90 11.82436 2.055919 .2569899 | 581. | 90 11.82436 2.055919 .2569899 | +-----------------------------------------+ . * . * Let or1 = _Smap1 minus the value of _Smap1 at 90. . * Define or2, or3 and or3 in a similar fashion. . * . generate or1 = _Smap1 - 90 . generate or2 = _Smap2 - 11.82436 . generate or3 = _Smap3 - 2.055919 . generate or4 = _Smap4 - .2569899 . * . * Calculate the log odds ratio for in-hospital death . * relative to patients with MAP = 90. . * . predictnl log_or = or1*_b[_Smap1] + or2*_b[_Smap2] /// > + or3*_b[_Smap3] +or4*_b[_Smap4], se(se_or) . generate lb_log_or = log_or - 1.96*se_or . generate ub_log_or = log_or + 1.96*se_or . generate or = exp(log_or) . generate lb_or = exp(lb_log_or) . generate ub_or = exp(ub_log_or) . . twoway rarea lb_or ub_or map, color(yellow) /// > || line or map, lwidth(medthick) color(red) /// > , ylabel(1 (3) 10 40(30)100 400(300)1000, angle(0)) /// > ymtick(2(1)10 20(10)100 200(100)900) yscale(log) /// > xlabel(20 (20) 180) xmtick(25 (5) 175) /// > ytitle(In-Hospital Mortal Odds Ratio) /// > legend(ring(0) position(2) order(2 "Odds Ratio" /// > 1 "95% Confidence Interval") cols(1)) name(g4) . more . log close name: log: C:\MyDocs\MPH\LectureNotes\ClassDoLogData\logistic regression\SUPPORTlogis > ticRCS.log log type: text closed on: 15 Jan 2010, 10:29:56 ---------------------------------------------------------------------------------------