library(dplyr)
library(knitr)
library(readr)
library(ggplot2)
library(patchwork)
options(scipen = 999)
humedad <- c(72.4, 41.6, 34.3, 35.1, 10.7, 12.9, 8.3, 20.1, 72.2, 24.0, 23.2, 47.4, 31.5, 10.6, 11.2, 73.3, 75.4, 96.6, 107.4, 54.9)
temperatura <- c(76.3, 70.3, 77.1, 68.0, 79.0, 67.4, 66.8, 76.9, 77.7, 67.7, 76.8, 86.6, 76.9, 86.3, 86.0, 76.3, 77.9,
78.7, 86.8, 70.9)
presion <- c(29.18, 29.35, 29.24, 29.27, 29.78, 29.39, 29.69, 29.48, 29.09, 29.60, 29.38, 29.35, 29.63, 29.56, 29.48, 29.40, 29.28, 29.29, 29.03, 29.37)
oxido_nitroso <- c(0.90, 0.91, 0.96, 0.89, 1.00, 1.10, 1.15, 1.03, 0.77, 1.07, 1.07, 0.94, 1.10, 1.10, 1.10, 0.91, 0.87, 0.78, 0.82, 0.95)
datos_camiones <- data.frame(oxido_nitroso, humedad, temperatura, presion)
kable(datos_camiones, caption = "Factores ambientales que influyen en la formación de óxido nitroso en motores disel en camiones")
| oxido_nitroso | humedad | temperatura | presion |
|---|---|---|---|
| 0.90 | 72.4 | 76.3 | 29.18 |
| 0.91 | 41.6 | 70.3 | 29.35 |
| 0.96 | 34.3 | 77.1 | 29.24 |
| 0.89 | 35.1 | 68.0 | 29.27 |
| 1.00 | 10.7 | 79.0 | 29.78 |
| 1.10 | 12.9 | 67.4 | 29.39 |
| 1.15 | 8.3 | 66.8 | 29.69 |
| 1.03 | 20.1 | 76.9 | 29.48 |
| 0.77 | 72.2 | 77.7 | 29.09 |
| 1.07 | 24.0 | 67.7 | 29.60 |
| 1.07 | 23.2 | 76.8 | 29.38 |
| 0.94 | 47.4 | 86.6 | 29.35 |
| 1.10 | 31.5 | 76.9 | 29.63 |
| 1.10 | 10.6 | 86.3 | 29.56 |
| 1.10 | 11.2 | 86.0 | 29.48 |
| 0.91 | 73.3 | 76.3 | 29.40 |
| 0.87 | 75.4 | 77.9 | 29.28 |
| 0.78 | 96.6 | 78.7 | 29.29 |
| 0.82 | 107.4 | 86.8 | 29.03 |
| 0.95 | 54.9 | 70.9 | 29.37 |
Variable dependiente \(y\) = oxido nitroso
Variable independiente \(x_1\) = húmedad
Variable independiente \(x_2\) = temperatura
Variable independiente \(x_3\) = presión
grafica_1 <- ggplot(data = datos_camiones, mapping = aes(x = humedad, y = oxido_nitroso)) +
geom_point(color = "forestgreen", size = 2) +
labs(title = 'oxido_nitroso ~ humedad', x = 'humedad') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_2 <- ggplot(data = datos_camiones, mapping = aes(x = temperatura, y = oxido_nitroso)) +
geom_point(color = "orange", size = 2) +
labs(title = 'oxido_nitroso ~ temperatura', x = 'tempertura') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_3 <- ggplot(data = datos_camiones, mapping = aes(x = presion, y = oxido_nitroso)) +
geom_point(color = "darkblue", size = 2) +
labs(title = 'oxido_nitroso ~ presion', x = 'presion') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_1 + grafica_2 + grafica_3
modelo <- lm(formula = oxido_nitroso ~ ., data = datos_camiones)
summary(modelo)
Call:
lm(formula = oxido_nitroso ~ ., data = datos_camiones)
Residuals:
Min 1Q Median 3Q Max
-0.11799 -0.02526 0.01345 0.04103 0.06523
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -3.5077781 3.0048641 -1.167 0.26017
humedad -0.0026250 0.0006549 -4.008 0.00101 **
temperatura 0.0007989 0.0020451 0.391 0.70121
presion 0.1541550 0.1013675 1.521 0.14784
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.05617 on 16 degrees of freedom
Multiple R-squared: 0.8005, Adjusted R-squared: 0.763
F-statistic: 21.4 on 3 and 16 DF, p-value: 0.000007609
\(y = \beta0 + \beta1x_1 + \beta3x_2 + \beta4x_3\)
\(yˆ=−3.507778−0.002625(50.0)+0.000799(76.0)+0.1541553(29.30)=0.9384ppm.\)
nuevo_dato <- data.frame(humedad = 50, temperatura = 76, presion = 29.30)
prediccion <- predict(modelo, newdata = nuevo_dato)
paste("La cantidad estimada de óxido nitroso emitido es:", round(prediccion,2))
[1] "La cantidad estimada de óxido nitroso emitido es: 0.94"
En el resumen de nuestro modelo identificados que las variables temperatura y humedad no son estadísitcamente significativas, ya que presentan valores por encima de 0.5, siendo la presión nuestra única variable significativa. Nuestros valores R-squared y Adjusted R-squared son de 0.8005 y 0.763, siendo valores altos pero que podrían mejorar al tomar nuestra variable de interés identificada anteriormente.
La temperatura ambiental \(x_1\).
El número de días del mes \(x_2\).
La pureza promedio del producto \(x_3\).
Las toneladas fabricadas del producto \(x_4\).
Se identifica y como el consumo de energía eléctrica.
y <- c(240, 236, 290, 274, 301, 316, 300, 296, 267, 276, 288, 261)
x1 <- c(25, 31, 45, 60, 65, 72, 80, 84, 75, 60, 50, 38)
x2 <- c(24, 21, 24, 25, 25, 26, 25, 25, 24, 25, 25, 23)
x3 <- c(91, 90, 88, 87, 91, 94, 87, 86, 88, 91, 90, 89)
x4 <- c(100, 95, 110, 88, 94, 99, 97, 96, 110, 105, 100, 98)
datos_factores <- data.frame(y, x1, x2, x3, x4)
kable(datos_factores, caption = "Aspectos que se relacionan con el consumo de energía eléctrica en una plata química")
| y | x1 | x2 | x3 | x4 |
|---|---|---|---|---|
| 240 | 25 | 24 | 91 | 100 |
| 236 | 31 | 21 | 90 | 95 |
| 290 | 45 | 24 | 88 | 110 |
| 274 | 60 | 25 | 87 | 88 |
| 301 | 65 | 25 | 91 | 94 |
| 316 | 72 | 26 | 94 | 99 |
| 300 | 80 | 25 | 87 | 97 |
| 296 | 84 | 25 | 86 | 96 |
| 267 | 75 | 24 | 88 | 110 |
| 276 | 60 | 25 | 91 | 105 |
| 288 | 50 | 25 | 90 | 100 |
| 261 | 38 | 23 | 89 | 98 |
grafica_1 <- ggplot(data = datos_factores, mapping = aes(x = x1, y = y)) +
geom_point(color = "orange", size = 2) +
labs(title = 'consumo ~ tempertura', x = 'temperatura') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_2 <- ggplot(data = datos_factores, mapping = aes(x = x2, y = y)) +
geom_point(color = "forestgreen", size = 2) +
labs(title = 'consumo ~ dias de mes', x = 'dias de mes') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_3 <- ggplot(data = datos_factores, mapping = aes(x = x3, y = y)) +
geom_point(color = "purple", size = 2) +
labs(title = 'consumo ~ purezas del producto', x = 'purezas del producto') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_4 <- ggplot(data = datos_factores, mapping = aes(x = x4, y = y)) +
geom_point(color = "red", size = 2) +
labs(title = 'consumo ~ produccion toneladas', x = 'produccion toneldas') +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
grafica_1 + grafica_2 + grafica_3 + grafica_4
modelo <- lm(formula = y ~ ., data = datos_factores)
summary(modelo)
Call:
lm(formula = y ~ ., data = datos_factores)
Residuals:
Min 1Q Median 3Q Max
-18.758 -9.952 3.350 6.627 23.311
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -102.71324 207.85885 -0.494 0.636
x1 0.60537 0.36890 1.641 0.145
x2 8.92364 5.30052 1.684 0.136
x3 1.43746 2.39162 0.601 0.567
x4 0.01361 0.73382 0.019 0.986
Residual standard error: 15.58 on 7 degrees of freedom
Multiple R-squared: 0.7447, Adjusted R-squared: 0.5989
F-statistic: 5.106 on 4 and 7 DF, p-value: 0.0303
$y = \beta0 + \beta1x_1 + \beta2x_2 + \beta3x_3 + \beta4x_4$
$yˆ=–102.7132+0.6054x1+8.9236x2+1.4374x3+0.0136x4=287.56$
nuevo_dato <- data.frame(x1 = 75, x2 = 24, x3 = 90, x4 = 98)
prediccion <- predict(modelo, newdata = nuevo_dato)
paste("La predicción de consumo de energía eléctrica es:", round(prediccion, 2))
[1] "La predicción de consumo de energía eléctrica es: 287.56"
En comparación con el ejercicio anterior, en el resumen del modelo identificamos que ninguna de las variables independientes es estadísticamente significativa para nuestra variable dependiente, aunque sus valores en Multiple R-squared y Adjusted R-square sean de 0.7447 y 0.5989 respectivamente, interpretando así que el modelo permite explicar solo el 74% de la variabilidad del consumo de energía eléctrica.