#install.packages("tidyverse")
library(tidyverse)
Primera parte ejercicio manual Pagina 1
Pagina 2
Ejercicio 2 problema 1
y <- c(250, 220, 200, 350, 210, 205,285,190)
x1 <- c(76,61,50,94,55,61,80,52)
x2 <- c(80,72,70,122,75,95,120,68)
x3 <- c(13.5,12.1,11.6,12.5,13.5,14,12.5,14.5)
misDatos <- data.frame(x1,x2,x3,y)
x1_y
x1_y<-misDatos %>% select(`x1`, `y`)
ggplot(x1_y, aes(x=`x1`, y=`y`)) + geom_point() + geom_smooth() + geom_smooth(method = "lm", col = "red")
x2_y
x2_y<-misDatos %>% select(`x2`, `y`)
ggplot(x2_y, aes(x=`x2`, y=`y`)) + geom_point() + geom_smooth() + geom_smooth(method = "lm", col = "red")
x3_y
x3_y<-misDatos %>% select(`x3`, `y`)
ggplot(x3_y, aes(x=`x3`, y=`y`)) + geom_point() + geom_smooth() + geom_smooth(method = "lm", col = "red")
pregunta 2 mostrar resumen:
Resumen general de todos los datos
summary(misDatos)
x1 x2 x3 y
Min. :50.00 Min. : 68.00 Min. :11.60 Min. :190.0
1st Qu.:54.25 1st Qu.: 71.50 1st Qu.:12.40 1st Qu.:203.8
Median :61.00 Median : 77.50 Median :13.00 Median :215.0
Mean :66.12 Mean : 87.75 Mean :13.03 Mean :238.8
3rd Qu.:77.00 3rd Qu.:101.25 3rd Qu.:13.62 3rd Qu.:258.8
Max. :94.00 Max. :122.00 Max. :14.50 Max. :350.0
Resumen de la modelo linea simple por variable
fit1 <- lm(data = x1_y, `y`~`x1`)
fit2 <- lm(data = x2_y, `y`~`x2`)
fit3 <- lm(data = x3_y, `y`~`x3`)
summary(fit1)
Call:
lm(formula = y ~ x1, data = x1_y)
Residuals:
Min 1Q Median 3Q Max
-22.1306 -5.1759 -0.8275 10.5814 17.0238
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 15.2268 24.8824 0.612 0.563
x1 3.3803 0.3675 9.199 9.3e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 15.16 on 6 degrees of freedom
Multiple R-squared: 0.9338, Adjusted R-squared: 0.9228
F-statistic: 84.63 on 1 and 6 DF, p-value: 9.303e-05
summary(fit2)
Call:
lm(formula = y ~ x2, data = x2_y)
Residuals:
Min 1Q Median 3Q Max
-49.09 -10.72 -1.48 17.85 38.77
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 53.0637 46.2261 1.148 0.29470
x2 2.1161 0.5127 4.128 0.00616 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 30.08 on 6 degrees of freedom
Multiple R-squared: 0.7396, Adjusted R-squared: 0.6961
F-statistic: 17.04 on 1 and 6 DF, p-value: 0.006164
summary(fit3)
Call:
lm(formula = y ~ x3, data = x3_y)
Residuals:
Min 1Q Median 3Q Max
-63.79 -25.88 -18.51 23.95 102.03
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 467.59 275.05 1.700 0.140
x3 -17.57 21.06 -0.834 0.436
Residual standard error: 55.79 on 6 degrees of freedom
Multiple R-squared: 0.1039, Adjusted R-squared: -0.04543
F-statistic: 0.6958 on 1 and 6 DF, p-value: 0.4361
Problema 3,4: calculo de la correlacion y su grafica
library(corrplot)
correlacion<-round(cor(x = misDatos , method = "pearson"), 3)
correlacion
x1 x2 x3 y
x1 1.000 0.858 -0.189 0.966
x2 0.858 1.000 -0.173 0.860
x3 -0.189 -0.173 1.000 -0.322
y 0.966 0.860 -0.322 1.000
library(corrplot)
corrplot(correlacion, method="number", type="upper")