Ejercicio 1

## Cargamos los datos
temperatura <- c(398, 292, 352, 575, 568, 450, 550, 408, 484, 350, 503, 600, 600)
contenido_ag2s <- c(0.15, 0.05, 0.23, 0.43, 0.23, 0.40, 0.44, 0.44, 0.45, 0.09, 0.59, 0.63, 0.63)

datos <- data.frame(temperatura, contenido_ag2s)
## Gráfico de dispersión
ggplot(datos, aes(x = temperatura, y = contenido_ag2s)) +
  geom_point() +
  labs(title = "Gráfico de Dispersión de Temperatura vs. Ag2S",
       x = "Temperatura de Cristalización (°C)",
       y = "Contenido de Ag2S (mol %)")

## Ajustamos el modelo de regresión lineal
modelo <- lm(contenido_ag2s ~ temperatura, data = datos)
summary(modelo)
## 
## Call:
## lm(formula = contenido_ag2s ~ temperatura, data = datos)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.27713 -0.08736  0.03855  0.07610  0.17786 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.3230052  0.1754542  -1.841  0.09273 . 
## temperatura  0.0014615  0.0003639   4.016  0.00203 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.132 on 11 degrees of freedom
## Multiple R-squared:  0.5945, Adjusted R-squared:  0.5577 
## F-statistic: 16.13 on 1 and 11 DF,  p-value: 0.002029
## Añadir la línea de regresión al gráfico de dispersión
ggplot(datos, aes(x = temperatura, y = contenido_ag2s)) +
  geom_point() +
  geom_smooth(method = "lm", col = "red") +
  labs(title = "Gráfico de Dispersión con Línea de Regresión",
       x = "Temperatura de Cristalización (°C)",
       y = "Contenido de Ag2S (mol %)")
## `geom_smooth()` using formula = 'y ~ x'

## Análisis ANOVA
anova(modelo)
## Analysis of Variance Table
## 
## Response: contenido_ag2s
##             Df  Sum Sq  Mean Sq F value   Pr(>F)   
## temperatura  1 0.28093 0.280927   16.13 0.002029 **
## Residuals   11 0.19158 0.017416                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Verificación de los supuestos
par(mfrow = c(2, 2))
plot(modelo)

Prueba de hipotesis sobre la creencia previa

H0: El contenido de plata promedio verdadero a 410°C es 0.20 (µ = 0.20)

H1: El contenido de plata promedio verdadero a 410°C no es 0.20 (µ ≠ 0.20)

nueva_temperatura <- data.frame(temperatura = 410)
prediccion <- predict(modelo, nueva_temperatura, interval="confidence")

t.test(contenido_ag2s, mu = 0.20, alternative = "two.sided")
## 
##  One Sample t-test
## 
## data:  contenido_ag2s
## t = 3.019, df = 12, p-value = 0.01068
## alternative hypothesis: true mean is not equal to 0.2
## 95 percent confidence interval:
##  0.2462420 0.4860657
## sample estimates:
## mean of x 
## 0.3661538
prediccion
##         fit       lwr       upr
## 1 0.2762147 0.1817718 0.3706575

Criterio

Como el análisis indica una relación positiva significativa entre la temperatura de cristalización y el contenido de Ag₂S en los cristales de galena.Además, los datos sugieren que el contenido de Ag₂S promedio verdadero a 410°C es significativamente mayor que 0.20.

Ejercicio 2

# Cargar los datos
tiempo_respuesta <- c(170, 165, 168, 175, 180, 190, 185, 220, 220, 240)
usuarios <- c(13, 12, 11, 16, 15, 20, 19, 24, 25, 28)
uso_cpu <- c(40, 35, 32, 40, 60, 55, 55, 65, 72, 75)
memoria <- c(1648, 1900, 1740, 1710, 1600, 1500, 1360, 1300, 1200, 1100)
ancho_banda <- c(80, 95, 85, 82, 80, 75, 70, 65, 60, 55)
latencia <- c(18, 25, 28, 30, 40, 45, 50, 55, 60, 65)

datos <- data.frame(tiempo_respuesta, usuarios, uso_cpu, memoria, ancho_banda, latencia)
# Ajustar el modelo de regresión lineal múltiple
modelo <- lm(tiempo_respuesta ~ usuarios + uso_cpu + memoria + ancho_banda + latencia, data = datos)
summary(modelo)
## 
## Call:
## lm(formula = tiempo_respuesta ~ usuarios + uso_cpu + memoria + 
##     ancho_banda + latencia, data = datos)
## 
## Residuals:
##       1       2       3       4       5       6       7       8       9      10 
##  1.0267  5.6131  5.7701 -7.8724 -0.7862 -6.4893 -6.7745  4.9594 -1.8551  6.4082 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 125.26435   88.78967   1.411    0.231
## usuarios      2.93885    2.04789   1.435    0.225
## uso_cpu       0.23891    0.58176   0.411    0.702
## memoria       0.09949    0.14408   0.690    0.528
## ancho_banda  -2.16073    2.76459  -0.782    0.478
## latencia      0.26966    0.77829   0.346    0.746
## 
## Residual standard error: 8.449 on 4 degrees of freedom
## Multiple R-squared:  0.9535, Adjusted R-squared:  0.8954 
## F-statistic: 16.41 on 5 and 4 DF,  p-value: 0.009021
anova(modelo) 
## Analysis of Variance Table
## 
## Response: tiempo_respuesta
##             Df Sum Sq Mean Sq F value    Pr(>F)    
## usuarios     1 5797.2  5797.2 81.2057 0.0008397 ***
## uso_cpu      1   10.9    10.9  0.1530 0.7156091    
## memoria      1    3.2     3.2  0.0445 0.8431616    
## ancho_banda  1   36.7    36.7  0.5142 0.5129565    
## latencia     1    8.6     8.6  0.1200 0.7464419    
## Residuals    4  285.6    71.4                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Verificación de los supuestos
par(mfrow = c(2, 2))
plot(modelo)
## Warning in sqrt(crit * p * (1 - hh)/hh): Se han producido NaNs
## Warning in sqrt(crit * p * (1 - hh)/hh): Se han producido NaNs

# método backward
modelo_backward <- step(modelo, direction = "backward")
## Start:  AIC=45.52
## tiempo_respuesta ~ usuarios + uso_cpu + memoria + ancho_banda + 
##     latencia
## 
##               Df Sum of Sq    RSS    AIC
## - latencia     1     8.570 294.12 43.814
## - uso_cpu      1    12.039 297.59 43.931
## - memoria      1    34.037 319.59 44.645
## - ancho_banda  1    43.608 329.16 44.940
## <none>                     285.55 45.518
## - usuarios     1   147.018 432.57 47.672
## 
## Step:  AIC=43.81
## tiempo_respuesta ~ usuarios + uso_cpu + memoria + ancho_banda
## 
##               Df Sum of Sq    RSS    AIC
## - uso_cpu      1    18.574 312.70 42.427
## - memoria      1    26.232 320.36 42.668
## - ancho_banda  1    36.710 330.84 42.990
## <none>                     294.12 43.814
## - usuarios     1   289.324 583.45 48.664
## 
## Step:  AIC=42.43
## tiempo_respuesta ~ usuarios + memoria + ancho_banda
## 
##               Df Sum of Sq    RSS    AIC
## - memoria      1     12.14 324.84 40.808
## - ancho_banda  1     23.14 335.84 41.140
## <none>                     312.70 42.427
## - usuarios     1    435.74 748.44 49.154
## 
## Step:  AIC=40.81
## tiempo_respuesta ~ usuarios + ancho_banda
## 
##               Df Sum of Sq    RSS    AIC
## - ancho_banda  1     20.10 344.94 39.408
## <none>                     324.84 40.808
## - usuarios     1    425.26 750.10 47.176
## 
## Step:  AIC=39.41
## tiempo_respuesta ~ usuarios
## 
##            Df Sum of Sq    RSS    AIC
## <none>                   344.9 39.408
## - usuarios  1    5797.2 6142.1 66.203
summary(modelo_backward)
## 
## Call:
## lm(formula = tiempo_respuesta ~ usuarios, data = datos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -9.317 -4.835  1.197  3.831  8.162 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 112.4300     7.1118   15.81 2.56e-07 ***
## usuarios      4.3098     0.3717   11.60 2.78e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.566 on 8 degrees of freedom
## Multiple R-squared:  0.9438, Adjusted R-squared:  0.9368 
## F-statistic: 134.5 on 1 and 8 DF,  p-value: 2.783e-06
# método forward
modelo_forward <- step(lm(tiempo_respuesta ~ 1, data = datos), scope = list(lower = lm(tiempo_respuesta ~ 1), upper = modelo), direction = "forward")
## Start:  AIC=66.2
## tiempo_respuesta ~ 1
## 
##               Df Sum of Sq    RSS    AIC
## + usuarios     1    5797.2  344.9 39.408
## + ancho_banda  1    5392.0  750.1 47.176
## + memoria      1    5345.0  797.1 47.784
## + latencia     1    5194.2  947.9 49.517
## + uso_cpu      1    5124.1 1018.0 50.230
## <none>                     6142.1 66.203
## 
## Step:  AIC=39.41
## tiempo_respuesta ~ usuarios
## 
##               Df Sum of Sq    RSS    AIC
## <none>                     344.94 39.408
## + ancho_banda  1   20.0960 324.84 40.808
## + uso_cpu      1   10.9239 334.01 41.086
## + memoria      1    9.1019 335.84 41.140
## + latencia     1    0.7420 344.20 41.386
summary(modelo_forward)
## 
## Call:
## lm(formula = tiempo_respuesta ~ usuarios, data = datos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -9.317 -4.835  1.197  3.831  8.162 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 112.4300     7.1118   15.81 2.56e-07 ***
## usuarios      4.3098     0.3717   11.60 2.78e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.566 on 8 degrees of freedom
## Multiple R-squared:  0.9438, Adjusted R-squared:  0.9368 
## F-statistic: 134.5 on 1 and 8 DF,  p-value: 2.783e-06

Criterio

Como el análisis de regresión lineal múltiple sugiere que varias variables independientes influyen significativamente en el tiempo de respuesta de un servidor, los métodos backward y forward ayudan a identificar las variables más significativas, mejorando así el modelo predictivo.