Regresión lineal Mtcars
Mpg vs Hp
#Regresión lineal
mod1 = lm(mpg ~ hp, data = mtcars )
plot(mtcars$hp, mtcars$mpg,
main = "Relación entre HP y MPG",
xlab = "Caballos de fuerza (HP)",
ylab = "Millas por galón (MPG)",
col = "blue",
pch = 19)
abline(mod1, col = "red", lwd = 2)

#Coeficiente beta estandarizado
beta_estandarizado = lm.beta(mod1)
print(beta_estandarizado)
##
## Call:
## lm(formula = mpg ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.7761684
#CI 95
intervalo_confianza = confint(beta_estandarizado, level = 0.95)
print(intervalo_confianza)
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.7968347 -0.755502
resumen_modelo = summary(mod1)
p_values = resumen_modelo$coefficients[,4]
cat("Los valores p de la regresión son:", p_values, "\n")
## Los valores p de la regresión son: 6.642736e-18 1.787835e-07
## (Intercept) hp
## 6.642736e-18 1.787835e-07
Cyl vs Hp

##
## Call:
## lm(formula = cyl ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA 0.8324475
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp 0.8270658 0.8378291
## Los valores p de la regresión son: 7.405351e-08 3.477861e-09
## (Intercept) hp
## 7.405351e-08 3.477861e-09
Disp vs Hp

##
## Call:
## lm(formula = disp ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA 0.7909486
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp 0.3785292 1.203368
## Los valores p de la regresión son: 0.5245902 7.142679e-08
## (Intercept) hp
## 5.245902e-01 7.142679e-08
Drat vs Hp

##
## Call:
## lm(formula = drat ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.4487591
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.4513576 -0.4461606
## Los valores p de la regresión son: 6.701581e-19 0.009988772
## (Intercept) hp
## 6.701581e-19 9.988772e-03
Wt vs Hp

##
## Call:
## lm(formula = wt ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA 0.6587479
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp 0.6547444 0.6627513
## Los valores p de la regresión son: 2.389427e-06 4.145827e-05
## (Intercept) hp
## 2.389427e-06 4.145827e-05
Qsec vs Hp

##
## Call:
## lm(formula = qsec ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.7082234
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.7150842 -0.7013626
## Los valores p de la regresión son: 6.728254e-27 5.766253e-06
## (Intercept) hp
## 6.728254e-27 5.766253e-06
Vs vs Hp

##
## Call:
## lm(formula = vs ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.7230967
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.7249901 -0.7212034
## Los valores p de la regresión son: 4.460506e-09 2.940896e-06
## (Intercept) hp
## 4.460506e-09 2.940896e-06
Am vs Hp

##
## Call:
## lm(formula = am ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.2432043
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.2458364 -0.2405721
## Los valores p de la regresión son: 0.003240628 0.1798309
## (Intercept) hp
## 0.003240628 0.179830905
Gear vs Hp

##
## Call:
## lm(formula = gear ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA -0.1257043
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp -0.1296848 -0.1217237
## Los valores p de la regresión son: 2.724935e-13 0.4930119
## (Intercept) hp
## 2.724935e-13 4.930119e-01
Carb vs Hp

##
## Call:
## lm(formula = carb ~ hp, data = mtcars)
##
## Standardized Coefficients::
## (Intercept) hp
## NA 0.7498125
## 2.5 % 97.5 %
## (Intercept) NA NA
## hp 0.7440006 0.7556244
## Los valores p de la regresión son: 0.6334148 7.82781e-07
## (Intercept) hp
## 6.334148e-01 7.827810e-07