Se carga el dataset “women” propio de R
data <- datasets::women
plot(height~weight, data=women)
Con las variables de altura y peso se realiza una regresión lineal mediante la función lm
regLWomen=lm(height~weight, data=women)
summary(regLWomen)
##
## Call:
## lm(formula = height ~ weight, data = women)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83233 -0.26249 0.08314 0.34353 0.49790
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 25.723456 1.043746 24.64 2.68e-12 ***
## weight 0.287249 0.007588 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.44 on 13 degrees of freedom
## Multiple R-squared: 0.991, Adjusted R-squared: 0.9903
## F-statistic: 1433 on 1 and 13 DF, p-value: 1.091e-14
Se grafica la regresión lineal obtenida
plot(height~weight, data=women)
abline(25.723456, 0.287249, col='blue')
Se crean los 5 nuevos registros para incorporarlos
ww <- c(80,124,135,149,157)
predict.lm(regLWomen,data.frame(weight=ww))
## 1 2 3 4 5
## 48.70339 61.34236 64.50210 68.52359 70.82158
Se incorporan los datos al dataset
weightNew <- c(women$weight, ww)
heightNew <- c(women$height,c(48.70339,61.34236,64.50210,68.52359,70.82158))
regLWomenNew <- lm(heightNew~weightNew)
summary(regLWomenNew)
##
## Call:
## lm(formula = heightNew ~ weightNew)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83233 -0.08967 0.00000 0.25059 0.49790
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 25.723453 0.598592 42.97 <2e-16 ***
## weightNew 0.287249 0.004397 65.33 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.374 on 18 degrees of freedom
## Multiple R-squared: 0.9958, Adjusted R-squared: 0.9956
## F-statistic: 4268 on 1 and 18 DF, p-value: < 2.2e-16
plot(heightNew~weightNew)
Se multiplican por 100 un dato del dataset
weightMulti <- (c(weightNew[1]*100,weightNew[2: 20]))
heightMulti <- (c(heightNew[1]*100,heightNew[2: 20]))
regLWomenMulti <- lm(heightMulti~weightMulti)
summary(regLWomenMulti)
##
## Call:
## lm(formula = heightMulti ~ weightMulti)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.0010 -2.9146 0.1341 2.2641 12.0941
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.7637879 0.9971542 -3.775 0.00139 **
## weightMulti 0.5046636 0.0003873 1303.193 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.289 on 18 degrees of freedom
## Multiple R-squared: 1, Adjusted R-squared: 1
## F-statistic: 1.698e+06 on 1 and 18 DF, p-value: < 2.2e-16
plot(heightMulti~weightMulti)
abline(-3.7637879, 0.5046636, col='blue')