Ejercicios 14-2

Bases de datos

bodyfat <- read.csv("C:/Users/David/Downloads/bodyfat.txt", sep="")
attach(bodyfat)
library(MASS)
data(birthwt)
library(psych)
Warning: package 'psych' was built under R version 4.2.3
library (corrr)
Warning: package 'corrr' was built under R version 4.2.3
library(ggstatsplot)
Warning: package 'ggstatsplot' was built under R version 4.2.3
You can cite this package as:
     Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
     Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library("RColorBrewer")
library(correlation)
Warning: package 'correlation' was built under R version 4.2.3
library(see)
Warning: package 'see' was built under R version 4.2.3

Resolución de ejercicio 14.5

ggscatterstats(data=bodyfat, x="Height", y="Weight")
Registered S3 method overwritten by 'ggside':
  method from   
  +.gg   ggplot2
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

mod4 <-lm(bodyfat$Height~bodyfat$Weight)
summary(mod4)

Call:
lm(formula = bodyfat$Height ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-41.651  -1.453   0.025   1.826   6.997 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    63.274240   1.359585  46.539  < 2e-16 ***
bodyfat$Weight  0.038422   0.007499   5.124 5.99e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.491 on 250 degrees of freedom
Multiple R-squared:  0.09504,   Adjusted R-squared:  0.09142 
F-statistic: 26.25 on 1 and 250 DF,  p-value: 5.99e-07
plot(mod4)

Ejercicio 14.6

mod5 <-lm(bodyfat$Density~bodyfat$Weight)
mod6 <-lm(bodyfat$Fat~bodyfat$Weight)
mod7 <-lm(bodyfat$Age~bodyfat$Weight)
mod8 <-lm(bodyfat$Height~bodyfat$Weight)
mod9 <-lm(bodyfat$Neck~bodyfat$Weight)
mod10 <-lm(bodyfat$Chest~bodyfat$Weight)
mod11 <-lm(bodyfat$Abdomen~bodyfat$Weight)
mod12 <-lm(bodyfat$Hip~bodyfat$Weight)
mod13 <-lm(bodyfat$Thigh~bodyfat$Weight)
mod14 <-lm(bodyfat$Knee~bodyfat$Weight)
mod15 <-lm(bodyfat$Ankle~bodyfat$Weight)
mod16 <-lm(bodyfat$Biceps~bodyfat$Weight)
mod17 <-lm(bodyfat$Forearm~bodyfat$Weight)
mod18 <-lm(bodyfat$Wrist~bodyfat$Weight)
summary(mod5)

Call:
lm(formula = bodyfat$Density ~ bodyfat$Weight)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.045157 -0.011341 -0.000571  0.010031  0.061059 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
(Intercept)     1.124e+00  5.973e-03  188.23   <2e-16 ***
bodyfat$Weight -3.847e-04  3.295e-05  -11.68   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.01534 on 250 degrees of freedom
Multiple R-squared:  0.3529,    Adjusted R-squared:  0.3503 
F-statistic: 136.3 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod6)

Call:
lm(formula = bodyfat$Fat ~ bodyfat$Weight)

Residuals:
     Min       1Q   Median       3Q      Max 
-17.8164  -4.7430   0.0746   4.9283  21.3605 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -12.05158    2.58139  -4.669 4.95e-06 ***
bodyfat$Weight   0.17439    0.01424  12.249  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 6.629 on 250 degrees of freedom
Multiple R-squared:  0.3751,    Adjusted R-squared:  0.3726 
F-statistic:   150 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod7)

Call:
lm(formula = bodyfat$Age ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-23.021  -9.078  -1.768   8.977  36.018 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    45.862834   4.916729   9.328   <2e-16 ***
bodyfat$Weight -0.005466   0.027117  -0.202     0.84    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 12.63 on 250 degrees of freedom
Multiple R-squared:  0.0001625, Adjusted R-squared:  -0.003837 
F-statistic: 0.04062 on 1 and 250 DF,  p-value: 0.8404
summary(mod8)

Call:
lm(formula = bodyfat$Height ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-41.651  -1.453   0.025   1.826   6.997 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    63.274240   1.359585  46.539  < 2e-16 ***
bodyfat$Weight  0.038422   0.007499   5.124 5.99e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.491 on 250 degrees of freedom
Multiple R-squared:  0.09504,   Adjusted R-squared:  0.09142 
F-statistic: 26.25 on 1 and 250 DF,  p-value: 5.99e-07
summary(mod9)

Call:
lm(formula = bodyfat$Neck ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-5.9696 -0.8677 -0.0810  0.9176  3.8629 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    25.697742   0.528030   48.67   <2e-16 ***
bodyfat$Weight  0.068712   0.002912   23.59   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.356 on 250 degrees of freedom
Multiple R-squared:  0.6901,    Adjusted R-squared:  0.6888 
F-statistic: 556.7 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod10)

Call:
lm(formula = bodyfat$Chest ~ bodyfat$Weight)

Residuals:
     Min       1Q   Median       3Q      Max 
-11.8789  -2.4541  -0.1527   2.4007  14.3860 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    54.929294   1.472641   37.30   <2e-16 ***
bodyfat$Weight  0.256504   0.008122   31.58   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.782 on 250 degrees of freedom
Multiple R-squared:  0.7996,    Adjusted R-squared:  0.7988 
F-statistic: 997.4 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod11)

Call:
lm(formula = bodyfat$Abdomen ~ bodyfat$Weight)

Residuals:
     Min       1Q   Median       3Q      Max 
-13.9903  -3.0936   0.2501   3.1306  16.4870 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    34.26038    1.93478   17.71   <2e-16 ***
bodyfat$Weight  0.32581    0.01067   30.53   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.969 on 250 degrees of freedom
Multiple R-squared:  0.7885,    Adjusted R-squared:  0.7877 
F-statistic: 932.2 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod12)

Call:
lm(formula = bodyfat$Hip ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-8.3119 -1.4211  0.0288  1.3472 10.9536 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    58.867571   0.946851   62.17   <2e-16 ***
bodyfat$Weight  0.229355   0.005222   43.92   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.432 on 250 degrees of freedom
Multiple R-squared:  0.8853,    Adjusted R-squared:  0.8848 
F-statistic:  1929 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod13)

Call:
lm(formula = bodyfat$Thigh ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-7.3808 -1.7686 -0.3038  1.5412  8.2245 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    31.640527   1.014701   31.18   <2e-16 ***
bodyfat$Weight  0.155180   0.005596   27.73   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.606 on 250 degrees of freedom
Multiple R-squared:  0.7546,    Adjusted R-squared:  0.7536 
F-statistic: 768.9 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod14)

Call:
lm(formula = bodyfat$Knee ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.8595 -0.8570 -0.0705  0.8252  3.9910 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    26.063139   0.490887   53.09   <2e-16 ***
bodyfat$Weight  0.070015   0.002707   25.86   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.261 on 250 degrees of freedom
Multiple R-squared:  0.7279,    Adjusted R-squared:  0.7268 
F-statistic: 668.8 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod15)

Call:
lm(formula = bodyfat$Ankle ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.8623 -0.6947 -0.1291  0.5549 11.0196 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    16.76995    0.52215   32.12   <2e-16 ***
bodyfat$Weight  0.03539    0.00288   12.29   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.341 on 250 degrees of freedom
Multiple R-squared:  0.3766,    Adjusted R-squared:  0.3741 
F-statistic:   151 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod16)

Call:
lm(formula = bodyfat$Biceps ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.5722 -1.1358 -0.0731  1.1886  8.3803 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    17.550687   0.706659   24.84   <2e-16 ***
bodyfat$Weight  0.082285   0.003897   21.11   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.815 on 250 degrees of freedom
Multiple R-squared:  0.6407,    Adjusted R-squared:  0.6392 
F-statistic: 445.7 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod17)

Call:
lm(formula = bodyfat$Forearm ~ bodyfat$Weight)

Residuals:
    Min      1Q  Median      3Q     Max 
-9.7365 -0.8025  0.0003  0.9324  8.0747 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    20.909802   0.612109   34.16   <2e-16 ***
bodyfat$Weight  0.043337   0.003376   12.84   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.572 on 250 degrees of freedom
Multiple R-squared:  0.3973,    Adjusted R-squared:  0.3949 
F-statistic: 164.8 on 1 and 250 DF,  p-value: < 2.2e-16
summary(mod18)

Call:
lm(formula = bodyfat$Wrist ~ bodyfat$Weight)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.85153 -0.44498 -0.03078  0.45811  2.00779 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    14.081892   0.249047   56.54   <2e-16 ***
bodyfat$Weight  0.023182   0.001374   16.88   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6396 on 250 degrees of freedom
Multiple R-squared:  0.5326,    Adjusted R-squared:  0.5307 
F-statistic: 284.8 on 1 and 250 DF,  p-value: < 2.2e-16
plot(mod5)

plot(mod6)

plot(mod7)

plot(mod8)

plot(mod9)

plot(mod10)

plot(mod11)

plot(mod12)

plot(mod13)

plot(mod14)

plot(mod15)

plot(mod16)

plot(mod17)

plot(mod18)

Ejercicio 14.7