Warning: Coercing text to numeric in E2 / R2C5: '38.9'
Warning: Coercing text to numeric in F2 / R2C6: '64.7'
Warning: Coercing text to numeric in H2 / R2C8: '59.7'
Warning: Coercing text to numeric in E3 / R3C5: '38.8'
Warning: Coercing text to numeric in F3 / R3C6: '61.3'
Warning: Coercing text to numeric in H3 / R3C8: '55.0'
Warning: Coercing text to numeric in E4 / R4C5: '40.1'
Warning: Coercing text to numeric in F4 / R4C6: '60.0'
Warning: Coercing text to numeric in H4 / R4C8: '65.6'
Warning: Coercing text to numeric in E5 / R5C5: '41.6'
Warning: Coercing text to numeric in F5 / R5C6: '45.3'
Warning: Coercing text to numeric in H5 / R5C8: '61.4'
Warning: Coercing text to numeric in E6 / R6C5: '39.2'
Warning: Coercing text to numeric in F6 / R6C6: '53.8'
Warning: Coercing text to numeric in H6 / R6C8: '66.1'
Warning: Coercing text to numeric in E7 / R7C5: '39.7'
Warning: Coercing text to numeric in F7 / R7C6: '74.1'
Warning: Coercing text to numeric in H7 / R7C8: '61.0'
Warning: Coercing text to numeric in E8 / R8C5: '38.1'
Warning: Coercing text to numeric in F8 / R8C6: '65.4'
Warning: Coercing text to numeric in H8 / R8C8: '66.1'
Warning: Coercing text to numeric in E9 / R9C5: '37.0'
Warning: Coercing text to numeric in F9 / R9C6: '78.3'
Warning: Coercing text to numeric in H9 / R9C8: '58.9'
Warning: Coercing text to numeric in E10 / R10C5: '42.1'
Warning: Coercing text to numeric in F10 / R10C6: '47.6'
Warning: Coercing text to numeric in H10 / R10C8: '57.0'
Warning: Coercing text to numeric in E11 / R11C5: '42.3'
Warning: Coercing text to numeric in F11 / R11C6: '54.2'
Warning: Coercing text to numeric in H11 / R11C8: '58.9'
Warning: Coercing text to numeric in E12 / R12C5: '37.3'
Warning: Coercing text to numeric in F12 / R12C6: '48.0'
Warning: Coercing text to numeric in H12 / R12C8: '68.5'
Warning: Coercing text to numeric in E13 / R13C5: '39.5'
Warning: Coercing text to numeric in F13 / R13C6: '51.9'
Warning: Coercing text to numeric in H13 / R13C8: '59.2'
Warning: Coercing text to numeric in E14 / R14C5: '37.4'
Warning: Coercing text to numeric in F14 / R14C6: '53.6'
Warning: Coercing text to numeric in H14 / R14C8: '58.8'
Warning: Coercing text to numeric in E15 / R15C5: '35.1'
Warning: Coercing text to numeric in F15 / R15C6: '71.4'
Warning: Coercing text to numeric in H15 / R15C8: '58.6'
Warning: Coercing text to numeric in E16 / R16C5: '38.8'
Warning: Coercing text to numeric in F16 / R16C6: '58.3'
Warning: Coercing text to numeric in H16 / R16C8: '59.2'
Warning: Coercing text to numeric in E17 / R17C5: '36.6'
Warning: Coercing text to numeric in F17 / R17C6: '52.6'
Warning: Coercing text to numeric in H17 / R17C8: '54.4'
Warning: Coercing text to numeric in E18 / R18C5: '35.3'
Warning: Coercing text to numeric in F18 / R18C6: '59.3'
Warning: Coercing text to numeric in H18 / R18C8: '49.6'
Warning: Coercing text to numeric in E19 / R19C5: '41.1'
Warning: Coercing text to numeric in F19 / R19C6: '55.3'
Warning: Coercing text to numeric in H19 / R19C8: '54.3'
Warning: Coercing text to numeric in E20 / R20C5: '38.6'
Warning: Coercing text to numeric in F20 / R20C6: '69.6'
Warning: Coercing text to numeric in H20 / R20C8: '58.7'
Warning: Coercing text to numeric in E21 / R21C5: '39.3'
Warning: Coercing text to numeric in F21 / R21C6: '78.3'
Warning: Coercing text to numeric in H21 / R21C8: '51.7'
Warning: Coercing text to numeric in E22 / R22C5: '39.7'
Warning: Coercing text to numeric in F22 / R22C6: '38.1'
Warning: Coercing text to numeric in H22 / R22C8: '61.9'
Warning: Coercing text to numeric in E23 / R23C5: '39.7'
Warning: Coercing text to numeric in F23 / R23C6: '68.8'
Warning: Coercing text to numeric in H23 / R23C8: '52.7'
Warning: Coercing text to numeric in E24 / R24C5: '35.5'
Warning: Coercing text to numeric in F24 / R24C6: '68.8'
Warning: Coercing text to numeric in H24 / R24C8: '57.8'
Warning: Coercing text to numeric in E25 / R25C5: '35.3'
Warning: Coercing text to numeric in F25 / R25C6: '74.1'
Warning: Coercing text to numeric in H25 / R25C8: '59.7'
Warning: Coercing text to numeric in E26 / R26C5: '38.7'
Warning: Coercing text to numeric in F26 / R26C6: '50.0'
Warning: Coercing text to numeric in H26 / R26C8: '54.9'
Warning: Coercing text to numeric in E27 / R27C5: '39.9'
Warning: Coercing text to numeric in F27 / R27C6: '57.1'
Warning: Coercing text to numeric in H27 / R27C8: '65.3'
Warning: Coercing text to numeric in E28 / R28C5: '37.4'
Warning: Coercing text to numeric in F28 / R28C6: '56.3'
Warning: Coercing text to numeric in H28 / R28C8: '43.8'
Warning: Coercing text to numeric in E29 / R29C5: '39.3'
Warning: Coercing text to numeric in F29 / R29C6: '47.0'
Warning: Coercing text to numeric in H29 / R29C8: '53.5'
View(datos)
Descriptivo
summary(datos)
Team y x1 x2
Length:28 Min. : 0.000 Min. :1416 Min. :1414
Class :character 1st Qu.: 4.000 1st Qu.:1896 1st Qu.:1714
Mode :character Median : 6.500 Median :2111 Median :2106
Mean : 6.964 Mean :2110 Mean :2127
3rd Qu.:10.000 3rd Qu.:2303 3rd Qu.:2474
Max. :13.000 Max. :2971 Max. :2929
x3 x4 x6 x7
Min. :35.10 Min. :38.10 Min. : 576.0 Min. :43.80
1st Qu.:37.38 1st Qu.:52.42 1st Qu.: 720.0 1st Qu.:54.77
Median :38.85 Median :57.70 Median : 794.0 Median :58.85
Mean :38.65 Mean :59.40 Mean : 795.4 Mean :58.30
3rd Qu.:39.70 3rd Qu.:68.80 3rd Qu.: 869.8 3rd Qu.:61.10
Max. :42.30 Max. :78.30 Max. :1037.0 Max. :68.50
x8 x9
Min. :1457 Min. :1575
1st Qu.:1888 1st Qu.:1916
Median :2062 Median :2142
Mean :2133 Mean :2138
3rd Qu.:2427 3rd Qu.:2328
Max. :2876 Max. :2670
Call:
lm(formula = y ~ x8 + x2 + x7 + x9 + x4, data = datos)
Residuals:
Min 1Q Median 3Q Max
-2.78880 -1.00317 0.03609 0.86568 2.80212
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.058e+01 7.939e+00 -1.333 0.19613
x8 -2.779e-03 1.380e-03 -2.014 0.05639 .
x2 3.963e-03 7.249e-04 5.467 1.72e-05 ***
x7 2.843e-01 8.730e-02 3.257 0.00361 **
x9 -2.049e-03 1.276e-03 -1.605 0.12271
x4 4.799e-02 3.351e-02 1.432 0.16617
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.725 on 22 degrees of freedom
Multiple R-squared: 0.7998, Adjusted R-squared: 0.7543
F-statistic: 17.58 on 5 and 22 DF, p-value: 4.927e-07
AIC(modboth, k =5)
[1] 138.2391
AIC_funt(modboth,5)
'log Lik.' 113.2391 (df=7)
Obtenemos un nuevo modelo con un AIC mas bajo que el inicial, por ende utilizaremos este.
modelo <- modbothsummary(modelo)
Call:
lm(formula = y ~ x8 + x2 + x7 + x9 + x4, data = datos)
Residuals:
Min 1Q Median 3Q Max
-2.78880 -1.00317 0.03609 0.86568 2.80212
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.058e+01 7.939e+00 -1.333 0.19613
x8 -2.779e-03 1.380e-03 -2.014 0.05639 .
x2 3.963e-03 7.249e-04 5.467 1.72e-05 ***
x7 2.843e-01 8.730e-02 3.257 0.00361 **
x9 -2.049e-03 1.276e-03 -1.605 0.12271
x4 4.799e-02 3.351e-02 1.432 0.16617
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.725 on 22 degrees of freedom
Multiple R-squared: 0.7998, Adjusted R-squared: 0.7543
F-statistic: 17.58 on 5 and 22 DF, p-value: 4.927e-07
var. categorica??
no.
Verificacion De Supuestos
qqnorm(residuals(modelo)) # Crear gráfico Q-Qqqline(residuals(modelo)) # Añadir la línea de referencia
# La función lm() calcula y almacena los valores predichos por el modelo y los# residuos.datos$prediccion <- modelo$fitted.valuesdatos$residuos <- modelo$residuals#Distribución de los residuos ggplot(data = datos, aes(x = prediccion, y = residuos)) +geom_point(aes(color = residuos)) +scale_color_gradient2(low ="blue3", mid ="grey", high ="red") +geom_hline(yintercept =0) +geom_segment(aes(xend = prediccion, yend =0), alpha =0.2) +labs(title ="Distribución de los residuos", x ="predicción modelo",y ="residuo") +theme_bw() +theme(plot.title =element_text(hjust =0.5), legend.position ="none")
Normalidad
shapiro.test(datos$residuos)
Shapiro-Wilk normality test
data: datos$residuos
W = 0.96885, p-value = 0.55
Homocedasticidad
bptest(modelo)
studentized Breusch-Pagan test
data: modelo
BP = 6.9601, df = 5, p-value = 0.2236
ggplot(data = datos, aes(x = prediccion, y = residuos)) +geom_point(aes(color = residuos)) +scale_color_gradient2(low ="blue3", mid ="grey", high ="red") +geom_segment(aes(xend = prediccion, yend =0), alpha =0.2) +geom_smooth(se =FALSE, color ="firebrick") +labs(title ="Distribución de los residuos", x ="predicción modelo",y ="residuo") +geom_hline(yintercept =0) +theme_bw() +theme(plot.title =element_text(hjust =0.5), legend.position ="none")
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Autocorrelacion De Los Residuos
dw_resultado <-dwtest(modelo) print(dw_resultado)
Durbin-Watson test
data: modelo
DW = 1.5967, p-value = 0.1182
alternative hypothesis: true autocorrelation is greater than 0
ggplot(data = datos, aes(x =seq_along(residuos), y = residuos)) +geom_point(aes(color = residuos)) +scale_color_gradient2(low ="blue3", mid ="grey", high ="red") +geom_line(size =0.3) +labs(title ="Distribución de los residuos", x ="index", y ="residuo") +geom_hline(yintercept =0) +theme_bw() +theme(plot.title =element_text(hjust =0.5), legend.position ="none")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Tenemos que se cumplen los supuestos
Outliers y Alto Leverage
Prueba De Bonferroni
outlierTest(modelo)
No Studentized residuals with Bonferroni p < 0.05
Largest |rstudent|:
rstudent unadjusted p-value Bonferroni p
4 2.205185 0.038725 NA
# Valores de leveragehatvalues_model <-hatvalues(modelo)datos$Leverage <- hatvalues_modeln <-nrow(datos)p <-length(coef(modelo))umbral_leverage <-2* (p / n)plot(hatvalues_model, main ="Valores de Leverage", xlab ="Observaciones", ylab ="Leverage")abline(h = umbral_leverage, col ="red", lty =2)
# Distancia de Cookcooks_dist <-cooks.distance(modelo)plot(cooks_dist, main ="Distancia de Cook", xlab ="Observaciones", ylab ="Distancia de Cook")abline(h =4/ n, col ="red", lty =2)
# Prueba de Bonferroni para Outliersbonferroni_test <-outlierTest(modelo, cutoff=Inf)print("Resultados del Test de Bonferroni para Outliers:")
[1] "Resultados del Test de Bonferroni para Outliers:"
print(bonferroni_test)
rstudent unadjusted p-value Bonferroni p
4 2.2051850 0.038725 NA
21 -1.8983400 0.071481 NA
15 -1.8171484 0.083494 NA
3 1.7958115 0.086928 NA
1 1.7259639 0.099039 NA
10 -1.6258698 0.118890 NA
7 -1.2773923 0.215410 NA
8 1.2262929 0.233660 NA
9 1.1521426 0.262210 NA
24 -0.8574013 0.400900 NA
Warning in plot.window(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy, type, ...): "id.n" is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in box(...): "id.n" is not a graphical parameter
Warning in title(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, ...): "id.n" is not a
graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, ...): "id.n" is not a
graphical parameter
Warning in plot.window(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy, type, ...): "id.n" is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in box(...): "id.n" is not a graphical parameter
Warning in title(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, ...): "id.n" is not a
graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, ...): "id.n" is not a
graphical parameter
Warning in plot.window(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy, type, ...): "id.n" is not a graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in axis(side = side, at = at, labels = labels, ...): "id.n" is not a
graphical parameter
Warning in box(...): "id.n" is not a graphical parameter
Warning in title(...): "id.n" is not a graphical parameter
Warning in plot.xy(xy.coords(x, y), type = type, ...): "id.n" is not a
graphical parameter
# Para los nuevos datos de predicción (nuevo conjunto de predictores)nuevos_datos <-data.frame(x8 =5, x2 =10, x7 =15, x9 =7, x4 =3)# Predicción con intervalos de confianzapred_conf <-predict(modelo_robusto, newdata = nuevos_datos, interval ="confidence", level =0.95)# Predicción con intervalos de predicciónpred_pred <-predict(modelo_robusto, newdata = nuevos_datos, interval ="prediction", level =0.95)
Warning in predict.lm(modelo_robusto, newdata = nuevos_datos, interval = "prediction", : Assuming constant prediction variance even though model fit is weighted