## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 2795 Columns: 36
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): Accident Date/Time, Operator Name, Pipeline/Facility Name, Pipelin...
## dbl (18): Report Number, Supplemental Number, Accident Year, Operator ID, Ac...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
plot(data_log$Liberacion, data_log$Recuperacion, col="steelblue", pch=16,
main="Nube de Puntos: Liberación vs Recuperación")# Recuperacion = b0 + b1 * log(Liberacion)
params <- coef(modelo_log)
cat("Intercepto (b0):", params[1], "\nPendiente logarítmica (b1):", params[2], "\n")## Intercepto (b0): -10.67203
## Pendiente logarítmica (b1): 65.5821
plot(data_log$Liberacion, data_log$Recuperacion,
main="Ajuste Logarítmico: Recuperación vs Liberación",
xlab="Barriles Liberados", ylab="Barriles Recuperados", pch=16, col="gray")
# Dibujar la curva logarítmica
x_seq <- seq(min(data_log$Liberacion), max(data_log$Liberacion), length.out=500)
y_pred <- predict(modelo_log, newdata = data.frame(Liberacion = x_seq))
lines(x_seq, y_pred, col="darkgreen", lwd=3)# A. Test de Pearson Normal
cor_normal <- cor.test(data_log$Liberacion, data_log$Recuperacion)
cat("\n--- TEST DE PEARSON (COMPLETO) ---\n")##
## --- TEST DE PEARSON (COMPLETO) ---
## cor
## 0.5131019
## [1] 1.426059e-185
# B. Test de Pearson Omitiendo Outliers
# Definimos outliers como el 5% superior en liberación
limite_outlier <- quantile(data_log$Liberacion, 0.95)
data_sin_outliers <- subset(data_log, Liberacion < limite_outlier)
cor_filtrado <- cor.test(data_sin_outliers$Liberacion, data_sin_outliers$Recuperacion)
cat("\n--- TEST DE PEARSON (SIN OUTLIERS) ---\n")##
## --- TEST DE PEARSON (SIN OUTLIERS) ---
## cor
## 0.8586589
#Para la estimación, supongamos un derrame de 1000 barriles:
pred_1000 <- predict(modelo_log, newdata = data.frame(Liberacion = 1000))
cat("Para 1000 bbl liberados, se estima recuperar:", round(pred_1000, 2), "bbl")## Para 1000 bbl liberados, se estima recuperar: 442.35 bbl
El modelo logarítmico indica que la tasa de recuperación disminuye conforme el desastre aumenta. El Test de Pearson sin outliers suele mostrar una correlación más alta, lo que demuestra que los accidentes extremos (mega-derrames) no siguen la lógica normal de contención y “ensucian” la estadística.