# Librerías necesarias
library(dplyr)
library(gt)
library(e1071)
# Paleta de colores del informe
col_principal <- "#0E6655"
col_barras <- "#16A085"
col_acento <- "#E67E22"
col_claro <- "#E8F8F5"
col_grid <- "#D7DBDD"
# --- Carga de datos ---
# El dataset está separado por ";" y usa codificación Latin-1 (según el archivo
# "Oil_Gas_Other_Regulated_Wells_Beginning_1860" descargado del NYS DEC).
# Ajusta la ruta según la ubicación del archivo en tu equipo.
ruta_csv <- "C:/Users/PATRICIA/Desktop/pr-estadistica/Oil__Gas____Other_Regulated_Wells__Beginning_1860 (3).csv"
Datos <- read.csv(ruta_csv,
header = TRUE,
sep = ";",
dec = ".",
fileEncoding = "Latin1",
stringsAsFactors = FALSE)
cat("Dimensiones del dataset:", nrow(Datos), "filas x", ncol(Datos), "columnas\n")
## Dimensiones del dataset: 47407 filas x 55 columnas
# Localizamos la columna de Profundidad Vertical Real de forma robusta (el nombre
# puede llegar alterado por R como "True.Vertical.Depth..ft" al leer "True Vertical Depth, ft")
col_prof <- grep("True.Vertical.Depth", names(Datos), value = TRUE)[1]
if (is.na(col_prof)) stop("ERROR: No se encontró la columna de Profundidad Vertical Real en el dataset.")
# Extracción y conversión a numérico
Variable <- suppressWarnings(as.numeric(Datos[[col_prof]]))
# Limpieza: se eliminan NA y valores 0 o sin dato registrado
Variable <- na.omit(Variable)
Variable <- Variable[Variable > 0]
if (length(Variable) == 0) stop("ERROR: No hay datos válidos de Profundidad Vertical Real tras la limpieza.")
cat("Columna detectada:", col_prof, "\n")
## Columna detectada: True.Vertical.Depth..ft
cat("N° de pozos con profundidad vertical real válida:", length(Variable), "\n")
## N° de pozos con profundidad vertical real válida: 32707
N <- length(Variable)
min_val <- min(Variable)
max_val <- max(Variable)
Rango <- max_val - min_val
K <- floor(1 + 3.322 * log10(N)) # N° de clases (Regla de Sturges)
Amplitud <- Rango / K
ficha <- data.frame(
Característica = c("Nombre de la variable", "Tipo de variable", "Unidad de medida",
"Población de referencia", "Tamaño de muestra (N)",
"Valor mínimo", "Valor máximo", "Rango",
"N° de clases (Sturges)", "Amplitud de clase"),
Valor = c("Profundidad vertical real (True Vertical Depth)", "Cuantitativa continua", "Pies (ft)",
"Pozos de petróleo y gas de Nueva York con profundidad vertical real registrada",
as.character(N), round(min_val, 1), round(max_val, 1),
round(Rango, 1), as.character(K), round(Amplitud, 1))
)
ficha %>%
gt() %>%
tab_header(title = md("**FICHA TÉCNICA DE LA VARIABLE**")) %>%
cols_align(align = "left", columns = everything()) %>%
tab_style(style = list(cell_fill(color = col_principal), cell_text(color = "white", weight = "bold")),
locations = cells_title()) %>%
tab_style(style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_labels()) %>%
opt_row_striping() %>%
tab_options(table.font.size = px(13), heading.align = "left")
| FICHA TÉCNICA DE LA VARIABLE | |
| Característica | Valor |
|---|---|
| Nombre de la variable | Profundidad vertical real (True Vertical Depth) |
| Tipo de variable | Cuantitativa continua |
| Unidad de medida | Pies (ft) |
| Población de referencia | Pozos de petróleo y gas de Nueva York con profundidad vertical real registrada |
| Tamaño de muestra (N) | 32707 |
| Valor mínimo | 1 |
| Valor máximo | 11953 |
| Rango | 11952 |
| N° de clases (Sturges) | 15 |
| Amplitud de clase | 796.8 |
La profundidad vertical real (True Vertical Depth) es la distancia vertical real desde la superficie hasta el fondo del pozo, medida en pies (ft). A diferencia de la profundidad medida (que sigue la trayectoria completa, incluyendo curvas en pozos direccionales), esta variable representa únicamente la componente vertical. Se excluyen del análisis los pozos con profundidad 0 o sin dato registrado.
breaks_table <- seq(min_val, max_val, length.out = K + 1)
breaks_table[length(breaks_table)] <- max_val + 0.0001
lim_inf_table <- breaks_table[1:K]
lim_sup_table <- breaks_table[2:(K + 1)]
MC <- (lim_inf_table + lim_sup_table) / 2
ni <- numeric(K)
for (i in 1:K) {
if (i < K) {
ni[i] <- length(Variable[Variable >= lim_inf_table[i] & Variable < lim_sup_table[i]])
} else {
ni[i] <- length(Variable[Variable >= lim_inf_table[i] & Variable <= lim_sup_table[i]])
}
}
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_Prof <- data.frame(
Li = round(lim_inf_table, 1),
Ls = round(lim_sup_table, 1),
MC = round(MC, 1),
ni = ni,
hi = round(hi, 2),
Ni_asc = Ni_asc,
Ni_desc = Ni_desc,
Hi_asc = round(Hi_asc, 2),
Hi_desc = round(Hi_desc, 2)
)
# Fila de totales
totales <- c("TOTAL", "-", "-", sum(ni), round(sum(hi), 2), "-", "-", "-", "-")
TDF_Char <- TDF_Prof %>% mutate(across(everything(), as.character))
TDF_Final <- rbind(TDF_Char, totales)
modal_row <- which.max(TDF_Prof$ni)
TDF_Final %>%
gt() %>%
tab_header(
title = md("**DISTRIBUCIÓN DE FRECUENCIAS — PROFUNDIDAD VERTICAL REAL**"),
subtitle = md("Variable: **Profundidad vertical real del pozo (ft)**")
) %>%
tab_spanner(label = "Frecuencias acumuladas",
columns = c(Ni_asc, Ni_desc, Hi_asc, Hi_desc)) %>%
cols_label(
Li = "Lím. Inf", Ls = "Lím. Sup", MC = "Marca de clase (Xi)",
ni = "ni", hi = "hi (%)",
Ni_asc = "Ni (Asc)", Ni_desc = "Ni (Desc)",
Hi_asc = "Hi (Asc)", Hi_desc = "Hi (Desc)"
) %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(style = list(cell_fill(color = col_principal), cell_text(color = "white", weight = "bold")),
locations = cells_title()) %>%
tab_style(style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_labels()) %>%
tab_style(style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_spanners()) %>%
tab_style(style = list(cell_fill(color = "#FDEBD0"), cell_text(weight = "bold")),
locations = cells_body(rows = modal_row)) %>%
tab_style(style = list(cell_fill(color = "#D0ECE7"), cell_text(weight = "bold")),
locations = cells_body(rows = nrow(TDF_Final))) %>%
opt_row_striping() %>%
tab_options(
table.font.size = px(13),
heading.align = "left",
heading.title.font.size = px(17),
data_row.padding = px(7),
table.border.top.color = col_principal,
table.border.bottom.color = col_principal,
column_labels.border.bottom.color = col_principal
) %>%
tab_source_note(md("*Fuente: NYS DEC — Oil, Gas & Other Regulated Wells. Elaboración: JENNY.*"))
| DISTRIBUCIÓN DE FRECUENCIAS — PROFUNDIDAD VERTICAL REAL | ||||||||
| Variable: Profundidad vertical real del pozo (ft) | ||||||||
| Lím. Inf | Lím. Sup | Marca de clase (Xi) | ni | hi (%) |
Frecuencias acumuladas
|
|||
|---|---|---|---|---|---|---|---|---|
| Ni (Asc) | Ni (Desc) | Hi (Asc) | Hi (Desc) | |||||
| 1 | 797.8 | 399.4 | 2120 | 6.48 | 2120 | 32707 | 6.48 | 100 |
| 797.8 | 1594.6 | 1196.2 | 14010 | 42.83 | 16130 | 30587 | 49.32 | 93.52 |
| 1594.6 | 2391.4 | 1993 | 7690 | 23.51 | 23820 | 16577 | 72.83 | 50.68 |
| 2391.4 | 3188.2 | 2789.8 | 2840 | 8.68 | 26660 | 8887 | 81.51 | 27.17 |
| 3188.2 | 3985 | 3586.6 | 2767 | 8.46 | 29427 | 6047 | 89.97 | 18.49 |
| 3985 | 4781.8 | 4383.4 | 2256 | 6.9 | 31683 | 3280 | 96.87 | 10.03 |
| 4781.8 | 5578.6 | 5180.2 | 467 | 1.43 | 32150 | 1024 | 98.3 | 3.13 |
| 5578.6 | 6375.4 | 5977 | 110 | 0.34 | 32260 | 557 | 98.63 | 1.7 |
| 6375.4 | 7172.2 | 6773.8 | 79 | 0.24 | 32339 | 447 | 98.87 | 1.37 |
| 7172.2 | 7969 | 7570.6 | 81 | 0.25 | 32420 | 368 | 99.12 | 1.13 |
| 7969 | 8765.8 | 8367.4 | 34 | 0.1 | 32454 | 287 | 99.23 | 0.88 |
| 8765.8 | 9562.6 | 9164.2 | 84 | 0.26 | 32538 | 253 | 99.48 | 0.77 |
| 9562.6 | 10359.4 | 9961 | 99 | 0.3 | 32637 | 169 | 99.79 | 0.52 |
| 10359.4 | 11156.2 | 10757.8 | 40 | 0.12 | 32677 | 70 | 99.91 | 0.21 |
| 11156.2 | 11953 | 11554.6 | 30 | 0.09 | 32707 | 30 | 100 | 0.09 |
| TOTAL | - | - | 32707 | 100 | - | - | - | - |
| Fuente: NYS DEC — Oil, Gas & Other Regulated Wells. Elaboración: JENNY. | ||||||||
h_base <- hist(Variable, breaks = "Sturges", plot = FALSE)
# Marcas "redondas" del eje Y que abarcan holgadamente la barra más alta,
# para que ninguna barra sobresalga por encima de la última línea de la grilla
y_ticks_freq <- pretty(c(0, h_base$counts), n = 6)
y_top_freq <- max(y_ticks_freq)
# Margen izquierdo ampliado (7) para que los números del eje (p. ej. "20,000")
# no se superpongan con el título del eje Y
par(mar = c(8, 7, 5, 2))
plot(h_base,
main = "Gráfica N°1: Distribución de la profundidad vertical real de los pozos (NY)",
xlab = "Profundidad vertical real (ft)", ylab = "",
col = col_barras, border = "white", axes = FALSE,
xlim = range(h_base$breaks), xaxs = "i",
ylim = c(0, y_top_freq), yaxs = "i")
axis(1, at = round(h_base$breaks), labels = format(round(h_base$breaks), big.mark = ","),
las = 2, cex.axis = 0.7)
axis(2, at = y_ticks_freq, labels = format(y_ticks_freq, big.mark = ","),
las = 1, cex.axis = 0.8)
# Título del eje Y separado de los números (line = 5) para evitar el choque
mtext("Frecuencia absoluta (n° de pozos)", side = 2, line = 5, cex = 0.9)
grid(nx = NA, ny = NULL, col = col_grid, lty = "dotted")
box(bty = "l", col = "black")
h_porc <- h_base
h_porc$counts <- (h_porc$counts / sum(h_porc$counts)) * 100
h_porc$density <- h_porc$counts
# Se deja espacio extra arriba (además de la etiqueta "%") para que ni la
# barra ni su etiqueta de texto sobresalgan del área del gráfico
y_ticks_porc <- pretty(c(0, h_porc$counts), n = 6)
y_max <- max(y_ticks_porc) + (y_ticks_porc[2] - y_ticks_porc[1]) * 0.4
# Margen izquierdo ampliado (7) para que los números del eje no choquen
# con el título del eje Y
par(mar = c(8, 7, 5, 2))
plot(h_porc,
main = "Gráfica N°2: Distribución porcentual de la profundidad vertical real",
xlab = "Profundidad vertical real (ft)", ylab = "",
col = col_barras, border = "white", axes = FALSE,
xlim = range(h_base$breaks), xaxs = "i",
ylim = c(0, y_max), yaxs = "i")
axis(1, at = round(h_base$breaks), labels = format(round(h_base$breaks), big.mark = ","),
las = 2, cex.axis = 0.7)
axis(2, at = y_ticks_porc, las = 1, cex.axis = 0.8)
mtext("Porcentaje de pozos (%)", side = 2, line = 5, cex = 0.9)
text(x = h_base$mids, y = h_porc$counts, labels = paste0(round(h_porc$counts, 1), "%"),
pos = 3, cex = 0.6, col = col_principal)
grid(nx = NA, ny = NULL, col = col_grid, lty = "dotted")
box(bty = "l", col = "black")
par(mar = c(7, 5, 4, 2))
boxplot(Variable, horizontal = TRUE, col = col_barras,
main = "Gráfica N°3: Diagrama de caja de la profundidad vertical real",
xlab = "", outline = TRUE, axes = FALSE,
outcol = col_acento, boxwex = 0.5, frame.plot = FALSE)
eje_x <- pretty(Variable, n = 8)
axis(1, at = eje_x, labels = format(eje_x, scientific = FALSE, big.mark = ","),
las = 2, cex.axis = 0.8)
mtext("Profundidad vertical real (ft)", side = 1, line = 5.5)
grid(nx = NULL, ny = NA, col = col_grid, lty = "dotted")
par(mar = c(5, 5, 4, 8), xpd = TRUE)
x_ac <- breaks_table
y_asc <- c(0, Ni_asc)
y_des <- c(Ni_desc, 0)
x_range <- range(x_ac)
y_range <- c(0, max(c(y_asc, y_des)))
plot(x_ac, y_asc, type = "o", col = col_principal, lwd = 2, pch = 16,
main = "Gráfica N°4: Ojivas de la profundidad vertical real",
xlab = "Profundidad vertical real (ft)", ylab = "Frecuencia acumulada (n° de pozos)",
xlim = x_range, ylim = y_range, axes = FALSE, frame.plot = FALSE)
axis(1, at = round(breaks_table), labels = format(round(breaks_table), big.mark = ","),
las = 2, cex.axis = 0.6)
axis(2, at = pretty(y_asc), labels = format(pretty(y_asc), big.mark = ","))
lines(x_ac, y_des, type = "o", col = col_acento, lwd = 2, pch = 16)
legend("right", legend = c("Ascendente (Ni↑)", "Descendente (Ni↓)"),
col = c(col_principal, col_acento), lty = 1, pch = 16,
inset = c(-0.18, 0), bty = "n")
grid(col = col_grid, lty = "dotted")
media_val <- mean(Variable)
mediana_val <- median(Variable)
freq_max <- max(TDF_Prof$ni)
modas_calc <- TDF_Prof$MC[TDF_Prof$ni == freq_max]
moda_txt <- paste(round(modas_calc, 1), collapse = " ; ")
rango_txt <- paste0("[", round(min_val, 1), " ; ", round(max_val, 1), "]")
varianza_val <- var(Variable)
sd_val <- sd(Variable)
cv_val <- (sd_val / abs(media_val)) * 100
asimetria_val <- skewness(Variable, type = 2)
curtosis_val <- kurtosis(Variable, type = 2)
vals_atipicos <- boxplot.stats(Variable)$out
num_atipicos <- length(vals_atipicos)
status_atipicos <- if (num_atipicos > 0) {
paste0(num_atipicos, " [", round(min(vals_atipicos), 1), " ; ", round(max(vals_atipicos), 1), "]")
} else {
"0 (Sin atípicos)"
}
df_resumen <- data.frame(
"Variable" = "Profundidad vertical real (ft)",
"Rango" = rango_txt,
"Media" = media_val,
"Mediana" = mediana_val,
"Moda" = moda_txt,
"Varianza" = varianza_val,
"Desv_Std" = sd_val,
"CV_Porc" = cv_val,
"Asimetria" = asimetria_val,
"Curtosis" = curtosis_val,
"Atipicos" = status_atipicos,
check.names = FALSE
)
df_resumen %>%
gt() %>%
tab_header(
title = md("**RESUMEN ESTADÍSTICO Y MEDIDAS DESCRIPTIVAS**"),
subtitle = "Indicadores de la profundidad vertical real de los pozos (ft) — Nueva York"
) %>%
tab_source_note(source_note = "Autor: JENNY") %>%
fmt_number(columns = c(Media, Mediana, Varianza, Desv_Std, CV_Porc), decimals = 2) %>%
fmt_number(columns = c(Asimetria, Curtosis), decimals = 4) %>%
cols_label(
Variable = "Variable", Rango = "Rango Total",
Media = "Media (X)", Mediana = "Mediana (Me)", Moda = "Moda (Mo)",
Varianza = "Varianza (S2)", Desv_Std = "Desv. Est. (S)", CV_Porc = "C.V. (%)",
Asimetria = "Asimetría (As)", Curtosis = "Curtosis", Atipicos = "Atípicos"
) %>%
cols_align(align = "center", columns = everything()) %>%
tab_style(style = list(cell_fill(color = col_principal), cell_text(color = "white", weight = "bold")),
locations = cells_title()) %>%
tab_style(style = list(cell_fill(color = "#148F77"), cell_text(color = "white", weight = "bold")),
locations = cells_column_labels()) %>%
tab_options(
table.font.size = px(13),
heading.align = "left",
data_row.padding = px(9),
table.border.top.color = col_principal,
table.border.bottom.color = col_principal,
column_labels.border.bottom.color = col_principal
)
| RESUMEN ESTADÍSTICO Y MEDIDAS DESCRIPTIVAS | ||||||||||
| Indicadores de la profundidad vertical real de los pozos (ft) — Nueva York | ||||||||||
| Variable | Rango Total | Media (X) | Mediana (Me) | Moda (Mo) | Varianza (S2) | Desv. Est. (S) | C.V. (%) | Asimetría (As) | Curtosis | Atípicos |
|---|---|---|---|---|---|---|---|---|---|---|
| Profundidad vertical real (ft) | [1 ; 11953] | 2,070.35 | 1,603.00 | 1196.2 | 1,899,200.03 | 1,378.11 | 66.56 | 2.3417 | 8.8188 | 1460 [4503 ; 11953] |
| Autor: JENNY | ||||||||||
La variable Profundidad vertical real fluctúa entre 1 y 11953 pies, y sus valores se concentran alrededor de 2070.4 ft (mediana ≈ 1603 ft). Presenta una desviación estándar de 1378.1 ft, siendo una variable heterogénea (C.V. = 66.56%).
La distribución es asimétrica positiva (sesgo hacia la derecha) (As = 2.3417) y leptocúrtica (más apuntada que la normal) (Curtosis = 8.8188). Se identificaron 1460 valores atípicos en el conjunto de datos.
De un total de 47407 pozos registrados en la base original, 32707 pozos presentan un dato de profundidad vertical real válido (> 0), lo cual permite caracterizar la distancia vertical real alcanzada por la perforación de los pozos en Nueva York.