--------------------------------------------------------------------------------------------------------------- name: log: C:\Users\dupontwd.VANDERBILT\Documents\MPH\LectureNotes\ClassDoLogData\linearRegression\Birth_Weig > ht.LR.log log type: text opened on: 14 Jan 2013, 10:56:07 . set more on . * Birth_Weight.LR.log . * . * Linear regression of birth weight on estriol . * See Rosner, Table 11.1, p554, and Green & Touchstone 1963 . * . set more on . use rostab11.dta, clear . regress bweight estriol Source | SS df MS Number of obs = 31 -------------+------------------------------ F( 1, 29) = 17.16 Model | 250.574476 1 250.574476 Prob > F = 0.0003 Residual | 423.425524 29 14.6008801 R-squared = 0.3718 -------------+------------------------------ Adj R-squared = 0.3501 Total | 674 30 22.4666667 Root MSE = 3.8211 ------------------------------------------------------------------------------ bweight | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- estriol | .6081905 .1468117 4.14 0.000 .3079268 .9084542 _cons | 21.52343 2.620417 8.21 0.000 16.16407 26.88278 ------------------------------------------------------------------------------ . predict y_hat, xb . twoway scatter bweight estriol /// > || line y_hat estriol /// > , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") . more . predict std_p, stdp . generate ci_u = y_hat + invttail(_N-2,0.025)*std_p . generate ci_l = y_hat - invttail(_N-2,0.025)*std_p . twoway rarea ci_u ci_l estriol, color(gs14) /// > || scatter bweight estriol /// > || line y_hat estriol /// > , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") . . more . * . * Calculating values of expected birth weight with confidence intervals . * associated with specific estriol levels that are in the dataset . * . list y_hat ci_u ci_l if estriol == 20 +--------------------------------+ | y_hat ci_u ci_l | |--------------------------------| 24. | 33.68724 35.31942 32.05505 | +--------------------------------+ . * . * If the desired estriol level is not in the data set we procede as follows . * . set obs 32 obs was 31, now 32 . replace estriol = 23 in 32 (1 real change made) . drop y_hat std_p ci_u ci_l . predict y_hat, xb . predict std_p, stdp . generate ci_u = y_hat + invttail(_N-2,0.025)*std_p . generate ci_l = y_hat - invttail(_N-2,0.025)*std_p . list y_hat ci_u ci_l if estriol == 23 +--------------------------------+ | y_hat ci_u ci_l | |--------------------------------| 32. | 35.51181 37.73932 33.28431 | +--------------------------------+ . . * The preceding graph could also have been generated without explicitly . * calculationg yhat, ci_u or ci_l as follows . * . twoway lfitci bweight estriol /// > || scatter bweight estriol /// > , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") . more . predict std_f, stdf . generate ci_uf = y_hat + invttail(_N-2,0.025)*std_f . generate ci_lf = y_hat - invttail(_N-2,0.025)*std_f . twoway lfitci bweight estriol /// > || scatter bweight estriol /// > || rline ci_uf ci_lf estriol, color(red) /// > , xlabel(10 (5) 25) xmtick(7 (1) 27) /// > ylabel(20 (5) 45) ytitle("Birth Weight (g/100)") legend(off) . more . twoway scatter bweight estriol /// > || lfit bweight estriol /// > || lowess bweight estriol, bwidth(.8) /// > ||, xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") . more . regress bweight estriol Source | SS df MS Number of obs = 31 -------------+------------------------------ F( 1, 29) = 17.16 Model | 250.574476 1 250.574476 Prob > F = 0.0003 Residual | 423.425524 29 14.6008801 R-squared = 0.3718 -------------+------------------------------ Adj R-squared = 0.3501 Total | 674 30 22.4666667 Root MSE = 3.8211 ------------------------------------------------------------------------------ bweight | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- estriol | .6081905 .1468117 4.14 0.000 .3079268 .9084542 _cons | 21.52343 2.620417 8.21 0.000 16.16407 26.88278 ------------------------------------------------------------------------------ . predict residual, rstudent (1 missing value generated) . twoway scatter residual estriol /// > || lowess residual estriol /// > , ylabel(-2 (1) 2) yline(-2 0 2) xlabel(10 (5) 25) xmtick(7 (1) 27) /// > ytitle(Studentized residual) . . log close name: log: C:\Users\dupontwd.VANDERBILT\Documents\MPH\LectureNotes\ClassDoLogData\linearRegression\Birth_Weig > ht.LR.log log type: text closed on: 14 Jan 2013, 10:56:19 ---------------------------------------------------------------------------------------------------------------