# Carga de datos
# Asegúrate de tener el archivo en la carpeta del proyecto
archivo <- "tabela_de_pocos_janeiro_2018.xlsx"
# Control de errores en carga
tryCatch({
datos <- read_excel(archivo)
}, error = function(e) {
stop("Error: No se encuentra el archivo .xlsx. Verifica el nombre y la ruta.")
})
# Visualización estructura
str(datos[, c("PROFUNDIDADE_VERTICAL_M", "PROFUNDIDADE_SONDADOR_M")])tibble [29,575 × 2] (S3: tbl_df/tbl/data.frame)
$ PROFUNDIDADE_VERTICAL_M: num [1:29575] -3145 6900 2937 2934 2953 ...
$ PROFUNDIDADE_SONDADOR_M: num [1:29575] 4050 6925 3809 4575 4570 ...
Se seleccionan las variables de interés y se realiza la limpieza.
# Limpieza y Conversión
datos_model <- datos %>%
select(PROFUNDIDADE_VERTICAL_M, PROFUNDIDADE_SONDADOR_M) %>%
mutate(
# Convertir a numérico y valor absoluto
x = abs(as.numeric(str_replace(as.character(PROFUNDIDADE_VERTICAL_M), ",", "."))),
y = abs(as.numeric(str_replace(as.character(PROFUNDIDADE_SONDADOR_M), ",", ".")))
) %>%
filter(!is.na(x) & !is.na(y) & x > 0 & y > 0)
# Verificación
n <- nrow(datos_model)
cat(paste("Registros válidos procesados:", n))Registros válidos procesados: 5511
par(mar = c(5, 5, 4, 2))
plot(datos_model$x, datos_model$y,
main = "Gráfica N°1: Dispersión Exploratoria de Datos",
xlab = "Profundidad Vertical (m)",
ylab = "Profundidad Sondador (m)",
col = "#3498DB", pch = 16, cex = 0.7, frame.plot = FALSE)
grid(nx = NULL, ny = NULL, col = "#D7DBDD", lty = "dotted")
axis(1); axis(2)Se plantea el modelo matemático: \[y = mx + b\]
Call:
lm(formula = y ~ x, data = datos_model)
Residuals:
Min 1Q Median 3Q Max
-26614.9 -206.1 -159.0 -56.3 5507.2
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 258.65030 12.52771 20.65 <0.0000000000000002 ***
x 0.97667 0.00525 186.04 <0.0000000000000002 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 625 on 5509 degrees of freedom
Multiple R-squared: 0.8627, Adjusted R-squared: 0.8627
F-statistic: 3.461e+04 on 1 and 5509 DF, p-value: < 0.00000000000000022
par(mar = c(5, 5, 4, 2))
plot(datos_model$x, datos_model$y,
main = "Gráfica N°2: Ajuste del Modelo Lineal",
xlab = "Profundidad Vertical (m)",
ylab = "Profundidad Sondador (m)",
col = "#95A5A6", pch = 16, cex = 0.6, frame.plot = FALSE)
# Línea de Regresión
abline(modelo, col = "#E74C3C", lwd = 3)
grid(nx = NULL, ny = NULL, col = "#D7DBDD", lty = "dotted")
legend("topleft", legend = "Modelo Lineal (y=mx+b)",
col = "#E74C3C", lwd = 3, bty = "n")b <- coef(modelo)[1] # Intercepto
m <- coef(modelo)[2] # Pendiente
ecuacion_txt <- paste0("y = ", round(m, 4), "x ", sprintf("%+.4f", b))
print(ecuacion_txt)[1] "y = 0.9767x +258.6503"
# Creación de tabla con estilo GT (Estilo Antisana)
tabla <- data.frame(
Variable = c("Prof. Vertical", "Prof. Sondador"),
Tipo = c("Independiente (X)", "Dependiente (Y)"),
Pearson = c(paste0(round(r*100,2), "%"), ""),
R2 = c(paste0(round(r2*100,2), "%"), ""),
Intercepto = c(sprintf("%.4f", b), ""),
Pendiente = c(sprintf("%.4f", m), ""),
Ecuacion = c(ecuacion_txt, "")
)
tabla %>%
gt() %>%
tab_header(
title = md("**RESUMEN DEL MODELO DE REGRESIÓN LINEAL**"),
subtitle = "Parámetros y Bondad de Ajuste"
) %>%
tab_source_note(source_note = "Fuente: Cálculos Grupo 3") %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(
style = list(cell_fill(color = "#2C3E50"), cell_text(color = "white", weight = "bold")),
locations = cells_title()
) %>%
tab_style(
style = list(cell_fill(color = "#ECF0F1"), cell_text(weight = "bold", color = "#2C3E50")),
locations = cells_column_labels()
) %>%
tab_options(
table.border.top.color = "#2C3E50",
table.border.bottom.color = "#2C3E50",
data_row.padding = px(8)
)| RESUMEN DEL MODELO DE REGRESIÓN LINEAL | ||||||
| Parámetros y Bondad de Ajuste | ||||||
| Variable | Tipo | Pearson | R2 | Intercepto | Pendiente | Ecuacion |
|---|---|---|---|---|---|---|
| Prof. Vertical | Independiente (X) | 92.88% | 86.27% | 258.6503 | 0.9767 | y = 0.9767x +258.6503 |
| Prof. Sondador | Dependiente (Y) | |||||
| Fuente: Cálculos Grupo 3 | ||||||
Pregunta: ¿Cuál será la profundidad estimada del sondador para un objetivo vertical de 3000 metros?
Estimación (m)
3188.666
cat(paste0("Entre la profundidad vertical y la profundidad del sondador existe una relación lineal positiva muy fuerte. ",
"El modelo **", ecuacion_txt, "** explica el **", round(r2*100, 2), "%** de la variabilidad de los datos. ",
"Esto confirma que la profundidad vertical es el factor determinante para la longitud de perforación."))Entre la profundidad vertical y la profundidad del sondador existe una relación lineal positiva muy fuerte. El modelo y = 0.9767x +258.6503 explica el 86.27% de la variabilidad de los datos. Esto confirma que la profundidad vertical es el factor determinante para la longitud de perforación.