1 Configuración y Carga de Datos

datos_originales <- readr::read_delim(
  ruta, delim=delimitador, trim_ws=TRUE, show_col_types=FALSE,
  name_repair="minimal", col_types=readr::cols(.default=readr::col_character())
)
## Carga exitosa: 47.501 registros y 56 variables.

2 Extracción y Limpieza de la Variable

valores_txt <- stringr::str_squish(as.character(datos_originales[[columna_dd]]))
valores_txt[toupper(valores_txt) %in% c("", "NA", "N/A", "NULL")] <- NA
valores_limpios <- gsub(",", "", valores_txt)
Variable <- suppressWarnings(as.numeric(valores_limpios))

n_total   <- length(Variable)
n_nulos   <- sum(is.na(Variable))
Variable  <- Variable[!is.na(Variable)]
N <- length(Variable)
n_ceros <- sum(Variable == 0)
if (N == 0L) stop("No hay registros válidos de Drilled Depth.")

Minimo_real <- min(Variable)
Maximo_real <- max(Variable)

cat("Variable analizada: Drilled Depth, ft | Unidad: pies (ft)\n")
## Variable analizada: Drilled Depth, ft | Unidad: pies (ft)
cat("Observaciones útiles (N):", fmt_entero(N), "| Nulos omitidos:", fmt_entero(n_nulos), "| Valores en 0:", fmt_entero(n_ceros), "\n")
## Observaciones útiles (N): 47.496 | Nulos omitidos: 5 | Valores en 0: 14.639
cat("Mínimo:", fmt_num(Minimo_real, 0), "| Máximo:", fmt_num(Maximo_real, 0), "pies\n")
## Mínimo: 0 | Máximo: 15795 pies

3 Identificación de la Variable

Escala: la profundidad perforada es cuantitativa continua de escala de razón (el 0 ft indica ausencia de profundidad). El conjunto incluye 14.639 pozos con valor 0 ft (30.82%), que se mantienen en el análisis.

VARIABLE TIPO ESCALA DE MEDICIÓN UNIDAD DE MEDIDA UNIDAD DE ANÁLISIS REGISTROS VÁLIDOS (N)
DRILLED DEPTH (Profundidad perforada, ft) Cuantitativa continua Razón Pies (ft) Pozo regulado 47.496

4 Tabla de Distribución de Frecuencias

4.1 Tabla con Límites Decimales (Regla de Sturges)

R_sturges        <- Maximo_real - Minimo_real
k_sturges        <- ceiling(1 + 3.322 * log10(N))
Amplitud_sturges <- R_sturges / k_sturges

cortes_sturges <- Minimo_real + (0:k_sturges) * Amplitud_sturges
cortes_sturges[k_sturges + 1] <- Maximo_real     # evita errores de redondeo en el extremo

Li_sturges <- cortes_sturges[1:k_sturges]
Ls_sturges <- cortes_sturges[2:(k_sturges + 1)]
MC_sturges <- (Li_sturges + Ls_sturges) / 2

inter_sturges <- cut(Variable, breaks=cortes_sturges, include.lowest=TRUE, right=FALSE)
ni_sturges    <- as.vector(table(inter_sturges))
hi_sturges    <- ni_sturges / N

TDF_Sturges <- data.frame(Li=Li_sturges, Ls=Ls_sturges, MC=MC_sturges,
                          ni=ni_sturges, hi=hi_sturges, hi_perc=hi_sturges * 100)
stopifnot(sum(TDF_Sturges$ni) == N)

cat("Número de intervalos (k):", k_sturges, "\n")
## Número de intervalos (k): 17
cat("Amplitud exacta de clase:", round(Amplitud_sturges, 4), "\n")
## Amplitud exacta de clase: 929.1176
tabla_sturges <- data.frame(
  "LÍM. INF (ft)"=fmt_num(TDF_Sturges$Li, 3),
  "LÍM. SUP (ft)"=fmt_num(TDF_Sturges$Ls, 3),
  "MARCA DE CLASE (xᵢ)"=fmt_num(TDF_Sturges$MC, 3),
  "FRECUENCIA ABSOLUTA (nᵢ)"=fmt_entero(TDF_Sturges$ni),
  "FRECUENCIA RELATIVA (hᵢ)"=sprintf("%.4f", TDF_Sturges$hi),
  "FRECUENCIA RELATIVA PORCENTUAL (%)"=sprintf("%.2f%%", TDF_Sturges$hi_perc),
  check.names=FALSE
)
tabla_sturges <- rbind(tabla_sturges, data.frame(
  "LÍM. INF (ft)"="TOTAL", "LÍM. SUP (ft)"="", "MARCA DE CLASE (xᵢ)"="",
  "FRECUENCIA ABSOLUTA (nᵢ)"=fmt_entero(sum(TDF_Sturges$ni)),
  "FRECUENCIA RELATIVA (hᵢ)"="1.0000", "FRECUENCIA RELATIVA PORCENTUAL (%)"="100.00%",
  check.names=FALSE
))
cat(crear_cuadro(tabla_sturges, 1,
  paste0("Distribución de frecuencias de la profundidad perforada (ft) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = ", k_sturges, ")"),
  align=c("c","c","c","r","r","r")))
Cuadro N° 1: Distribución de frecuencias de la profundidad perforada (ft) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = 17)
LÍM. INF (ft) LÍM. SUP (ft) MARCA DE CLASE (xᵢ) FRECUENCIA ABSOLUTA (nᵢ) FRECUENCIA RELATIVA (hᵢ) FRECUENCIA RELATIVA PORCENTUAL (%)
0.000 929.118 464.559 18.002 0.3790 37.90%
929.118 1858.235 1393.676 16.700 0.3516 35.16%
1858.235 2787.353 2322.794 5.751 0.1211 12.11%
2787.353 3716.471 3251.912 2.982 0.0628 6.28%
3716.471 4645.588 4181.029 3.039 0.0640 6.40%
4645.588 5574.706 5110.147 672 0.0141 1.41%
5574.706 6503.824 6039.265 103 0.0022 0.22%
6503.824 7432.941 6968.382 86 0.0018 0.18%
7432.941 8362.059 7897.500 59 0.0012 0.12%
8362.059 9291.176 8826.618 22 0.0005 0.05%
9291.176 10220.294 9755.735 39 0.0008 0.08%
10220.294 11149.412 10684.853 26 0.0005 0.05%
11149.412 12078.529 11613.971 11 0.0002 0.02%
12078.529 13007.647 12543.088 2 0.0000 0.00%
13007.647 13936.765 13472.206 0 0.0000 0.00%
13936.765 14865.882 14401.324 1 0.0000 0.00%
14865.882 15795.000 15330.441 1 0.0000 0.00%
TOTAL 47.496 1.0000 100.00%

Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.

4.2 Justificación del ajuste

Los límites exactos de Sturges (Cuadro N° 1) son poco prácticos, por lo que se redondean a múltiplos de 10 manteniendo el mismo número de clases (k).

4.3 Tabla con Límites Enteros

BASE         <- 10
min_int      <- floor(Minimo_real / BASE) * BASE
max_int      <- ceiling(Maximo_real / BASE) * BASE
k_int_sug    <- k_sturges            # se mantiene el mismo k obtenido en el paso 1 (Sturges)

Rango_int    <- max_int - min_int
Amplitud_int <- ceiling((Rango_int / k_int_sug) / BASE) * BASE
if (Amplitud_int == 0) Amplitud_int <- BASE

cortes_int <- seq(from=min_int, by=Amplitud_int, length.out=k_int_sug + 1)
if (max(cortes_int) < Maximo_real) cortes_int <- c(cortes_int, max(cortes_int) + Amplitud_int)
while (length(cortes_int) > 2 && cortes_int[length(cortes_int) - 1] >= Maximo_real) {
  cortes_int <- cortes_int[-length(cortes_int)]
}
K_real <- length(cortes_int) - 1

inter_int <- cut(Variable, breaks=cortes_int, include.lowest=TRUE, right=FALSE)
ni_int    <- as.vector(table(inter_int))

hi_int_unit <- ni_int / N
hi_int_perc <- hi_int_unit * 100

TDF_Enteros <- data.frame(
  Li = cortes_int[1:K_real],
  Ls = cortes_int[2:(K_real + 1)],
  MC = (cortes_int[1:K_real] + cortes_int[2:(K_real + 1)]) / 2,
  ni = ni_int,
  hi_unit = hi_int_unit,
  hi_perc = hi_int_perc,
  Ni_asc  = cumsum(ni_int),
  Ni_desc = rev(cumsum(rev(ni_int))),
  Hi_asc_perc  = cumsum(hi_int_perc),
  Hi_desc_perc = rev(cumsum(rev(hi_int_perc)))
)
stopifnot(sum(TDF_Enteros$ni) == N)

cat("Clases ajustadas (k), consistentes con Sturges:", K_real, "\n")
## Clases ajustadas (k), consistentes con Sturges: 17
cat("Amplitud ajustada:", Amplitud_int, "pies\n")
## Amplitud ajustada: 930 pies
tabla_final <- data.frame(
  "LÍM. INF (ft)"=fmt_num(TDF_Enteros$Li, 0),
  "LÍM. SUP (ft)"=fmt_num(TDF_Enteros$Ls, 0),
  "MARCA DE CLASE (xᵢ)"=fmt_num(TDF_Enteros$MC, 1),
  "nᵢ"=fmt_entero(TDF_Enteros$ni),
  "hᵢ"=sprintf("%.4f", TDF_Enteros$hi_unit),
  "hᵢ (%)"=sprintf("%.2f", TDF_Enteros$hi_perc),
  "Nᵢ (↑)"=fmt_entero(TDF_Enteros$Ni_asc),
  "Nᵢ (↓)"=fmt_entero(TDF_Enteros$Ni_desc),
  "Hᵢ (% ↑)"=sprintf("%.2f", TDF_Enteros$Hi_asc_perc),
  "Hᵢ (% ↓)"=sprintf("%.2f", TDF_Enteros$Hi_desc_perc),
  check.names=FALSE
)
tabla_final <- rbind(tabla_final, data.frame(
  "LÍM. INF (ft)"="TOTAL", "LÍM. SUP (ft)"="", "MARCA DE CLASE (xᵢ)"="",
  "nᵢ"=fmt_entero(sum(TDF_Enteros$ni)), "hᵢ"="1.0000", "hᵢ (%)"="100.00",
  "Nᵢ (↑)"="", "Nᵢ (↓)"="", "Hᵢ (% ↑)"="", "Hᵢ (% ↓)"="", check.names=FALSE
))
cat(crear_cuadro(tabla_final, 2,
  "Distribución de frecuencias de los pozos regulados según la profundidad perforada (ft), límites enteros, Nueva York, 1860 - 2026",
  desplazamiento=(K_real > 15L), align=c("c","c","c",rep("r",7))))
Cuadro N° 2: Distribución de frecuencias de los pozos regulados según la profundidad perforada (ft), límites enteros, Nueva York, 1860 - 2026
LÍM. INF (ft) LÍM. SUP (ft) MARCA DE CLASE (xᵢ) nᵢ hᵢ hᵢ (%) Nᵢ (↑) Nᵢ (↓) Hᵢ (% ↑) Hᵢ (% ↓)
0 930 465.0 18.002 0.3790 37.90 18.002 47.496 37.90 100.00
930 1860 1395.0 16.708 0.3518 35.18 34.710 29.494 73.08 62.10
1860 2790 2325.0 5.748 0.1210 12.10 40.458 12.786 85.18 26.92
2790 3720 3255.0 2.984 0.0628 6.28 43.442 7.038 91.46 14.82
3720 4650 4185.0 3.040 0.0640 6.40 46.482 4.054 97.87 8.54
4650 5580 5115.0 664 0.0140 1.40 47.146 1.014 99.26 2.13
5580 6510 6045.0 105 0.0022 0.22 47.251 350 99.48 0.74
6510 7440 6975.0 84 0.0018 0.18 47.335 245 99.66 0.52
7440 8370 7905.0 59 0.0012 0.12 47.394 161 99.79 0.34
8370 9300 8835.0 22 0.0005 0.05 47.416 102 99.83 0.21
9300 10230 9765.0 39 0.0008 0.08 47.455 80 99.91 0.17
10230 11160 10695.0 26 0.0005 0.05 47.481 41 99.97 0.09
11160 12090 11625.0 11 0.0002 0.02 47.492 15 99.99 0.03
12090 13020 12555.0 2 0.0000 0.00 47.494 4 100.00 0.01
13020 13950 13485.0 0 0.0000 0.00 47.494 2 100.00 0.00
13950 14880 14415.0 1 0.0000 0.00 47.495 2 100.00 0.00
14880 15810 15345.0 1 0.0000 0.00 47.496 1 100.00 0.00
TOTAL 47.496 1.0000 100.00

Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.

Interpretación: el intervalo de profundidad con mayor concentración de pozos es [0 – 930) pies, con 18.002 pozos (37.90% de los 47.496 registros válidos). Hasta los 1860 pies se acumula al menos el 50 % de los pozos.

5 Representación Gráfica

5.1 Gráfica N° 1 — Frecuencia absoluta (nᵢ) local

ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=ni, fill=intervalo)) +
  ggplot2::geom_col(width=.72, color="#244861", linewidth=.36) +
  ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)), vjust=-.48,
                     size=4.5, fontface="bold", color="#15364C") +
  ggplot2::scale_fill_manual(values=colores) +
  ggplot2::scale_y_continuous(limits=c(0, limite_ni_local), labels=fmt_entero,
                              expand=ggplot2::expansion(mult=c(0,0))) +
  ggplot2::coord_cartesian(clip="off") +
  ggplot2::labs(title="Gráfica N° 1: Frecuencia absoluta (nᵢ) local",
                x="Profundidad perforada (ft)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
  tema_barras

5.2 Gráfica N° 2 — Frecuencia absoluta (nᵢ) global

ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=ni)) +
  ggplot2::geom_col(fill=color_barras, color="#244861", width=.72, linewidth=.36) +
  ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)), vjust=-.48,
                     size=4.5, fontface="bold", color="#15364C") +
  ggplot2::scale_y_continuous(limits=c(0, limite_ni_global), labels=fmt_entero,
                              expand=ggplot2::expansion(mult=c(0,0))) +
  ggplot2::coord_cartesian(clip="off") +
  ggplot2::labs(title="Gráfica N° 2: Frecuencia absoluta (nᵢ) global",
                x="Profundidad perforada (ft)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
  tema_barras

5.3 Gráfica N° 3 — Frecuencia relativa (hᵢ) local

ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=hi_unit, fill=intervalo)) +
  ggplot2::geom_col(width=.72, color="#244861", linewidth=.36) +
  ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%", hi_perc)), vjust=-.48,
                     size=4.3, fontface="bold", color="#15364C") +
  ggplot2::scale_fill_manual(values=colores) +
  ggplot2::scale_y_continuous(limits=c(0, limite_hi_local), labels=etiqueta_pct,
                              expand=ggplot2::expansion(mult=c(0,0))) +
  ggplot2::coord_cartesian(clip="off") +
  ggplot2::labs(title="Gráfica N° 3: Frecuencia relativa (hᵢ) local",
                x="Profundidad perforada (ft)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
  tema_barras

5.4 Gráfica N° 4 — Frecuencia relativa (hᵢ) global

ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=hi_unit)) +
  ggplot2::geom_col(fill=color_barras, color="#244861", width=.72, linewidth=.36) +
  ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%", hi_perc)), vjust=-.48,
                     size=4.3, fontface="bold", color="#15364C") +
  ggplot2::scale_y_continuous(limits=c(0, limite_hi_global), breaks=seq(0, 1, by=.2),
                              labels=etiqueta_pct, expand=ggplot2::expansion(mult=c(0,0))) +
  ggplot2::coord_cartesian(clip="off") +
  ggplot2::labs(title="Gráfica N° 4: Frecuencia relativa (hᵢ) global",
                x="Profundidad perforada (ft)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
  tema_barras

5.5 Gráfica N° 5 — Diagrama de caja

col_grid <- "#DDE6ED"
eje_x <- pretty(Variable, n=8)
par(mar=c(7, 5, 4, 2))
plot(NULL, xlim=range(eje_x), ylim=c(0.4, 1.6), axes=FALSE, xlab="", ylab="",
     main="Gráfica N° 5: Diagrama de caja de la profundidad perforada")
abline(v=eje_x, col=col_grid, lty="dotted")                    # cuadrícula detrás de la caja
boxplot(Variable, horizontal=TRUE, at=1, add=TRUE, axes=FALSE, col=color_barras,
        border="#15364C", medlwd=3, outline=TRUE, outcol=color_outlier,
        boxwex=0.5, frame.plot=FALSE)
axis(1, at=eje_x, labels=fmt_entero(eje_x), las=2, cex.axis=0.9)
mtext("Profundidad perforada (ft)", side=1, line=5.5)

5.6 Gráfica N° 6 — Ojivas

ojiva_df <- data.frame(
  x    = c(TDF_Enteros$Ls, TDF_Enteros$Li),
  y    = c(TDF_Enteros$Hi_asc_perc, TDF_Enteros$Hi_desc_perc),
  tipo = rep(c("Ascendente", "Descendente"), each=K_real)
)

ggplot2::ggplot(ojiva_df, ggplot2::aes(x=x, y=y, color=tipo, group=tipo)) +
  ggplot2::geom_line(linewidth=1.2) +
  ggplot2::geom_point(size=2.8) +
  ggplot2::scale_color_manual(values=c(Ascendente=color_ojiva1, Descendente=color_ojiva2)) +
  ggplot2::scale_x_continuous(labels=fmt_entero) +
  ggplot2::scale_y_continuous(labels=function(x) paste0(x, "%"), limits=c(0, 105),
                              expand=ggplot2::expansion(mult=c(0, 0))) +
  ggplot2::labs(title="Gráfica N° 6: Ojivas ascendente y descendente",
                x="Profundidad perforada (ft)", y="Frecuencia acumulada (%)", color=NULL,
                caption=fuente_graficas) +
  tema_barras +
  ggplot2::theme(legend.position="bottom",
                 legend.text=ggplot2::element_text(size=13),
                 axis.text.x=ggplot2::element_text(angle=0, hjust=.5),
                 panel.grid.major.x=ggplot2::element_line(color="#DDE6ED", linewidth=.35))

6 Tabla de Indicadores

Profundidad perforada es cuantitativa continua de escala de razón (sección 3): se calculan tendencia central, dispersión, forma y valores atípicos.

media    <- mean(Variable)
mediana  <- median(Variable)
moda_val <- TDF_Enteros$MC[which.max(TDF_Enteros$ni)]   # marca de clase de la clase modal
varianza <- var(Variable)
sd_val   <- sd(Variable)
CV       <- (sd_val / abs(media)) * 100

asim <- e1071::skewness(Variable, type=2)
kurt <- e1071::kurtosis(Variable)                       # curtosis en exceso (normal = 0)

Q1 <- quantile(Variable, 0.25); Q3 <- quantile(Variable, 0.75); IQR_val <- Q3 - Q1
outliers_data <- Variable[Variable < (Q1 - 1.5*IQR_val) | Variable > (Q3 + 1.5*IQR_val)]
num_out <- length(outliers_data)
out_txt <- if (num_out > 0) {
  paste0(fmt_entero(num_out), " [", fmt_num(min(outliers_data), 0), "; ", fmt_num(max(outliers_data), 0), "]")
} else "0 [Sin outliers]"
ind <- data.frame(
  "Variable"="Profundidad perforada (ft)",
  "Rango"=paste0("[", fmt_num(min(Variable),0), "; ", fmt_num(max(Variable),0), "]"),
  "Media (X̄)"=fmt_num(media, 2), "Mediana (Me)"=fmt_num(mediana, 2), "Moda (Mo)"=fmt_num(moda_val, 2),
  "Varianza (S²)"=fmt_num(varianza, 2), "Desv. Est. (S)"=fmt_num(sd_val, 2),
  "C.V. (%)"=fmt_num(CV, 2),
  "Asimetría (As)"=fmt_num(asim, 4), "Curtosis (K)"=fmt_num(kurt, 4),
  "Outliers [Intervalo]"=out_txt, check.names=FALSE
)
k <- knitr::kable(ind, format="html", escape=TRUE, align=c("l", rep("c", 10))) |>
  kableExtra::kable_styling(bootstrap_options=c("striped","condensed"),
                           full_width=TRUE, position="center") |>
  kableExtra::add_header_above(c("Variable"=2, "Tendencia central"=3,
    "Dispersión"=3, "Forma"=2, "Valores atípicos"=1), bold=TRUE, background="#dddfe2") |>
  kableExtra::row_spec(0, bold=TRUE, background="#f1f2f4")
cat('<div class="cuadro indicadores">',
    '<div class="cuadro-titulo">Cuadro N° 3: Indicadores estadísticos de Profundidad perforada (ft), Nueva York, 1860 - 2026</div>',
    as.character(k),
    '<p class="cuadro-nota"><strong>Registros válidos (N):</strong> ', fmt_entero(N),
    ' &nbsp; | &nbsp; <strong>Clases (k):</strong> ', K_real,
    ' &nbsp; | &nbsp; <strong>Amplitud:</strong> ', Amplitud_int, ' pies',
    ' &nbsp; | &nbsp; <strong>Q1:</strong> ', fmt_num(Q1,0),
    ' &nbsp; | &nbsp; <strong>Q3:</strong> ', fmt_num(Q3,0), '.</p>',
    '<p class="cuadro-nota">La moda se calcula como la marca de clase del intervalo de mayor frecuencia. La curtosis se expresa en exceso respecto a la normal (K = 0).</p>',
    '<p class="cuadro-fuente">Fuente: Oil, Gas &amp; Other Regulated Wells: Beginning 1860.</p></div>', sep="")
Cuadro N° 3: Indicadores estadísticos de Profundidad perforada (ft), Nueva York, 1860 - 2026
Variable
Tendencia central
Dispersión
Forma
Valores atípicos
Variable Rango Media (X̄) Mediana (Me) Moda (Mo) Varianza (S²) Desv. Est. (S) C.V. (%) Asimetría (As) Curtosis (K) Outliers [Intervalo]
Profundidad perforada (ft) [0; 15795] 1397.82 1251.00 465.00 1952986.86 1397.49 99.98 1.4597 4.0807 764 [4826; 15795]

Registros válidos (N): 47.496   |   Clases (k): 17   |   Amplitud: 930 pies   |   Q1: 0   |   Q3: 1930.

La moda se calcula como la marca de clase del intervalo de mayor frecuencia. La curtosis se expresa en exceso respecto a la normal (K = 0).

Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.

7 Conclusión

Las profundidades perforadas de los pozos regulados de Nueva York fluctúan entre 0 y 15795 pies y giran en torno a 1251.00 pies (mediana), con una media de 1397.82 pies y una desviación estándar de 1397.49, lo que da un conjunto de datos heterogéneo (C.V. = 99.98%). La distribución es asimétrica positiva (cola hacia las profundidades altas) (As = 1.4597) y leptocúrtica (más concentrada que la normal) (K = 4.0807), y presenta 764 valores atípicos (entre 4826 y 15795 pies). El intervalo con más pozos es [0 – 930) pies, con 37.90% de los registros válidos, lo que muestra que la actividad de perforación se concentra en determinadas franjas de profundidad. Cabe señalar que 14.639 pozos (30.82%) registran profundidad 0 ft y que 5 registros sin dato fueron excluidos del análisis.

Autor: Estalin Echeverría | Grupo 5 | Análisis Estadístico — Oil, Gas & Other Regulated Wells - NY State