summary(full.mod)
## 
## Call:
## lm(formula = Bodyfat ~ ., data = subset(bodyfat, select = -Id))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3767 -2.5514 -0.1723  2.6391  9.1393 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -52.553646  40.062856  -1.312   0.1922    
## Age           0.009288   0.043470   0.214   0.8312    
## Weight       -0.271016   0.243569  -1.113   0.2682    
## Height        0.258388   0.320810   0.805   0.4223    
## Neck         -0.592669   0.322125  -1.840   0.0684 .  
## Chest         0.090883   0.164738   0.552   0.5822    
## Abdo          0.995184   0.123072   8.086 7.29e-13 ***
## Hip          -0.141981   0.204533  -0.694   0.4890    
## Thigh         0.101272   0.200714   0.505   0.6148    
## Knee         -0.096682   0.325889  -0.297   0.7673    
## Ankle        -0.048017   0.507695  -0.095   0.9248    
## Bic           0.075332   0.244105   0.309   0.7582    
## Fore          0.412107   0.272144   1.514   0.1327    
## Wrist        -0.263067   0.745145  -0.353   0.7247    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.081 on 114 degrees of freedom
## Multiple R-squared:  0.7519, Adjusted R-squared:  0.7236 
## F-statistic: 26.57 on 13 and 114 DF,  p-value: < 2.2e-16
cor(bodyfat)
##                  Id    Bodyfat         Age     Weight     Height       Neck
## Id       1.00000000 0.03939478  0.31247917 0.02991081  0.1005728 0.01905489
## Bodyfat  0.03939478 1.00000000  0.25437478 0.66152537  0.1513761 0.46478119
## Age      0.31247917 0.25437478  1.00000000 0.03625955 -0.1456736 0.16143675
## Weight   0.02991081 0.66152537  0.03625955 1.00000000  0.5566971 0.77653328
## Height   0.10057276 0.15137609 -0.14567365 0.55669710  1.0000000 0.32875108
## Neck     0.01905489 0.46478119  0.16143675 0.77653328  0.3287511 1.00000000
## Chest    0.08919333 0.73793844  0.21663744 0.89169209  0.2738272 0.72333247
## Abdo     0.05306424 0.83825415  0.24349337 0.88518199  0.2855097 0.69104708
## Hip     -0.05670558 0.62734000 -0.03808131 0.93299025  0.4593269 0.67828816
## Thigh   -0.11581914 0.52256353 -0.20937442 0.83565003  0.3633394 0.63693632
## Knee     0.08259872 0.48760762  0.09193971 0.82244800  0.5652882 0.61183461
## Ankle   -0.05909733 0.35953002 -0.06344775 0.73209696  0.4387430 0.54684519
## Bic     -0.07388071 0.49151203 -0.07291758 0.78242651  0.2999832 0.68510986
## Fore    -0.01516617 0.34038274 -0.05128106 0.61700438  0.2959517 0.62291587
## Wrist    0.07399466 0.42009072  0.30484297 0.70467729  0.2724456 0.75856061
##              Chest       Abdo         Hip      Thigh       Knee       Ankle
## Id      0.08919333 0.05306424 -0.05670558 -0.1158191 0.08259872 -0.05909733
## Bodyfat 0.73793844 0.83825415  0.62734000  0.5225635 0.48760762  0.35953002
## Age     0.21663744 0.24349337 -0.03808131 -0.2093744 0.09193971 -0.06344775
## Weight  0.89169209 0.88518199  0.93299025  0.8356500 0.82244800  0.73209696
## Height  0.27382720 0.28550967  0.45932694  0.3633394 0.56528815  0.43874296
## Neck    0.72333247 0.69104708  0.67828816  0.6369363 0.61183461  0.54684519
## Chest   1.00000000 0.90988148  0.80172538  0.6793998 0.65754967  0.55066510
## Abdo    0.90988148 1.00000000  0.84601360  0.7159499 0.68721784  0.55320958
## Hip     0.80172538 0.84601360  1.00000000  0.8717518 0.77475311  0.69969995
## Thigh   0.67939979 0.71594992  0.87175176  1.0000000 0.74233690  0.68393641
## Knee    0.65754967 0.68721784  0.77475311  0.7423369 1.00000000  0.73889645
## Ankle   0.55066510 0.55320958  0.69969995  0.6839364 0.73889645  1.00000000
## Bic     0.69793237 0.66113863  0.75209342  0.7880858 0.63122086  0.55134883
## Fore    0.52877383 0.45341062  0.52056277  0.5413877 0.47546587  0.51538622
## Wrist   0.64290732 0.62450167  0.64123969  0.5427466 0.61037364  0.63668233
##                 Bic        Fore      Wrist
## Id      -0.07388071 -0.01516617 0.07399466
## Bodyfat  0.49151203  0.34038274 0.42009072
## Age     -0.07291758 -0.05128106 0.30484297
## Weight   0.78242651  0.61700438 0.70467729
## Height   0.29998318  0.29595168 0.27244564
## Neck     0.68510986  0.62291587 0.75856061
## Chest    0.69793237  0.52877383 0.64290732
## Abdo     0.66113863  0.45341062 0.62450167
## Hip      0.75209342  0.52056277 0.64123969
## Thigh    0.78808577  0.54138768 0.54274663
## Knee     0.63122086  0.47546587 0.61037364
## Ankle    0.55134883  0.51538622 0.63668233
## Bic      1.00000000  0.67831620 0.58626764
## Fore     0.67831620  1.00000000 0.52990372
## Wrist    0.58626764  0.52990372 1.00000000
corrplot(cor(bodyfat), method = "number", type = "upper", diag =FALSE)

##I assumed that variables are “highly correlated” if correlation is >0.6.

##Therefore, Weight is higly correlated with: Chest, Abdo, Hip, Thigh, Knee, Ankle, Bic, Fore, Wrist, Neck.

##Thus, I remove them from model and create the new one with only Weight, Height, Age.

ggplot(bodyfat, aes(Bodyfat, Weight+Age+Height)) +
   geom_point(na.rm = TRUE) +
  geom_smooth(method = "lm", na.rm = TRUE)
## `geom_smooth()` using formula 'y ~ x'

full_mod<-lm(Bodyfat~Weight+Age+Height, data=bodyfat)

par(mfrow=c(2,2))
with(bodyfat, plot(Age,resid(full_mod),
     xlab="Age",
     ylab="Residual"))
abline(h=0, lwd=2, lty=2, col="blue")

with(bodyfat, plot(Height,resid(full_mod),
                   xlab="Height",
                   ylab="Residual"))
abline(h=0, lwd=2, lty=2, col="blue")

with(bodyfat, plot(Weight,resid(full_mod),
                   xlab="Weight",
                   ylab="Residual"))
abline(h=0, lwd=2, lty=2, col="blue")

##Explanatory variables are linearly related to percent body fat

qqnorm(resid(full_mod))
qqline(resid(full_mod))

##Residuals are normally distributed

summary(full_mod)
## 
## Call:
## lm(formula = Bodyfat ~ Weight + Age + Height, data = bodyfat)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.2015  -3.8572   0.3377   3.6076  11.5864 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 34.11780   15.95284   2.139  0.03442 *  
## Weight       0.52509    0.04838  10.853  < 2e-16 ***
## Age          0.11531    0.03863   2.985  0.00341 ** 
## Height      -0.89161    0.24774  -3.599  0.00046 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.334 on 124 degrees of freedom
## Multiple R-squared:  0.5389, Adjusted R-squared:  0.5278 
## F-statistic: 48.31 on 3 and 124 DF,  p-value: < 2.2e-16

##Equation:

Body fat = 34.11780 ± 15.95284 + (0.52509 ± 0.04838) * Weight + (0.11531 ± 0.03863) * Age + (-0.89161 ± 0.24774) * Height ± 5.334

##Body fat changes approx.:

increases 0.52509 ± 0.04838 every additional Weight unit

increases 0.11531 ± 0.03863 every additional Age unit

decreases 0.89161 ± 0.24774 every additional Height unit

predict.lm(full_mod, newdata=data.frame(Weight=90, Age=30, Height=74),
           interval="prediction", level=0.95)
##        fit      lwr      upr
## 1 18.85597 8.119608 29.59234