# 8.3 Body weights, Part III. A more realistic approach to modeling infant weights is to consider all possibly related variables at once.
# Other variables of interest include length of pregnancy in days (gestation), mother's age in years (age), mother's height in inches (height),
# and mother's pregnancy weight in pounds (weight). Below are three observations from this data set.
# (a) body_weight = -80.41 + 0.44 * gestation - 3.33 * parity - 0.01 * age + 1.15 * height + 0.05 * weight - 8.40 * smoke
# (b) The slope of gestation predicts a 0.44 ounce increase in the birth weight of the baby for each additional day of pregnancy with all else
# held constant; The slope of age predicts a 0.01 ounce decrease in the birth weight of the baby for each additional year in mother's age
# with all else held constant.
# (c) Because parity might be correlated with one of the other variables in the model, which will complicates model estimation.
# (d) For the observation, the actual body weight is 120.
gestation = 284
parity = 0
age = 27
height = 62
weight = 100
smoke = 0

body_weight = -80.41 + 0.44 * gestation - 3.33 * parity - 0.01 * age + 1.15 * height + 0.05 * weight - 8.40 * smoke

body_weight
## [1] 120.58
# The residual for the first observation in the data set is 120 - 120.58 = - 0.58.
# (e)
VarR = 249.28 # Variability in residuals
VarBR = 332.57 # Variability in the outcome
R2 =  1 - VarR/VarBR
R2
## [1] 0.2504435
# The R2 is 0.2504
n = 1236 # number of cases
k = 7 # number of predictor variables in the model
adjustR2 = 1 - VarR/VarBR * (n-1)/(n-k-1)
adjustR2
## [1] 0.2461708
# The adjusted R2 is 0.2468.