datos_1<-mtcars[, c(1,6,8)]
datos_1$vs<- as.factor(datos_1$vs)
str(datos_1)
## 'data.frame': 32 obs. of 3 variables:
## $ mpg: num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ vs : Factor w/ 2 levels "0","1": 1 1 2 2 1 2 1 2 2 2 ...
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
ggplot(data = datos_1, aes(x = wt, y = mpg, color = vs)) +
geom_point() +
geom_smooth(method = "lm", se = TRUE)
## `geom_smooth()` using formula = 'y ~ x'

modelo3<-lm(mpg~wt+vs,data=datos_1)
summary(modelo3)
##
## Call:
## lm(formula = mpg ~ wt + vs, data = datos_1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7071 -2.4415 -0.3129 1.4319 6.0156
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.0042 2.3554 14.012 1.92e-14 ***
## wt -4.4428 0.6134 -7.243 5.63e-08 ***
## vs1 3.1544 1.1907 2.649 0.0129 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.78 on 29 degrees of freedom
## Multiple R-squared: 0.801, Adjusted R-squared: 0.7873
## F-statistic: 58.36 on 2 and 29 DF, p-value: 6.818e-11