knitr::opts_chunk$set(echo = TRUE)
setwd("C:/Users/LEO/Documents/ESTA")
Datos <- read.csv("tabela_de_pocos_janeiro_2018.csv", header = TRUE, sep = ";" , dec = ".", fileEncoding = "Latin1")
library(readxl)
library(dplyr)
library(gt)
library(e1071)
Datos_Brutos <- read_xlsx("C:/Users/LEO/Documents/ESTA/tabela_de_pocos_janeiro_2018.xlsx", sheet = 1)
colnames(Datos_Brutos) <- trimws(colnames(Datos_Brutos))
Datos <- Datos_Brutos %>%
select(any_of(c("POCO", "PROFUNDIDADE_VERTICAL_M"))) %>%
mutate(Variable_Analisis = as.numeric(gsub(",", ".", as.character(PROFUNDIDADE_VERTICAL_M))))
Variable <- na.omit(Datos$Variable_Analisis)
Variable <- Variable[Variable >= 0 & Variable < 7000]
if(length(Variable) == 0) {
stop("ERROR: No hay datos válidos para la variable seleccionada.")
}
N <- length(Variable)
K <- floor(1 + 3.322 * log10(N))
breaks_table <- seq(min(Variable), max(Variable), length.out = K + 1)
ni <- as.vector(table(cut(Variable, breaks = breaks_table, include.lowest = TRUE, right = FALSE)))
hi <- (ni / sum(ni)) * 100
Ni_asc <- cumsum(ni)
Ni_desc <- rev(cumsum(rev(ni)))
Hi_asc <- cumsum(hi)
Hi_desc <- rev(cumsum(rev(hi)))
A continuación se presenta la tabla de distribución de frecuencias obtenida.
TDF_Tvd <- data.frame(
Li = round(breaks_table[1:K], 2),
Ls = round(breaks_table[2:(K+1)], 2),
MC = round((breaks_table[1:K] + breaks_table[2:(K+1)]) / 2, 2),
ni = ni,
hi = hi,
Ni_asc = Ni_asc,
Ni_desc = Ni_desc,
Hi_asc = Hi_asc,
Hi_desc = Hi_desc
)
TDF_Tvd %>%
gt(rowname_col = "Li") %>%
tab_header(
title = md("**DISTRIBUCIÓN DE FRECUENCIAS: PROFUNDIDADE_VERTICAL_M**"),
subtitle = md("Variable: **tvd_m**")
) %>%
tab_source_note(source_note = "Fuente: Datos ANP 2018") %>%
grand_summary_rows(
columns = c(ni, hi),
fns = list("TOTAL" = ~sum(., na.rm = TRUE))
) %>%
fmt_number(
columns = c(ni, Ni_asc, Ni_desc),
decimals = 0,
use_seps = TRUE
) %>%
fmt_number(
columns = c(hi, Hi_asc, Hi_desc),
decimals = 2
) %>%
cols_label(
Ls = "Lím. Sup", MC = "Marca Clase (Xi)",
ni = "ni", hi = "hi (%)",
Ni_asc = "Ni (Asc)", Ni_desc = "Ni (Desc)",
Hi_asc = "Hi (Asc)", Hi_desc = "Hi (Desc)"
) %>%
tab_stubhead(label = "Lím. Inf") %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(
style = cell_text(align = "center"),
locations = cells_stub()
) %>%
tab_style(
style = list(cell_fill(color = "#1F4E5B"), cell_text(color = "white", weight = "bold")),
locations = list(cells_title(), cells_column_labels(), cells_stubhead())
) %>%
tab_options(
table.border.top.style = "none",
table.border.bottom.color = "#2E4053",
column_labels.border.bottom.color = "#2E4053",
data_row.padding = px(6)
)
| DISTRIBUCIÓN DE FRECUENCIAS: PROFUNDIDADE_VERTICAL_M | ||||||||
| Variable: tvd_m | ||||||||
| Lím. Inf | Lím. Sup | Marca Clase (Xi) | ni | hi (%) | Ni (Asc) | Ni (Desc) | Hi (Asc) | Hi (Desc) |
|---|---|---|---|---|---|---|---|---|
| 0.00 | 533.08 | 266.54 | 2,902 | 59.04 | 2,902 | 4,915 | 59.04 | 100.00 |
| 533.08 | 1066.15 | 799.62 | 686 | 13.96 | 3,588 | 2,013 | 73.00 | 40.96 |
| 1066.15 | 1599.23 | 1332.69 | 256 | 5.21 | 3,844 | 1,327 | 78.21 | 27.00 |
| 1599.23 | 2132.31 | 1865.77 | 184 | 3.74 | 4,028 | 1,071 | 81.95 | 21.79 |
| 2132.31 | 2665.38 | 2398.85 | 256 | 5.21 | 4,284 | 887 | 87.16 | 18.05 |
| 2665.38 | 3198.46 | 2931.92 | 295 | 6.00 | 4,579 | 631 | 93.16 | 12.84 |
| 3198.46 | 3731.54 | 3465.00 | 110 | 2.24 | 4,689 | 336 | 95.40 | 6.84 |
| 3731.54 | 4264.62 | 3998.08 | 53 | 1.08 | 4,742 | 226 | 96.48 | 4.60 |
| 4264.62 | 4797.69 | 4531.15 | 57 | 1.16 | 4,799 | 173 | 97.64 | 3.52 |
| 4797.69 | 5330.77 | 5064.23 | 47 | 0.96 | 4,846 | 116 | 98.60 | 2.36 |
| 5330.77 | 5863.85 | 5597.31 | 41 | 0.83 | 4,887 | 69 | 99.43 | 1.40 |
| 5863.85 | 6396.92 | 6130.38 | 17 | 0.35 | 4,904 | 28 | 99.78 | 0.57 |
| 6396.92 | 6930.00 | 6663.46 | 11 | 0.22 | 4,915 | 11 | 100.00 | 0.22 |
| TOTAL | — | — | 4915 | 100 | — | — | — | — |
| Fuente: Datos ANP 2018 | ||||||||
min_val <- floor(min(Variable) / 400) * 400
max_val <- ceiling(max(Variable) / 400) * 400
breaks_table <- seq(min_val, max_val, by = 400)
K <- length(breaks_table) - 1
ni <- as.vector(table(cut(Variable, breaks = breaks_table, include.lowest = TRUE, right = FALSE)))
hi <- (ni / sum(ni)) * 100
Ni_asc <- cumsum(ni)
Ni_desc <- rev(cumsum(rev(ni)))
Hi_asc <- cumsum(hi)
Hi_desc <- rev(cumsum(rev(hi)))
TDF_Tvd <- data.frame(
Li = round(breaks_table[1:K], 2),
Ls = round(breaks_table[2:(K+1)], 2),
MC = round((breaks_table[1:K] + breaks_table[2:(K+1)]) / 2, 2),
ni = ni,
hi = hi,
Ni_asc = Ni_asc,
Ni_desc = Ni_desc,
Hi_asc = Hi_asc,
Hi_desc = Hi_desc
)
TDF_Tvd %>%
gt(rowname_col = "Li") %>%
tab_header(
title = md("**DISTRIBUCIÓN DE FRECUENCIAS SIMPLIFICADA: PROFUNDIDADE_VERTICAL_M**"),
subtitle = md("Variable: **tvd_m** (Amplitud = 400)")
) %>%
tab_source_note(source_note = "Fuente: Datos ANP 2018") %>%
grand_summary_rows(
columns = c(ni, hi),
fns = list("TOTAL" = ~sum(., na.rm = TRUE))
) %>%
fmt_number(
columns = c(ni, Ni_asc, Ni_desc),
decimals = 0,
use_seps = TRUE
) %>%
fmt_number(
columns = c(hi, Hi_asc, Hi_desc),
decimals = 2
) %>%
cols_label(
Ls = "Lím. Sup", MC = "Marca Clase (Xi)",
ni = "ni", hi = "hi (%)",
Ni_asc = "Ni (Asc)", Ni_desc = "Ni (Desc)",
Hi_asc = "Hi (Asc)", Hi_desc = "Hi (Desc)"
) %>%
tab_stubhead(label = "Lím. Inf") %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(
style = cell_text(align = "center"),
locations = cells_stub()
) %>%
tab_style(
style = list(cell_fill(color = "#1F4E5B"), cell_text(color = "white", weight = "bold")),
locations = list(cells_title(), cells_column_labels(), cells_stubhead())
) %>%
tab_options(
table.border.top.style = "none",
table.border.bottom.color = "#2E4053",
column_labels.border.bottom.color = "#2E4053",
data_row.padding = px(6)
)
| DISTRIBUCIÓN DE FRECUENCIAS SIMPLIFICADA: PROFUNDIDADE_VERTICAL_M | ||||||||
| Variable: tvd_m (Amplitud = 400) | ||||||||
| Lím. Inf | Lím. Sup | Marca Clase (Xi) | ni | hi (%) | Ni (Asc) | Ni (Desc) | Hi (Asc) | Hi (Desc) |
|---|---|---|---|---|---|---|---|---|
| 0 | 400 | 200 | 2,685 | 54.63 | 2,685 | 4,915 | 54.63 | 100.00 |
| 400 | 800 | 600 | 630 | 12.82 | 3,315 | 2,230 | 67.45 | 45.37 |
| 800 | 1200 | 1000 | 338 | 6.88 | 3,653 | 1,600 | 74.32 | 32.55 |
| 1200 | 1600 | 1400 | 192 | 3.91 | 3,845 | 1,262 | 78.23 | 25.68 |
| 1600 | 2000 | 1800 | 138 | 2.81 | 3,983 | 1,070 | 81.04 | 21.77 |
| 2000 | 2400 | 2200 | 152 | 3.09 | 4,135 | 932 | 84.13 | 18.96 |
| 2400 | 2800 | 2600 | 232 | 4.72 | 4,367 | 780 | 88.85 | 15.87 |
| 2800 | 3200 | 3000 | 212 | 4.31 | 4,579 | 548 | 93.16 | 11.15 |
| 3200 | 3600 | 3400 | 93 | 1.89 | 4,672 | 336 | 95.06 | 6.84 |
| 3600 | 4000 | 3800 | 43 | 0.87 | 4,715 | 243 | 95.93 | 4.94 |
| 4000 | 4400 | 4200 | 39 | 0.79 | 4,754 | 200 | 96.72 | 4.07 |
| 4400 | 4800 | 4600 | 45 | 0.92 | 4,799 | 161 | 97.64 | 3.28 |
| 4800 | 5200 | 5000 | 36 | 0.73 | 4,835 | 116 | 98.37 | 2.36 |
| 5200 | 5600 | 5400 | 37 | 0.75 | 4,872 | 80 | 99.13 | 1.63 |
| 5600 | 6000 | 5800 | 26 | 0.53 | 4,898 | 43 | 99.65 | 0.87 |
| 6000 | 6400 | 6200 | 6 | 0.12 | 4,904 | 17 | 99.78 | 0.35 |
| 6400 | 6800 | 6600 | 6 | 0.12 | 4,910 | 11 | 99.90 | 0.22 |
| 6800 | 7200 | 7000 | 5 | 0.10 | 4,915 | 5 | 100.00 | 0.10 |
| TOTAL | — | — | 4915 | 100 | — | — | — | — |
| Fuente: Datos ANP 2018 | ||||||||
Esta sección presenta la visualización de la distribución de los datos.
col_gris_azulado <- "#5D6D7E"
col_ejes <- "#2E4053"
max_var <- max(Variable)
breaks_50 <- seq(0, max_var + 500, by = 500)
h_base <- hist(Variable, breaks = breaks_50, plot = FALSE)
limite_x <- c(0, max(max_var, 1000))
par(mar = c(8, 5, 4, 2))
plot(h_base,
main = "Gráfica No.1: Distribución de tvd_m de Pozos Petroleros de Brasil",
xlab = "Profundidad Vertical - tvd_m (m)", ylab = "Frecuencia Absoluta",
col = col_gris_azulado, border = "white", axes = FALSE,
ylim = c(0, max(h_base$counts) * 1.1),
xlim = limite_x)
axis(1, at = seq(0, limite_x[2], by = 400), las = 2, cex.axis = 0.7)
axis(2)
grid(nx = NA, ny = NULL, col = "#D7DBDD", lty = "dotted")
par(mar = c(8, 5, 4, 2))
plot(h_base,
main = "Gráfica N°2: Distribución de tvd_m de Pozos Petroleros de Brasil",
xlab = "Profundidad Vertical - tvd_m (m)", ylab = "Total Pozos",
col = col_gris_azulado, border = "white", axes = FALSE,
ylim = c(0, sum(h_base$counts)),
xlim = limite_x)
axis(1, at = seq(0, limite_x[2], by = 400), las = 2, cex.axis = 0.7)
axis(2)
grid(nx = NA, ny = NULL, col = "#D7DBDD", lty = "dotted")
h_porc <- h_base
h_porc$counts <- (h_porc$counts / sum(h_porc$counts)) * 100
par(mar = c(8, 5, 4, 2))
plot(h_porc,
main = "Gráfica N°3: Distribución Porcentual de tvd_m de Pozos Petroleros de Brasil",
xlab = "Profundidad Vertical - tvd_m (m)", ylab = "Porcentaje (%)",
col = col_gris_azulado, border = "white", axes = FALSE, freq = TRUE,
ylim = c(0, max(h_porc$counts)*1.2),
xlim = limite_x)
axis(1, at = seq(0, limite_x[2], by = 400), las = 2, cex.axis = 0.7)
axis(2)
text(x = h_base$mids[h_base$mids <= limite_x[2]],
y = h_porc$counts[h_base$mids <= limite_x[2]],
label = paste0(round(h_porc$counts[h_base$mids <= limite_x[2]], 1), "%"),
pos = 3, cex = 0.6, col = col_ejes)
par(mar = c(8, 5, 4, 2))
plot(h_porc,
main = "Gráfica No.4: Distribución Porcentual de tvd_m de Pozos Petroleros de Brasil",
xlab = "Profundidad Vertical - tvd_m (m)", ylab = "% del Total",
col = col_gris_azulado, border = "white", axes = FALSE, freq = TRUE,
ylim = c(0, 100),
xlim = limite_x)
axis(1, at = seq(0, limite_x[2], by = 400), las = 2, cex.axis = 0.7)
axis(2)
text(x = h_base$mids[h_base$mids <= limite_x[2]],
y = h_porc$counts[h_base$mids <= limite_x[2]],
label = paste0(round(h_porc$counts[h_base$mids <= limite_x[2]], 1), "%"),
pos = 3, cex = 0.6, col = col_ejes)
col_gris_azulado <- "#5D6D7E"
col_acento <- "#C0392B"
par(mar = c(8, 5, 4, 2))
boxplot(Variable, horizontal = TRUE, col = col_gris_azulado,
main = "Gráfica No.5: Diagrama de Caja (tvd_m)",
xlab = "Profundidad Vertical - tvd_m (m)", outline = TRUE, outpch = 19,
outcol = col_acento, axes = FALSE, xlim = c(0.7, 1.3),
ylim = limite_x)
axis(1, at = seq(0, limite_x[2], by = 400), las = 2, cex.axis = 0.7)
box()
col_azul_oscuro <- "#2E4053"
col_rojo_fuerte <- "#C0392B"
par(mar = c(8, 5, 4, 8), xpd = TRUE)
x_vals_ojiva <- breaks_table
plot(x_vals_ojiva, c(0, Ni_asc), type = "o", col = col_azul_oscuro,
lwd=2, pch=19, axes=F,
main = "Gráfica No.6: Ojivas Ascendente y Descendente (tvd_m)",
xlab = "Profundidad Vertical - tvd_m (m)", ylab = "Frecuencia acumulada")
lines(x_vals_ojiva, c(Ni_desc, 0), type = "o", col = col_rojo_fuerte,
lwd=2, pch=19)
axis(1, at = seq(0, max(breaks_table), by = 400), las = 2, cex.axis = 0.6)
axis(2)
legend("right", legend = c("Ascendente", "Descendente"),
col = c(col_azul_oscuro, col_rojo_fuerte),
lty = 1, pch = 19, cex = 0.7, lwd=2,
inset = c(-0.15, 0), bty="n")
grid()
media_val <- mean(Variable)
mediana_val <- median(Variable)
sd_val <- sd(Variable)
status_atipicos <- if(length(boxplot.stats(Variable)$out) > 0) {
paste0(length(boxplot.stats(Variable)$out), " [ ", round(min(boxplot.stats(Variable)$out), 2), " ; ", round(max(boxplot.stats(Variable)$out), 2), "]")
} else { "0 (Sin atípicos)" }
df_resumen <- data.frame(
Variable = "tvd_m",
Rango = paste0("[", round(min(Variable), 2), " ; ", round(max(Variable), 2), "]"),
X = media_val,
Me = mediana_val,
Mo = paste(round(TDF_Tvd$MC[TDF_Tvd$hi == max(TDF_Tvd$hi)], 2), collapse = ", "),
Varianza = var(Variable),
sd = sd_val,
CV = (sd_val / abs(media_val)) * 100,
As = skewness(Variable, type = 2),
K = kurtosis(Variable, type = 2),
Atipicos = status_atipicos
)
df_resumen %>%
gt() %>%
tab_header(title = md("**CONCLUSIONES Y ESTADÍSTICOS**"), subtitle = "Variable: tvd_m") %>%
cols_label(
X = "X",
Me = "Me",
Mo = "Mo",
sd = "sd",
CV = "CV",
As = "As",
K = "K",
Atipicos = "Valores atípicos"
) %>%
fmt_number(columns = c(X, Me, Varianza, sd, CV, K), decimals = 2) %>%
fmt_number(columns = As, decimals = 4) %>%
cols_width(
Variable ~ px(140),
Rango ~ px(120),
Mo ~ px(100),
Atipicos ~ px(220),
everything() ~ px(85)
) %>%
tab_options(
column_labels.background.color = "#2E4053",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
heading.border.bottom.style = "solid",
column_labels.border.top.style = "solid",
column_labels.border.bottom.style = "solid",
data_row.padding = px(8)
) %>%
tab_style(
style = list(
cell_text(weight = "bold", color = "white"),
cell_borders(sides = c("left", "right"), color = "#D3D3D3", weight = px(1))
),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_borders(sides = c("left", "right"), color = "#D3D3D3", weight = px(1)),
locations = cells_body()
)
| CONCLUSIONES Y ESTADÍSTICOS | ||||||||||
| Variable: tvd_m | ||||||||||
| Variable | Rango | X | Me | Mo | Varianza | sd | CV | As | K | Valores atípicos |
|---|---|---|---|---|---|---|---|---|---|---|
| tvd_m | [0 ; 6930] | 885.92 | 68.43 | 200 | 1,753,092.23 | 1,324.04 | 149.45 | 1.7632 | 2.74 | 322 [ 3259 ; 6930] |
Los valores de tvd_m fluctúan entre 0 y 6930 y giran en torno a 68.43, con una desviación estándar de 1324.04, con 322 valores atípicos en el rango de 3259 a 6930, siendo un conjunto de datos heterogéneo, cuyos valores se agrupan fuertemente en la parte baja de tvd_m. Por lo anterior, el comportamiento es perjudicial, ya que una concentración masiva de pozos en profundidades muy bajas limita el potencial de producción a gran escala y reduce la rentabilidad operativa de la empresa perforadora.