The lab specifications can be found [here]

Exercise 1

Use the table1 package to create a table with appropriate descriptive information about the data set. Use the examples provided in the following vignette to help you build a table.

Non smoker
(N=1564)
Smoker
(N=124)
Birth Weight (g)
Mean (SD) 3250 (601) 3070 (597)
Median [Min, Max] 3290 [369, 5880] 3090 [630, 4220]
Risk Factors Reported
No 1088 (69.6%) 84 (67.7%)
Yes 476 (30.4%) 40 (32.3%)
Mother Age
Mean (SD) 29.0 (5.79) 27.8 (5.79)
Median [Min, Max] 29.0 [15.0, 49.0] 28.0 [17.0, 42.0]
Mother Race/Hispanic Origin
NH White 844 (54.0%) 94 (75.8%)
NH Black 266 (17.0%) 14 (11.3%)
NH Other 125 (8.0%) 10 (8.1%)
Hispanic 329 (21.0%) 6 (4.8%)
Marital Status
Married 1017 (65.0%) 40 (32.3%)
Unmarried 547 (35.0%) 84 (67.7%)
Mother Education
lower 177 (11.3%) 34 (27.4%)
HS 377 (24.1%) 45 (36.3%)
Some college 437 (27.9%) 37 (29.8%)
Uni 573 (36.6%) 8 (6.5%)
PRIORLIVE
0 601 (38.4%) 38 (30.6%)
1 516 (33.0%) 41 (33.1%)
2 265 (16.9%) 17 (13.7%)
3 93 (5.9%) 17 (13.7%)
4+ 89 (5.7%) 11 (8.9%)
PRIORDEAD
0 1551 (99.2%) 123 (99.2%)
1+ 13 (0.8%) 1 (0.8%)
Mother BMI
Mean (SD) 26.9 (6.32) 27.3 (6.42)
Median [Min, Max] 25.6 [15.6, 58.4] 26.3 [16.5, 50.1]

Answer: As we can see from the results in the table, the birth weight of children born from a mother who smokes is lower than that of children born from a non-smoker mother. This is consistent with the available litrature in this issue.

Exercise 2

Use the ggpairs function to explore the association between the different variables. Try to replicate the figure below, or create your own variation.

Answer: The above EDA output displays various associations between the variables. Fo instance we can see from the first graph the relationship between mother’s smoking status and birth weight of children (those born to mothers who smoke have generally lower birth weight). We can also observe correlation between mothers weight and infants birth weight, as well as mother’s BMI and infant birth weight.

Exercise 3

Fit four linear models, each nested within the other: the null model, the unadjusted model, the full model and the optimal model. Use the step function find the optimal model using the stepwise method. Then use anova to compare the four models. What is your conclusion? Now compare your models using modelsummary function. What does the number in the (brackets) mean? How can you identify the optimal model just by looking at the \(R^2\) and the AIC?

## Start:  AIC=21609.55
## DBWT ~ 1
## 
##             Df Sum of Sq       RSS   AIC
## + DMAR       1  28672236 583166851 21530
## + MRACEHISP  3  28557357 583281730 21535
## + PRIORLIVE  4   7485192 604353895 21597
## + MEDUC      3   5189885 606649203 21601
## + CIG_REC    1   3685187 608153901 21601
## + risks      1   3277949 608561138 21602
## + BMI        1   3170730 608668358 21603
## + MAGER      1   2941408 608897679 21603
## + PRIORDEAD  1    849628 610989460 21609
## <none>                   611839087 21610
## 
## Step:  AIC=21530.53
## DBWT ~ DMAR
## 
##             Df Sum of Sq       RSS   AIC
## + MRACEHISP  3  15359037 567807814 21492
## + risks      1   4395289 578771562 21520
## + BMI        1   3607980 579558871 21522
## + PRIORLIVE  4   4500359 578666492 21526
## + CIG_REC    1    978350 582188501 21530
## + PRIORDEAD  1    818812 582348039 21530
## <none>                   583166851 21530
## + MAGER      1     82475 583084376 21532
## + MEDUC      3    313468 582853384 21536
## - DMAR       1  28672236 611839087 21610
## 
## Step:  AIC=21491.48
## DBWT ~ DMAR + MRACEHISP
## 
##             Df Sum of Sq       RSS   AIC
## + BMI        1   4532441 563275373 21480
## + risks      1   3924653 563883161 21482
## + CIG_REC    1   2181695 565626119 21487
## + PRIORLIVE  4   3880005 563927809 21488
## + PRIORDEAD  1    846700 566961114 21491
## <none>                   567807814 21492
## + MAGER      1     52434 567755381 21493
## + MEDUC      3     98014 567709800 21497
## - MRACEHISP  3  15359037 583166851 21530
## - DMAR       1  15473916 583281730 21535
## 
## Step:  AIC=21479.95
## DBWT ~ DMAR + MRACEHISP + BMI
## 
##             Df Sum of Sq       RSS   AIC
## + risks      1   6059709 557215664 21464
## + CIG_REC    1   2362075 560913299 21475
## + PRIORLIVE  4   3457999 559817375 21478
## + PRIORDEAD  1    896345 562379028 21479
## <none>                   563275373 21480
## + MAGER      1    125890 563149483 21482
## + MEDUC      3    115009 563160364 21486
## - BMI        1   4532441 567807814 21492
## - MRACEHISP  3  16283498 579558871 21522
## - DMAR       1  15325756 578601129 21523
## 
## Step:  AIC=21463.69
## DBWT ~ DMAR + MRACEHISP + BMI + risks
## 
##             Df Sum of Sq       RSS   AIC
## + PRIORLIVE  4   5580134 551635530 21455
## + CIG_REC    1   2199370 555016294 21459
## + PRIORDEAD  1   1025923 556189741 21463
## <none>                   557215664 21464
## + MAGER      1     22588 557193076 21466
## + MEDUC      3     69675 557145989 21470
## - risks      1   6059709 563275373 21480
## - BMI        1   6667497 563883161 21482
## - MRACEHISP  3  15921403 573137067 21505
## - DMAR       1  16431163 573646827 21511
## 
## Step:  AIC=21454.7
## DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE
## 
##             Df Sum of Sq       RSS   AIC
## + CIG_REC    1   2707991 548927539 21448
## + PRIORDEAD  1    921529 550714001 21454
## <none>                   551635530 21455
## + MAGER      1    280671 551354859 21456
## + MEDUC      3    173640 551461890 21460
## - PRIORLIVE  4   5580134 557215664 21464
## - BMI        1   6486820 558122350 21472
## - risks      1   8181845 559817375 21478
## - MRACEHISP  3  15145908 566781438 21494
## - DMAR       1  14456460 566091990 21496
## 
## Step:  AIC=21448.4
## DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE + CIG_REC
## 
##             Df Sum of Sq       RSS   AIC
## + PRIORDEAD  1    922493 548005046 21448
## <none>                   548927539 21448
## + MAGER      1    337056 548590483 21449
## + MEDUC      3     75431 548852108 21454
## - CIG_REC    1   2707991 551635530 21455
## - PRIORLIVE  4   6088755 555016294 21459
## - BMI        1   6662694 555590232 21467
## - risks      1   8131760 557059299 21471
## - DMAR       1  10955889 559883427 21480
## - MRACEHISP  3  16576572 565504111 21493
## 
## Step:  AIC=21447.56
## DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE + CIG_REC + 
##     PRIORDEAD
## 
##             Df Sum of Sq       RSS   AIC
## <none>                   548005046 21448
## - PRIORDEAD  1    922493 548927539 21448
## + MAGER      1    361028 547644018 21448
## + MEDUC      3     82260 547922786 21453
## - CIG_REC    1   2708955 550714001 21454
## - PRIORLIVE  4   5984714 553989760 21458
## - BMI        1   6749558 554754604 21466
## - risks      1   8234365 556239411 21471
## - DMAR       1  10970232 558975278 21479
## - MRACEHISP  3  16594210 564599256 21492
## Analysis of Variance Table
## 
## Model 1: DBWT ~ 1
## Model 2: DBWT ~ CIG_REC
## Model 3: DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE + CIG_REC + 
##     PRIORDEAD
## Model 4: DBWT ~ CIG_REC + risks + MAGER + MRACEHISP + DMAR + MEDUC + PRIORLIVE + 
##     PRIORDEAD + BMI
##   Res.Df       RSS Df Sum of Sq       F    Pr(>F)    
## 1   1687 611839087                                   
## 2   1686 608153901  1   3685187 11.2491 0.0008144 ***
## 3   1675 548005046 11  60148855 16.6914 < 2.2e-16 ***
## 4   1671 547416336  4    588710  0.4493 0.7730024    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Analysis of Variance Table
## 
## Model 1: DBWT ~ 1
## Model 2: DBWT ~ CIG_REC
## Model 3: DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE + CIG_REC + 
##     PRIORDEAD
## Model 4: DBWT ~ CIG_REC + risks + MAGER + MRACEHISP + DMAR + MEDUC + PRIORLIVE + 
##     PRIORDEAD + BMI
##   Res.Df       RSS Df Sum of Sq       F    Pr(>F)    
## 1   1687 611839087                                   
## 2   1686 608153901  1   3685187 11.2491 0.0008144 ***
## 3   1675 548005046 11  60148855 16.6914 < 2.2e-16 ***
## 4   1671 547416336  4    588710  0.4493 0.7730024    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
null unadjasted optimal full
(Intercept) 3234.746*** 3247.903*** 3080.559*** 3162.373***
(14.658) (15.187) (64.625) (107.021)
CIG_RECSmoker −179.096** −160.083** −156.593**
(56.032) (55.632) (56.325)
DMARUnmarried −184.275*** −189.782***
(31.823) (35.084)
MRACEHISPNH Black −292.140*** −290.175***
(41.690) (41.829)
MRACEHISPNH Other −121.695* −120.774*
(52.796) (52.960)
MRACEHISPHispanic −74.492+ −72.464+
(38.075) (39.120)
BMI 10.261*** 10.493***
(2.259) (2.277)
risksYes −158.808*** −152.902***
(31.655) (32.055)
PRIORLIVE1 130.686*** 140.483***
(33.814) (34.725)
PRIORLIVE2 107.170* 123.385**
(41.746) (43.880)
PRIORLIVE3 138.776* 161.298*
(59.972) (63.149)
PRIORLIVE4+ 131.949* 162.508*
(62.333) (67.562)
PRIORDEAD1+ 258.434+ 265.467+
(153.905) (154.184)
MAGER −3.836
(3.085)
MEDUCHS 8.448
(49.909)
MEDUCSome college −0.240
(50.838)
MEDUCUni 31.610
(56.902)
Num.Obs. 1688 1688 1688 1688
R2 0.000 0.006 0.104 0.105
R2 Adj. 0.000 0.005 0.098 0.097
AIC 26401.9 26393.7 26239.9 26246.1
BIC 26412.7 26410.0 26315.9 26343.8
Log.Lik. −13198.942 −13193.843 −13105.946 −13105.039
F 10.217 16.259 12.291
RMSE 602.05 600.23 569.78 569.47
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

Answer: We can compare (identify) the optimal model by looking at the AIC (the smaller the AIC value, the better fit). As such, we can see that the optimal model inded has the lowest AIC and is the best fitting of all while the null model is the worst. R-squared measures the proportion of variability in the dependent variable that is explained by the model. A higher R-squared generally indicates a better fit. ***Now if we look at our output, according to the F-statistic for each model, we can see that model 3 the best fitting model.

Exercise 4

Center and scale all the continuous variables, and create a forest plot for the optimal model.

Answer: This plot tells us that mother’s BMI, prior births now living, smoking and prior births now dead are statistically significant. Moreover, we can also see that BMI is the most precise estimator and prior births now dead the most uncertain (less precise) as seen by the width of the lines that represent the confidence interval.

Exercise 5

How do the effect estimate of smoking, the standard error of its estimate, its 95% confidence interval, and its statistical significance change between the un-adjusted, optimal and full models? Please use the centered and scaled models to answer this question.

## # A tibble: 17 × 7
##    term              estimate std.error statistic   p.value conf.low conf.high
##    <chr>                <dbl>     <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
##  1 (Intercept)       3162.       107.    29.5     9.73e-155  2952.     3372.  
##  2 CIG_RECSmoker     -157.        56.3   -2.78    5.49e-  3  -267.      -46.1 
##  3 risksYes          -153.        32.1   -4.77    2.00e-  6  -216.      -90.0 
##  4 MAGER               -3.84       3.09  -1.24    2.14e-  1    -9.89      2.22
##  5 MRACEHISPNH Black -290.        41.8   -6.94    5.70e- 12  -372.     -208.  
##  6 MRACEHISPNH Other -121.        53.0   -2.28    2.27e-  2  -225.      -16.9 
##  7 MRACEHISPHispanic  -72.5       39.1   -1.85    6.41e-  2  -149.        4.26
##  8 DMARUnmarried     -190.        35.1   -5.41    7.24e-  8  -259.     -121.  
##  9 MEDUCHS              8.45      49.9    0.169   8.66e-  1   -89.4     106.  
## 10 MEDUCSome college   -0.240     50.8   -0.00472 9.96e-  1  -100.       99.5 
## 11 MEDUCUni            31.6       56.9    0.556   5.79e-  1   -80.0     143.  
## 12 PRIORLIVE1         140.        34.7    4.05    5.46e-  5    72.4     209.  
## 13 PRIORLIVE2         123.        43.9    2.81    4.98e-  3    37.3     209.  
## 14 PRIORLIVE3         161.        63.1    2.55    1.07e-  2    37.4     285.  
## 15 PRIORLIVE4+        163.        67.6    2.41    1.63e-  2    30.0     295.  
## 16 PRIORDEAD1+        265.       154.     1.72    8.53e-  2   -36.9     568.  
## 17 BMI                 10.5        2.28   4.61    4.36e-  6     6.03     15.0

Answer:

The effect estimate of smoking (CIG_RECYes) becomes more negative as we move from the unadjusted model to the optimal and full models. This means by accounting for additional variables in the models it strengthens the association between smoking and the outcome variable (DBWT).

The standard error of the estimate decreases from the unadjusted to the optimal model, indicating increased precision. However, there is a slight increase in standard error in the full model compared to the optimal model.

The confidence intervals become narrower as we move from the unadjusted to the optimal and full models. This reflects increased confidence in the estimated effect of smoking as more variables are considered.

The p-values remain significant in all models. This suggests that the association between smoking and the outcome is statistically significant even after adjusting for additional variables.

***All in all, the optimal and full models improve the estimation of the effect of smoking by accounting for additional variables. Regardless of that though the significance (p-value) remains robust across all models.

Exercise 6

Does the association between cigarette smoking during pregnancy and birth weight depend on mother’s education? Modify the FULL model appropriately to be able to answer this question. Use anova to test whether the model with the interaction is significantly better than the one without it. Regardless of statistical significance, create a dumbell plot illustrating the smoking effect at each level of mother’s education and estimate the cigarette smoking effect at each level of mother’s education. Hint: When creating the dataset for plotting, include the value zero for each predictor not included in the interaction (the reference level for all categorical variables). Picking the value zero in a centered predictor is like choosing the mean of that variable, which is a reasonable choice.

##            DBWT MRACEHISP    CIG_REC        MEDUC
## 1   0.062274688  NH White Non smoker        lower
## 2   0.044478085  NH White     Smoker        lower
## 3   0.088547793  NH White Non smoker           HS
## 4  -0.050146730  NH White     Smoker           HS
## 5   0.087773609  NH White Non smoker Some college
## 6  -0.132368083  NH White     Smoker Some college
## 7   0.106740302  NH White Non smoker          Uni
## 8   0.024046565  NH White     Smoker          Uni
## 9  -0.177128407  NH Black Non smoker        lower
## 10 -0.194925010  NH Black     Smoker        lower
## 11 -0.150855303  NH Black Non smoker           HS
## 12 -0.289549825  NH Black     Smoker           HS
## 13 -0.151629486  NH Black Non smoker Some college
## 14 -0.371771178  NH Black     Smoker Some college
## 15 -0.132662793  NH Black Non smoker          Uni
## 16 -0.215356530  NH Black     Smoker          Uni
## 17 -0.039972642  NH Other Non smoker        lower
## 18 -0.057769244  NH Other     Smoker        lower
## 19 -0.013699537  NH Other Non smoker           HS
## 20 -0.152394060  NH Other     Smoker           HS
## 21 -0.014473721  NH Other Non smoker Some college
## 22 -0.234615412  NH Other     Smoker Some college
## 23  0.004492972  NH Other Non smoker          Uni
## 24 -0.078200765  NH Other     Smoker          Uni
## 25  0.006155744  Hispanic Non smoker        lower
## 26 -0.011640859  Hispanic     Smoker        lower
## 27  0.032428848  Hispanic Non smoker           HS
## 28 -0.106265674  Hispanic     Smoker           HS
## 29  0.031654665  Hispanic Non smoker Some college
## 30 -0.188487027  Hispanic     Smoker Some college
## 31  0.050621358  Hispanic Non smoker          Uni
## 32 -0.032072379  Hispanic     Smoker          Uni

Answer: The graph shows that there is an interaction between smoking and level of education.

Exercise 7

Does the association between mother’s BMI and birth-weight differ between mothers of different race/ethnicity? Modify the OPTIMAL model appropriately to be able to answer this question, using the dataset with the centered variables. Use anova to test whether the model with the interaction is significantly better than the one without it. Regardless of statistical significance, estimate the BMI effect at each level of mother’s race/ethnicity and plot the BMI effect at each level of mother’s race/ethnicity using a dumbell plot.

## 
## Call:
## lm(formula = DBWT ~ DMAR + MRACEHISP + BMI + risks + PRIORLIVE + 
##     CIG_REC + PRIORDEAD + BMI:MRACEHISP, data = natality.ctr)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2545 -0.2491  0.0248  0.3009  1.9732 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             0.1028     0.0239    4.31  1.8e-05 ***
## DMARUnmarried          -0.1546     0.0265   -5.85  6.1e-09 ***
## MRACEHISPNH Black      -0.2395     0.0348   -6.89  8.0e-12 ***
## MRACEHISPNH Other      -0.0921     0.0443   -2.08  0.03788 *  
## MRACEHISPHispanic      -0.0607     0.0316   -1.92  0.05535 .  
## BMI                     0.1200     0.0323    3.71  0.00021 ***
## risksYes               -0.1323     0.0263   -5.03  5.4e-07 ***
## PRIORLIVE1              0.1077     0.0281    3.84  0.00013 ***
## PRIORLIVE2              0.0895     0.0347    2.58  0.00989 ** 
## PRIORLIVE3              0.1152     0.0498    2.31  0.02094 *  
## PRIORLIVE4+             0.1085     0.0518    2.09  0.03641 *  
## CIG_RECSmoker          -0.1355     0.0462   -2.93  0.00341 ** 
## PRIORDEAD1+             0.2070     0.1279    1.62  0.10575    
## MRACEHISPNH Black:BMI  -0.0503     0.0588   -0.86  0.39256    
## MRACEHISPNH Other:BMI   0.1204     0.0982    1.23  0.22071    
## MRACEHISPHispanic:BMI  -0.0457     0.0629   -0.73  0.46727    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.47 on 1672 degrees of freedom
## Multiple R-squared:  0.106,  Adjusted R-squared:  0.098 
## F-statistic: 13.2 on 15 and 1672 DF,  p-value: <2e-16
## # A tibble: 2 × 7
##   term                          df.residual   rss    df  sumsq statistic p.value
##   <chr>                               <dbl> <dbl> <dbl>  <dbl>     <dbl>   <dbl>
## 1 DBWT ~ DMAR + MRACEHISP + BM…        1675  378.    NA NA         NA     NA    
## 2 DBWT ~ DMAR + MRACEHISP + BM…        1672  377.     3  0.712      1.05   0.369

Answer: As we can see from the ANOVA there is no significant difference between the optimal model and a model containing the interaction. However, there is an interaction between BMI and ethnicity.

Exercise 8

Does the association between mother’s BMI and birth-weight depend on mother’s age? Modify the FULL model appropriately to be able to answer this question, using the dataset with the centered variables. Use anova to test whether the model with the interaction is significantly better than the one without it. Regardless of statistical significance, estimate the BMI effect for mothers age 20, 30, and 40 years and make a plot illustrating the BMI effect at each of these ages.

## # A tibble: 18 × 5
##    term               estimate std.error statistic  p.value
##    <chr>                 <dbl>     <dbl>     <dbl>    <dbl>
##  1 (Intercept)        0.0831      0.0483    1.72   8.55e- 2
##  2 CIG_RECSmoker     -0.131       0.0468   -2.79   5.25e- 3
##  3 risksYes          -0.127       0.0266   -4.76   2.13e- 6
##  4 MAGER             -0.0370      0.0297   -1.25   2.13e- 1
##  5 MRACEHISPNH Black -0.240       0.0348   -6.89   7.93e-12
##  6 MRACEHISPNH Other -0.101       0.0440   -2.29   2.21e- 2
##  7 MRACEHISPHispanic -0.0593      0.0325   -1.82   6.83e- 2
##  8 DMARUnmarried     -0.158       0.0291   -5.42   7.01e- 8
##  9 MEDUCHS            0.00679     0.0414    0.164  8.70e- 1
## 10 MEDUCSome college -0.000422    0.0422   -0.0100 9.92e- 1
## 11 MEDUCUni           0.0251      0.0473    0.531  5.96e- 1
## 12 PRIORLIVE1         0.116       0.0288    4.03   5.82e- 5
## 13 PRIORLIVE2         0.102       0.0365    2.79   5.37e- 3
## 14 PRIORLIVE3         0.134       0.0524    2.55   1.08e- 2
## 15 PRIORLIVE4+        0.135       0.0561    2.41   1.60e- 2
## 16 PRIORDEAD1+        0.217       0.128     1.69   9.03e- 2
## 17 BMI                0.110       0.0239    4.60   4.65e- 6
## 18 MAGER:BMI         -0.0242      0.0469   -0.517  6.05e- 1
## # A tibble: 2 × 7
##   term                          df.residual   rss    df  sumsq statistic p.value
##   <chr>                               <dbl> <dbl> <dbl>  <dbl>     <dbl>   <dbl>
## 1 DBWT ~ CIG_REC + risks + MAG…        1668  377.    NA NA         NA     NA    
## 2 DBWT ~ CIG_REC + risks + MAG…        1670  377.    -2 -0.586      1.30   0.274

Answer: With p-value of 0.605,the anova table indicates that there is no significant difference between the optimal model and a model containing an interaction between BMI and age.However, the different slopes for different ages indicates that there is an interaction between age of the mother and BMI in the correlation with birth weight.